Shop OBEX P1 Docs P2 Docs Learn Events
Convert 5v analog signal to 3.3v — Parallax Forums

Convert 5v analog signal to 3.3v

ajit.nayak87ajit.nayak87 Posts: 76
edited 2014-03-23 08:13 in General Discussion
I am having sensor Inclinometer it specification attached below. it output varies from 0-5v . 0 degree read at 2.5v , +70 @ 5v and -70 @ 0v from output side.I have micro controller chip kit uno32 Analog input pin of 10 bit resolution Which can read voltage between 0-3.3v. Question Here:
  1. How to convert 5v sensor output to 3.3v to match its resolution.??
  2. I have also tried to used to drop 5v output to3.3v using diode. How it will affect the sensor output voltage??

I have drop the volatge from 5v to 3.3v using voltage devider network using R1=504ohm and R2=980ohm

voltagedivider.gif

int sensorPin = A0; 
float Yvoltage;

static float ARDUINO_ANALOG_SCALING =0.00322265625;
static float Ydegree;
static int Sensor_Value;
static float Xdegree;
float Xvoltage;

void setup()
{
  Serial.begin(9600);
}
void loop() 
{
 Sensor_Value=analogRead(A0); 
 Serial.print(" Sensor vlaue:");
    Serial.println(Sensor_Value);
 
 Yvoltage = Sensor_Value * ARDUINO_ANALOG_SCALING;
   Serial.print(" Y voltage:");
    Serial.println(Yvoltage);
    Ydegree=(30*Yvoltage)-75; 
    Serial.print(" Y degree:");
    Serial.println(Ydegree);
     Serial.println("......................");
    delay(1000);
}

INC.jpg
582 x 529 - 45K
INC.jpg 44.8K

