Bad readings from DS18B20 temperature sensors

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Bad readings from DS18B20 temperature sensors

Postby wapcaplet » Sat Jul 07, 2012 10:33 pm

I've recently embarked on my first serious electronics project using the Arduino. It's a pump controller for a solar water heater, using a relay circuit to turn on a 12V water pump based on the difference in temperature between two DS18B20 digital temperature sensors. This page has a description of what I'm doing, and wiring schematics (scroll to the bottom).

Everything is working pretty well, except the temperature sensors are often reading -196.60 when the pump is on (relay closed). When the pump is off (relay open), the sensors return correct readings every time. I suspect it's because (1) The relay is powered by the 5V pin from the Arduino, and (2) The sensors are using the same 5V power source, running in "parasite" mode (signal and power on the same wire).

I've tried using a longer sampling interval, but I get the same behavior whether the sensors are polled every 1 second, 30 seconds, or 60 seconds. I've read that the DS18B20 has an internal capacitor which allows it to hold a charge long enough to send its data across the wire--could it be that the capacitor is failing to charge when some of the 5V is powering the relay? I've also read that when these sensors have problems in parasite mode, it may help to use a lower pull-up resistance (mine's currently the recommended 4.7Kohm).

For now, I'm handling the problem in software by just ignoring the bad readings--I still get enough good readings that it works anyway--but I would like to learn about how the relay and sensors might be interfering with each other, and how to fix it. I'd appreciate any advice!
wapcaplet
 
Posts: 9
Joined: Fri Jun 15, 2012 4:30 pm

Re: Bad readings from DS18B20 temperature sensors

Postby john444 » Sat Jul 07, 2012 11:04 pm

Hi WapCaplet,

I suspect that the relay is pulling the 5-V power down when it is energized.
Since you are driving the relay from a transistor anyway, you could replace the 5-V relay with one with a 12-V coil.
Then power the new relay coil from 12-V instead of 5-V from the Arduino.
Or, for less money, replace the transistor & relay with a FET (like the IRLB8721 AdaFruit id 355) to more directly switch the pump-motor.
Don't know how many amps the pump-motor draws but if it is less than 20 or so the FET should work fine.

Good luck, John
john444
 
Posts: 407
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Bad readings from DS18B20 temperature sensors

Postby wapcaplet » Sun Jul 08, 2012 12:23 am

Thanks for the reply John. The water pump is 12V, so powering the relay with a 12V source would probably be redundant. I must admit I don't fully understand the relay circuit I'm using; I got the schematic from another site, and it looks to be a typical layout for relays. I know the transistor is acting as a switch, with the Arduino pin 8 sending a relatively low current to tell the transistor to connect up the 5V power. Indirect, but it works, so long as you don't make any other demands on the 5V line :-)

The pump is only 1.2 amps, so it sounds like a FET is the way to go. The TO-220 looks like it'll do the job without draining as much power from the sensors. How would that be wired? I'm guessing Arduino control pin through a resistor to the middle pin of the FET, then 12V +/- on the other two pins.
wapcaplet
 
Posts: 9
Joined: Fri Jun 15, 2012 4:30 pm

Re: Bad readings from DS18B20 temperature sensors

Postby john444 » Sun Jul 08, 2012 1:42 am

Wepcaplet,

wapcaplet wrote:it looks to be a typical layout for relays
There are lots of flavors of relays.
Some would easily be operated from the Arduino's 5-V supply but many cannot.
The relay you selected may be one of those that caused the problem you described.

wapcaplet wrote:How would that be wired?
LadyAda has a tutorial that describes using a (different) FET.
Although, the connections will be the same for the IRLB8721.
http://www.ladyada.net/products/rgbledstrip/#usage
Also, she is driving 3 different sets (colors) of LEDs.
You need only one FET to turn on/off your pump-motor.

