DS18B20 Temperature Probe With LCD
by samuel123abc in Circuits > Arduino
37243 Views, 41 Favorites, 0 Comments
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!
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$)
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
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); }
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
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"); }
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