First, you will need to connect the probe to the breadboard. This should be easy to do since the probe comes with pre-tinned leads. Simply push the ends of the leads into the breadboard sockets and use a 4.6kΩ pull-up resistor on the data pin as shown in fig.1. Now, you will need to connect the Arduino to the breadboard. Use the jumper leads to connect the male to male jumper leads to connect the power, ground and digital pin to the breadboard.
You can now start writing the code to get this all working:
First, clear the IDE window. Then, include the aforementioned libraries:
#include <DS18B20.h>
#include <LCD_I2C.h>
Initialize the KY1602 I2C LCD driver (address 0x27 in this example) and specify the LCD display (in this case 16 characters, 2 rows):
DS18B20 ds(12);
LCD_I2C lcd(0x27, 16, 2);
Initialize the LCD display and turn on the LCD backlight. This is done inside the void setup function:
void setup() {
lcd.begin();
lcd.backlight();
}
Start a while loop. This is done inside the void loop function:
void loop() {
while (ds.selectNext()) {
Set the cursor to the first character and display the temperature in ºF and ºC:
lcd.setCursor(0,0);
lcd.print(ds.getTempC());
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print(ds.getTempF());
lcd.print((char)223);
lcd.print("F");
}
Choose how often to update the screen (in this case, 800ms):
delay(800);
}
The completed code should look like this:
#include <DS18B20.h>
#include <LCD_I2C.h>
DS18B20 ds(12);
LCD_I2C lcd(0x27, 16, 2);
void setup() {
lcd.begin();
lcd.backlight();
}
void loop() {
while (ds.selectNext()) {
lcd.setCursor(0,0);
lcd.print(ds.getTempC());
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print(ds.getTempF());
lcd.print((char)223);
lcd.print("F");
}
delay(800);
}