wapcaplet wrote:I'm guessing Arduino control pin through a resistor to the middle pin of the FET, then 12V +/- on the other two pins.
I think you misunderstand the connections for this FET.
When looking at the printing on the FET: (see the spec sheet - http://www.adafruit.com/datasheets/irlb8721pbf.pdf)
Left pin is the Gate. Connect to the Arduino output pin (you chose to use pin-8)
(+5v on the gate causes a low resistance from drain to source, 0v causes high resistance)
Center pin is the Drain. Connect to the (-) of the pump-motor. (+) connection on the motor goes to +12-V.
Right pin is the Source. Connect to both the Arduino ground as well as the 12-V ground.
(or the (-) connection on a battery / power supply)

You have very well written descriptions and good photos of your solar heater.
Nice job, John
john444
 
Posts: 407
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Bad readings from DS18B20 temperature sensors

Postby wapcaplet » Sun Jul 08, 2012 9:51 pm

John,

Thanks for the explanation. I think I'm starting to get it. I've re-sketched the circuit based on LadyAda's tutorial and your description:

Image

A couple things I wonder about: (1) Will that LED and resistor going into the FET from Pin 8 be a problem? I like having the LED to indicate when the pump is on, but the FET's data sheet is kind of overwhelming, so I'm unsure whether I'd need a different resistance there. I'm assuming Pin 8 is 5V; please correct me if I'm wrong. (2) I've seen some FET switch diagrams that have a high-ohm pulldown resistor between the FET's gate and ground, in order to ensure that the gate is receiving 0V when it's off. Would it make sense to include one of those here?

Anything else I'm missing?
wapcaplet
 
Posts: 9
Joined: Fri Jun 15, 2012 4:30 pm

Re: Bad readings from DS18B20 temperature sensors

Postby john444 » Mon Jul 09, 2012 12:56 pm

We still need to do a little work on this.
However, I will invite someone else to address the temp sensor wiring.
But I have attached a diagram for the FET & pump.
Note the gate, source, & drain terminals on the FET.

[img]C:\Users\johnm\Desktop\FET%20&%20Pupm%20Schematic.jpg[/img]

The LED will be a problem in the gate circuit.
Although, you may place it in parallel with the pump (with a revised resistor)
It will come on when the pump is powered.
12-V source, 2-V drop across LED, desire 20-mA current through LED.
10-V / 0.02-A = 500-ohm (you may use the 1k but the LED will be dimmer).

Also, I placed a diode in parallel with the motor to reduce voltage spikes.

How does this look? John
john444
 
Posts: 407
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Bad readings from DS18B20 temperature sensors

Postby john444 » Mon Jul 09, 2012 1:01 pm

I did not get the image loaded.
I will try again. John
Attachments
FET & Pupm Schematic.jpg
FET & Pupm Schematic.jpg (178.07 KiB) Viewed 2341 times
john444
 
Posts: 407
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Bad readings from DS18B20 temperature sensors

Postby wapcaplet » Mon Jul 09, 2012 11:46 pm

John,

Wow, I was off on a couple things. I wondered about whether it'd be good to have a diode there; I've read that it helps prevent spikes with an inductive load (there's one in my existing relay circuit for the same reason). Thanks also for the LED suggestion; wiring it in parallel and driving it from the 12V load makes sense. Revised schematic:

differential_controller_2.png
differential_controller_2.png (9.18 KiB) Viewed 2333 times


I've also included the pulldown resistor from gate to source (R3). I am anxious to try it out--I don't have a FET on-hand, and I'm waiting for some out-of-stock items on adafruit (most importantly, an LCD display for showing temperature in real-time) before ordering one. This has been purely a mental exercise for me so far, albeit a very enlightening one. Thanks again for all your help; I will let you know once I get it wired up.
wapcaplet
 
Posts: 9
Joined: Fri Jun 15, 2012 4:30 pm

Re: Bad readings from DS18B20 temperature sensors

Postby wapcaplet » Sun Jul 15, 2012 11:25 am

I had another idea for solving this problem--what if I drove the relay coil from the Arduino's VIN pin? The Arduino is connected to a 9V wall-wart power supply, so there should be power to spare from that pin (and this will allow the 5V line to be dedicated to the digital sensors).

The relay I'm using now has a coil rated at a nominal 5V, maximum 6.5V, with a current of 90mA. To drive it with a 9V supply, I should use a resistor in series with the relay coil to absorb the extra 4V. The resistor should be 4V / 0.09A = 44 ohms, and it should be rated at 4V * 0.09A = 0.36W. The lowest resistor I have is 100 ohm, 0.5W, so I figure two of those in parallel will give the desired resistance (50 ohms, close enough).

Is my reasoning sound on this?
wapcaplet
 
Posts: 9
Joined: Fri Jun 15, 2012 4:30 pm

Re: Bad readings from DS18B20 temperature sensors

Postby john444 » Sun Jul 15, 2012 12:45 pm

Hi Wap,

Much better schematic.
The last change to the schematic I suggest would be:
Move the Adruino-Gnd connection from the 12-v Batt(-) to R3-Gnd.

This is because there will be some voltage-drop caused by the current to the Water-Pump.
The small resistance of the wire from the FET to the Batt (-) will ‘raise’ the Gnd voltage at R3.
The result is to reduce the effective output voltage of Pin8.
In high current situations it can become a problem. To prevent this –
1. make the wire from the FET to Batt(-) very low resistance or
2. Move the Arduino-Gnd to the R3 gnd connection. (A much better solution).

I am not a skilled programmer so I will ask talented people to please correct my mistakes.
wapcaplet wrote:I've also included the pulldown resistor from gate to source (R3).

Be sure to initialize Pin8 so that it is capable of ‘pulling high’.
Sometimes, pins are initialized to use the internal ‘pull-up’ resistors.
If you set Pin8 to use the internal resistors, the ‘on’ (low) output voltage would be 0-v (as you expect).
But, the ‘off’ (high) output voltage would be less than 5-v (the ratio of the internal R to R3).

wapcaplet wrote:I will let you know once I get it wired up.

Yes, please do.

Best of Luck, John
john444
 
Posts: 407
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Bad readings from DS18B20 temperature sensors

Postby john444 » Sun Jul 15, 2012 3:22 pm

Here are a couple of photos of my setup.
It is still a work in process.

Photo of my semi in-ground pool
Pool & Solar-Heater.jpg
Pool & Solar-Heater.jpg (58.3 KiB) Viewed 2251 times

Control panel is on the right side of the photo (under the striped umbrella).
Solar-panels are the black strips at the lower right.

Photo of the inside of the control-box
Pool Control-Box.jpg
Pool Control-Box.jpg (56.3 KiB) Viewed 2251 times

Right now - I manually operate the Filter-pump, Chlorine-generator and Heater-pump.
Yet to be installed is a barrier inside the enclosure to separate the high-voltage from the low.
The only thing crossing the barrier will be the 24-V to energize the contactor coils.

The plan is to monitor the temperature of the pool-water and the water at the outlet of the solar-heater. During the day, the Arduino will turn on/off the pump to maintain the temp in the pool.
If the temp goes over the set-point, it will cool the pool-water by running the pump at night.
I am using the analog LM34 temp sensors.
I like being able to verift the temp with a meter to compare to what the Arduino indicates.

Not shown in the photos:
On the right - a panel with ground-fault/arc-fault breakers
On the left - receptacles with over-ride switches for each device.

John
john444
 
Posts: 407
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Bad readings from DS18B20 temperature sensors

Postby wapcaplet » Sat Jul 28, 2012 2:37 pm

Thanks for sharing your photos John. Quite an elaborate setup you have there! Great to see someone else making good use of solar energy.

I have good news and bad news. The good news is that I got the new circuit wired up and soldered (using a FET, matching the schematic above), and it controls my water pump just as well as the old relay circuit did (plus, it fits onto my new proto-wingshield from adafruit, with an RGB LCD display shield on top). The bad news is that it did not solve the problem of bad temperature readings from the DS18B20 sensors.

I have a couple other ideas to try:

(1) Use the Arduino's VIN pin (9V) through a suitable resistor to power the sensors, instead of using the 5V rail. My thinking here is that this would produce a more stable voltage to the sensors (though I have no evidence to back that up). In fact when I measured the 5V rail with the pump on and off (when I was still using a relay), it was already very stable, varying only by 0.1V at most.
(2) Stick a few small capacitors inline to the sensors to smooth out the voltage--perhaps even add capacitors at the end of the long wire, close to the sensor itself. These sensors already have a built-in capacitor, but I figure a couple more can't hurt.

I'm learning towards (2); my gut tells me it has a better chance of succeeding.
wapcaplet
 
Posts: 9
Joined: Fri Jun 15, 2012 4:30 pm

Re: Bad readings from DS18B20 temperature sensors

Postby john444 » Sat Jul 28, 2012 3:51 pm

Hi Wap,

Good to hear from you again.
It is difficult to troubleshoot problems without being able to see your wiring.
Can you post a photo?

However, I suspect that your digital temp sensors are picking up noise from the ground ckt.
If you compare my schematic to yours (July 09), note the connection of the Arduino ground.
In your schematic, there is a common stretch of wire for both the motor ckt and the Arduino gnd.
In my circuit, they go different directions and only connect at 1 point.
(Actually, not exactly. There is the FET source lead in common)

If you have not done so already, move the Arduino ground to the FET source terminal.
You might try this by using a clip-lead or even holding the Arduino gnd there.
BTW. You do have only have 1 ground wire to the Arduino, right?
The idea is to isolate the motor ckt from the Arduino as much as possible.

John
john444
 
Posts: 407
Joined: Sun Mar 04, 2012 1:42 pm
Location: Claremore, Ok

Re: Bad readings from DS18B20 temperature sensors

Postby wapcaplet » Sat Jul 28, 2012 9:17 pm

John,

I'll get a photo of the actual circuit and attach it soon (it's pretty closely packed, so it may not help much). Meanwhile, the schematic is almost identical to the previous one I posted; I took out the LED since I'm using the LCD to indicate when the pump is turned on. As far as I can see, it's equivalent to your schematic, with the addition of the R3 resistor, which I added with the intention that it would pull down the FET's Gate to ground.

I did a breadboard test, with a voltmeter in place of the water pump; it measured 12V when Pin8 was +5V, and measured about 0.1V when Pin8 was off. This implies that there is still a trickle from Source to Drain even with the Gate pulled down to ground; I don't know if this is normal, or if it may point to a flaw in my design.

The 12V negative line is connected to the Arduino ground, and both together are tied to the FET Source terminal (as well as going to the ground line of the sensors). This does seem to throw a wrench in the effort to isolate the motor circuit, but I understand (correctly, I hope) that they need a common ground so that (a) the Gate voltage is relative to Source (to turn on the FET), and (b) the Drain voltage is also relative to Source (to power the pump with 12V). Took me a while to get my head around the concept of "Source" being the negative/ground lead, but it makes sense, since that's the source of electrons.
Attachments
fet_controller_circuit_v2.png
fet_controller_circuit_v2.png (8.73 KiB) Viewed 2028 times
wapcaplet
 
Posts: 9
Joined: Fri Jun 15, 2012 4:30 pm

Re: Bad readings from DS18B20 temperature sensors

Postby wapcaplet » Sat Jul 28, 2012 9:46 pm

Here's a photo of the wiring. As I said, it's a little hard to see, especially since some of the wiring is on the back side (which didn't photograph well), but I quadruple-checked all the connections before soldering and they should be equivalent to the schematic. Some notes:

  • I used different pins than my schematic; pin 12 goes to the gate (instead of pin 8), and pin 11 goes to the sensors' red wire (instead of pin 1)
  • The 100K pulldown resistor is connected to the GND rail, and to the FET Gate (via the vertical red wire)
  • The 12V(-) is also connected to the GND rail (via the diagonal black wire)
  • The 4.7K pullup goes from the 5V rail to the red lead going to the sensors (via the L-shaped red wire)
  • The 1N4001 diode is reverse-biased across the pump terminals (via the short red/black wires you see next to the screw terminals)
  • 12V(+) goes directly to the pump's red wire (and to the bottom end of the diode)
  • FET drain goes to the pump's black wire (and to the top end of the diode)
Attachments
fet_controller_v2_photo.jpg
fet_controller_v2_photo.jpg (542.78 KiB) Viewed 2427 times
wapcaplet
 
Posts: 9
Joined: Fri Jun 15, 2012 4:30 pm

Next

Return to Arduino

Who is online

Users browsing this forum: Google [Bot] and 3 guests

Stuff to buy from the Adafruit store and links to product documentation!


New Products [103]

Raspberry Pi[80]
 
FLORA[23]
 
Bunnie Studios[9]
 
FPGA[1]
 
mbed[11]
Arduino[60]
 
NETduino[14]
 
BeagleBone[24]
 
Android[6]
 
XBee[10]
More Dev Boards[30]


 
BoArduino[8]
 
SpokePOV[4]
 
TV-B-Gone[4]
 
MiniPOV[3]
 
SIM reader[3]
 
Microtouch[5]
 
Clocks & Watches[18]
 
Drawdio[4]
 
Brain Machine[1]
 
Game of Life[2]
 
MintyBoost[2]
More DIY Kits[16]


 
MaKey MaKey[3]
 
Tweet-a-Watt[5]
 
Young Engineers[33]
 
Discover Electronics[2]
 
Snap Circuits[4]
 
littleBits[3]
 
Project packs[8]


 
Breakout Boards[33]
LCDs & Displays[48]
Components & Parts[69]
Batteries & Power[49]
EL Wire/Tape/Panel[52]
LEDs[109]
 
Wireless[14]
Cables[61]
 
Lasers[6]
Sensors/Parts[145]
 
Enclosures/Cases[11]
 
Solar[11]
 
RFID / NFC[13]
Prototyping[70]
 
iDevices[13]
Tools[71]
 
Wearables[39]
 
CNC[37]
 
Robotics[29]
 
3D printing[1]
 
Materials[24]


 
Stickers[41]
 
Skill badges[55]
 
Books[25]
 
Circuit Playground[7]
 
Gift Certificates[4]