Wednesday 18 May 2016

voltage - converting 3.3v to 1.2v


I have a electrical problem that I hope to get some help with. Let me first start of by saying that I'm quite a noob in this field (I'm a IT guy), but I hope to learn something.


The problem I have is this: I have a sensor to monitor the humidity of soil. When I power it with 3.3v I get a output of 1.9v when it is fully submerged in water and a output of 3.1 v when it's dry. For my project I actually need a output value between 0.2v and 1.2v


To achieve that, I've created a voltage divider (my first ever) using a 1k and a 2k resistor. When I power it with 3.3v I get a output of 1.04v, which is pretty close to what I want (Close enough I thought). My schema looks like this:


enter image description here


I measure at points A and B



I powered the sensor with the 1.04v (so at point B), so the connections look like this:


enter image description here


I was hoping to get a well scaled value out of it. Unfortunately the results are not quite what I wanted. When it's fully submerged, I now get 0.71v, and when it's fry I get 0.86. It seems I'm now losing a lot of resultion, so I'm guessing there must be a better way to do this.


This is by the way the sensor I'm using: Link


The reason I need a value between 0.2v and 1.2v is that I want to hook it up to a ESP8266 Wifi module / microcontroller.


Any ideas?



Answer




Well your close but not quiet there. In the description of the sensor on the webpage you linked it says that the operating voltage is 3.3v to 5v. So while you may have been able to only use that 1.04v as Vcc I would suggest just using the 3.3v source.


What you want to do is have the voltage divider on the output of the device. I have the circuit shown below



schematic


simulate this circuit – Schematic created using CircuitLab


Now here is how I got those two values.


First off you have stated that the high voltage for the output was 3.1v. You want this value to be only 1.2v. Using the Voltage divider formula shown below you can almost get all the values you need.


$$V_{out} = V_{in}*\frac{R2}{R1+R2}$$


V_out is the disried 1.2v, V_in is the 3.1v of the sensor. Now I simply picked R1 to be 10k and solved for R2. Now using these values to see what the lower voltage will be you end up with 0.67v. While its not wonderful its the best you will get with a simple voltage divider.



Alright, So I'm going to keep this as simple as I can. In short you have two problems you have to solve. First you need to 'subtract' a voltage of 1.9 from the output of the sensor to shift it, then your range will be 1.2v down to 0v. However this new output has a total range of 1.2v, not 1v. To correct this you need an amplifier with a gain less then one. Now for simple things like this a LM741 is a pre-built amplifier IC. It has 4 pins, a Vcc(+Power), Vss(-Power), Inverting input, and non-inverting input. Operational amplifiers like the LM741 can do many, many different things but I'm only going to cover your application. They can be used as amplifiers(duh), voltage subtractors, voltage adders, comparators, level shifters and the list goes on. However for this application we will be using the voltage subtractor and amplifier properties. The circuit you need is below with an explaining following. I encourage you to read all of it, op amps are used in tons of applications.


schematic


simulate this circuit



In this circuit the inverting input will have a constant voltage, which will 'subtract' a voltage from the voltage on the non-inverting input. The gain on the non-inverting input can then be adjusted to give you the scale you want. Now I'm going to direct you to this link, this site is very helpful for new people and I still refer to it when I don't feel like re-deriving equations for common circuits(why re-invent the wheel?). I'm just going to hop to the end where it has the equation I'm going to use. Keep in mind my subscripts are not the same because my resistors are labeled differently.


$$V_{out}=\frac{R_4}{R_3}*(V_2-V_1)$$


Now the high and low voltage of V2 is known, the voltage output that we want is known. Now I'll be assuming R4 is 10k again, since if you don't there will be technically an infinite number of solutions. The equations below show the equation with the numbers pluged in. First for the high voltage you want, second for the low voltage you want.


$$1.2=\frac{10k}{R_3}*(3.1-V_1)$$ $$0.2=\frac{10k}{R_3}*(1.9-V_1)$$


Now when you solve this you get that R3 need to be 12k and V1 needs to be 1.66v. V1 can be obtained by a voltage divider. There's an example further up so i'm going to skip that.


Note 1: Since you are connection this to a microcontroller you may want to add in a zener diode to limit the upper range range of the voltage, with either circuit if the sensor does go above 3.1v, you will go over 1.2v on the output, which if the microcontroller can can only go up to 1.2v, you can damage it. A simple way to do this is with a zener diode. Below is breif circuit of how to do it. You can do homework to understand how it works.


schematic


simulate this circuit


Note 2: Many micro-controllers will have a analog to digital converter(ADC) built into them and the input range of the ADC is from the Vcc of the micro-controller which is commonly 3.3v down to 0v. So you may not even need to do this and instead just attach the output of the sensor right to the micro-controller. Then you can use the ADC to get a number representing the voltage and do whatever you want with it.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...