Comments

  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-03-21 01:50
    If you want to preserve all the information in the analog signal, but have the maximum be 3.3volts, using two resistors in a voltage divider network.

    A diode is a non-linear device, so it won't work right. Its response will vary along a curve.

    Your voltage divider schematic is good, but you may have to adjust resistor values to get a stable reading. This is a question of how much of a load the sensor outputs can tolerate. Your values may be fine or a bit low.

    5/3.3 = total resistance/the 3.3 volt resistance

    So you might try a higher total resistance, such as 5000 ohms or 10,000 ohms.

    Right now, 504 ohms + 980 ohms equals 1484 ohms at 5 volts, so you are loading the sensor at about 3ma output. The microcontroller input can easily handle less.

    Ideally you want a 500 ohms and 1000 ohms. You can double and triple that to 1000ohms with 2000ohms or 1500ohms with 3000ohms and so on.

    Is that 3ma too high a load or okay?
    With the right values and ratio of resistors, you will get what you want... a linear response.
  • Phil Pilgrim (PhiPi)Phil Pilgrim (PhiPi) Posts: 23,514
    edited 2014-03-21 02:05
    The voltage divider you've posted should work fine. The only catch is the input impedance of the ADC. If it's too low, it will load the divider and produce lower-than-expected results. The solution would be to feed the divided voltage into a unity-gain buffer amplifier ahead of the ADC.

    -Phil
  • ajit.nayak87ajit.nayak87 Posts: 76
    edited 2014-03-21 02:13
    http://ww1.microchip.com/downloads/en/DeviceDoc/chipKIT-Uno32-RevC_rm.pdf
    I amusing above board . I tried with above resistance value . USing program i am getting improper value . I am getting -75 degree at 0v and 2.8v i am getting 0 v but other 3.3v i could not able to achieve 75 degree.
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-03-21 02:15
    Your provided spec sheet seem to claim less than 1ma current consumption from the sensor, so loading it for 3ma may be too much

    Try higher resistors -- say 2000 ohms and 4000 ohms to make the load below 1 ma. If that doesn't work, go even lower.

    +++++++++++
    Ummm, if you are getting -75 degrees and expect 75 degrees, you might have just made a math mistake in your programing. The senor might be doing fine.
  • ajit.nayak87ajit.nayak87 Posts: 76
    edited 2014-03-21 02:33
    i have tried multiple resistor network. 1k an2k, 2k and 4.7k. 4.7K /10k, 1k,4.4 k Format . Can some one help me here how to choose proper resistor Network get or set my resolution
  • ajit.nayak87ajit.nayak87 Posts: 76
    edited 2014-03-21 02:50
    i used 4.4k and 10K resistor .In order to meet current requirement of analog pins. for 0v i am getting -75 , 2.5v 0degree,for 3.3v max angle goes upto 23.90 degree. How to choose proper resistor here
  • Peter JakackiPeter Jakacki Posts: 10,193
    edited 2014-03-21 05:43
    Most ADCs will load the input while sampling so it will help if you use a small value capacitor here and just for the sake of seeing if it helps just try a 0.1uF ceramic across ADC inputs (to ground). There are better caps to use when you get picky.
    To choose the divider you need to know about your source impedance but for the moment let's just assume it is around 1K to be safe but it would of course help if you gave a link to the inclinometer.
    Now even if we only present a 1/10 of the load by using the equivalent of 10K load it will still introduce error but let's just work with that.
    So R1+R2 = 10K and at max voltage of 5V --> 500uA
    Therefore R2 = 3.3/500uA = 6K6 and that leaves 3K4 for R1 (the input).
    Now you can fudge these values up or down a bit to match up with standard values but I would just use two 3K3s in series for the 6K6 and and 3K3+100R in series for R1. Place a 0.1uF across R2. Try that and measure the FS voltage with a meter.

    VIN
    3K3----100R
    >ADC
    ...............................|
    3K3----3K3
    GND
    ...............................|
    104
    GND
  • fengfeng Posts: 39
    edited 2014-03-21 07:15
    Try this



    int sensorPin = A0; float Yvoltage;static float ARDUINO_ANALOG_SCALING =0.00322265625;static float Ydegree;static int Sensor_Value;static float Xdegree;float Xvoltage;void setup(){ Serial.begin(9600);}void loop() { Sensor_Value=analogRead(A0); // Result = 0 - 1024 Serial.print(" Sensor vlaue:"); Serial.println(Sensor_Value); Yvoltage = Sensor_Value * ARDUINO_ANALOG_SCALING; // Result = 0 - 3.3V Serial.print(" Y voltage:"); Serial.println(Yvoltage); Ydegree=(30*Yvoltage)-75; // Change to Ydegree = 45.45 * (Yvoltage - 1.65) Serial.print(" Y degree:"); Serial.println(Ydegree); Serial.println("......................"); delay(1000);}


    Then you can change the sensor supply voltage to 3.3V (Min.to Max.supply 3 - 6 Vdc

    OR

    you can configure the divider to R1 = 2010 ohm (2000 ohm + 10 ohm) and R2 = 3900 ohm
  • LoopyBytelooseLoopyByteloose Posts: 12,537
    edited 2014-03-21 08:56
    Peter J made the resistors easy by using 3 resistors of the same value 3.3K.

    I hope you are making progress, but wish you were actually using a Propeller.
  • frank freedmanfrank freedman Posts: 1,983
    edited 2014-03-21 09:48
    Depends on the job they want to do and what is the easiest. (i.e. most familiar). I have just acquired a Pi to play with. Looks best used as a great front end/UI for a project. I can not imagine using it to do the ADC projects I had been playing with especially at the upper end of audio range and higher. Single core device, all processes running through it. Pi great non-realtime device prop great realtime processor. For me, someone with much more experience could do the realtime stuff on a Pi, but for me looks like they will be a good team to play with.

    On the topic of bringing over to propeller, perhaps some articles and contributions to say Maker pubs like the arduino interface chapter in the "Getting Started With the Raspberry Pi" would be a great help to getting people to do more with props and Pi Just a thought for widening the market for the propeller.

    FF
    Peter J made the resistors easy by using 3 resistors of the same value 3.3K.

    I hope you are making progress, but wish you were actually using a Propeller.
  • kwinnkwinn Posts: 8,697
    edited 2014-03-21 19:01
    A 5K 22 turn trim pot works well as an adjustable voltage divider on an MCP3208, and should work with most other ADC's. The adjustment allows you to set the ratio. Just make sure to set the wiper to mid point initially and use a 3.3V level to adjust for a full scale reading. Peter's suggestion of using a 0.1uF capacitor on the input is also a good idea to reduce noise and increase accuracy of the reading.
  • fengfeng Posts: 39
    edited 2014-03-23 08:13
    I suspect that it’s a program error (post #9).
    Not possible send exel-files as attachments?
Sign In or Register to comment.