Categories

Display temperature on I2C OLED display

Taking our hello world I2C OLED example a bit further, this is our next creation. We connect a DS18B20 temperature sensor and display the temperature on the display

Coding

You need to download and install various libraries and copy them into your Arduino libraries folder.

Dallas 18b20 Temperature Library
“1-Wire” Library

Multi LCD library

 


#include "Arduino.h"
#include "Wire.h"
#include "OneWire.h"
#include "MicroLCD.h"
#include "DallasTemperature.h"

#define DS18B20 2

OneWire ourWire(DS18B20);
DallasTemperature sensors(&ourWire);

//LCD_SH1106 lcd; /* for SH1106 OLED module */
LCD_SSD1306 lcd; /* for SSD1306 OLED module */

void setup()
{
lcd.begin();
sensors.begin();
}

void loop()
{

sensors.requestTemperatures();
lcd.clear();
lcd.setFontSize(FONT_SIZE_MEDIUM);
lcd.print(sensors.getTempCByIndex(0));
lcd.print(" celsius");
delay(1000);
}

 

Links

Share

Comments are closed.