Introduction: DS18B20 Temperature Probe With LCD
The DS18B20 comes in a temperature probe form, which is waterproof. I had a real hard time trying to get this one working and I thought I would share how I in the end got it working. Enjoy!
Step 1: Parts
The parts you will need for this project:
Arduino Mega or other arduino (3-15$)
An LCD (around 3$)
A DS18B20 temperature probe (I got this for about 2$)
A couple of jumper wires (Around 3$)
A 4.7K resistor (Don't exactly know, I got a pack of 600 resistors with different types for 3$)
A 220 Ohm resitor for the LCD (Again, I don't exactly know, as I got a pack of 600 resistors with different types for 3$)
Step 2: Connections (without LCD)
The way I am going to put this is first by using only the DS18B20 sensor and print the results to the serial monitor in case you don't have a LCD or just want to test your sensor.
Next I am going to show you how to connect the LCD as well.
So for the DS18B20:
You have to connect this as the picture intends. You will have to connect:
VCC -> Arduino 5V, plus a 4.7K resistor going from VCC to Data
Data -> Any arduino pin
GND -> Arduino GND
Step 3: Code (without LCD)
Here is the code for the sensor without LCD, I am using two extra libraries:
Enjoy:
#include <OneWire.h>
#include <DallasTemperature.h>#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float tempC = 0; float tempF = 0;
void setup() { sensors.begin(); pinMode(3, OUTPUT); analogWrite(3, 0); Serial.begin(9600); }
void loop() { sensors.requestTemperatures(); tempC = sensors.getTempCByIndex(0); tempF = sensors.toFahrenheit(tempC); delay(1000); Serial.print("C: "); Serial.print(tempC); Serial.print(" F: "); Serial.println(tempF); }
Step 4: Connections (with LCD)
If you are going to connect the LCD, connect it like this:
I am going to connect the wire which should go to a potentiometer to control the contrast to pin 3 on arduino.
Connections: (LCD -> ARDUINO)
Pin 1 -> GND
Pin 2 -> VCC
Pin 3 -> Arduino pin 3
Pin 4 -> Arduino pin 33
Pin 5 -> GND
Pin 6 -> Arduino pin 31
Pin 7 - 10 -> NONE
Pin 11 -> Arduino pin 22
Pin 12 -> Arduino pin 24
Pin 13 -> Arduino pin 26
Pin 14 -> Arduino pin 28
Pin 15 -> VCC through 220 OHM resistor.
Pin 16 -> GND
Step 5: Code (with LCD)
Here is the code for the LCD, remember to hook everything up right, and then this will work like a charm up to 125 degrees. And if your display only shows -127 degrees, then it is probably the resistor to the temp sensor not hooked up right.
I am using two extra libraries:
Here is the code, enjoy:
#include <OneWire.h>
#include <LiquidCrystal.h> #include <DallasTemperature.h>
#define ONE_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
float tempC = 0; float tempF = 0;
LiquidCrystal lcd(33,31,22,24,26,28);
void setup() { sensors.begin(); lcd.begin(16,2); lcd.clear(); pinMode(3, OUTPUT); analogWrite(3, 0); Serial.begin(9600); }
void loop() { sensors.requestTemperatures(); tempC = sensors.getTempCByIndex(0); tempF = sensors.toFahrenheit(tempC); delay(1000); Serial.println(tempC); lcd.setCursor(0,0); lcd.print("C: "); lcd.print(tempC); lcd.print(" degrees"); lcd.setCursor(0,1); lcd.print("F: "); lcd.print(tempF); lcd.print(" degrees"); }
Step 6: Proof of Working and End/finish
I have measured temperature up to 100 degrees with this sensor and it works very well. Take a look at the pictures and you will see when it is at about 99 degrees Celsius. The only downside is that when the display gets up to more than a hundred degrees fahrenheit, the S gets cut off, which is kind of unfortunate, although you can fix this by adding a lcd.clear(); at the end of the code above the semi-colon.
Thanks for reading this tutorial and I hope it will help you in connecting your DS18B20. If you liked this tutorial, please subscribe for more and give it a favourite.
Samuel
14 Comments
2 years ago
great project,Thanks
I have a question, What is thermal time constant of this sensor?
5 years ago
what is the code if im using arduino uno?thanks in advance
6 years ago
Can i have the coding for this project? really helped if i could get it
7 years ago on Introduction
Nice Instructable. Thanks!
Just a couple of suggestions. The first is a schematic is always a big help especially when the pictures are a little unclear or pin numbers are obscured. I could not tell where the gray wire (data) went on the board. (BTW-My Data wire was Black) (I was using an UNO). Also in the text you say to attach the DATA line to any Arduino pin (Pin 7). That is not correct as the program is looking for the to appear data on specific pin. Also in the sketch the DATA in pin is not clearly identified as such. A comment next to the code would be a big help.
Once I guessed that digital pin 7 was the expected data port everything took off fine.
Thanks again!
Reply 7 years ago on Introduction
Correction. Black is Ground. My DATA wire is yellow. Not that is matters.
Red=Vcc (3 to 5.5Volts) Black=Gnd Whatever left over is the data lead.
7 years ago
Where Did you buy 600 resistors for 3$??
Reply 7 years ago
On aliexpress.com , just search for resistor :)
8 years ago on Introduction
Where are you getting your Arduino Mega for $3-15?
Reply 8 years ago on Introduction
Hello mrmath,
I am not getting the arduino mega for 3 dollars although I got mine from aliexpress for 9,84$ which is a pretty nice price. It works great and came with the atom USB to serial. Click here to see it.
Samuel
Reply 8 years ago on Introduction
You're linking to a clone (which is perfectly fine--I own a clone Uno), but your instructable shows a genuine Arduino. I was thinking you were getting the genuine article for $3-15. That would be a steal.
Reply 8 years ago on Introduction
hello,
The mega in the picture is actually a clone, it is not the genuine article.
Samuel
Reply 8 years ago on Introduction
*atmel not atom
8 years ago on Introduction
Great project, very nicely done. Thanks for sharing this!
Reply 8 years ago on Introduction
Thanks a lot for your feedback, I appreciate it!
Samuel