Arduino with SSD1306 OLED display and LM35 temperature sensor
- Calibrated Directly in ° Celsius (Centigrade)
- Linear + 10 mV/°C Scale Factor
- 0.5°C Ensured Accuracy (at +25°C)
- Rated for Full −55°C to +150°C Range
- Suitable for Remote Applications
- Low Cost Due to Wafer-Level Trimming
- Operates from 4 to 30 V
- Less than 60-μA Current Drain
- Low Self-Heating, 0.08°C in Still Air
- Nonlinearity Only ±¼°C Typical
- Low Impedance Output, 0.1 Ω for 1 mA Load
- Arduino board
- SSD1306 OLED display
- LM35 temperature sensor —-> datasheet
- Breadboard
- Jumper wires

1
2
3
|
#include <Wire.h> // include Arduino wire library (required for I2C devices)
#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_SSD1306.h> // include Adafruit SSD1306 OLED display driver
|
1
2
3
4
5
|
#define OLED_RESET 4 // define display reset pin
Adafruit_SSD1306 display(OLED_RESET);
// define LM35 data pin connection
#define LM35_PIN A0
|
1
|
tCelsius = 10 * analogRead(LM35_pin) / 9.3;
|
1
|
sprintf(_buffer, "%03u.%1u K", tKelvin / 10, tKelvin % 10);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
/*
* Arduino with LM35 analog temperature sensor and SSD1306 OLED display.
* This is a free software with NO WARRANTY.
* http://simple-circuit.com/
*/
#include <Wire.h> // include Arduino wire library (required for I2C devices)
#include <Adafruit_GFX.h> // include Adafruit graphics library
#include <Adafruit_SSD1306.h> // include Adafruit SSD1306 OLED display driver
#define OLED_RESET 4 // define display reset pin
Adafruit_SSD1306 display(OLED_RESET);
// define LM35 data pin connection
#define LM35_pin A0
void setup(void)
{
delay(1000); // wait a second
analogReference(INTERNAL); // set positive reference voltage to 1.1V
// initialize the SSD1306 OLED display with I2C address = 0x3D
display.begin(SSD1306_SWITCHCAPVCC, 0x3D);
// clear the display buffer.
display.clearDisplay();
display.setTextSize(1); // text size = 1
display.setTextColor(WHITE, BLACK); // set text color to white and black background
display.setCursor(15, 0); // move cursor to position (15, 0) pixel
display.print("LM35 TEMPERATURE:");
display.display(); // update the display
display.setTextSize(2); // text size = 2
}
int tKelvin, tCelsius, tFahrenheit;
char _buffer[8];
void loop()
{
// read analog voltage ( = tenths degree Celsius)
// 9.3 = 1023/(1.1*100)
tCelsius = 10 * analogRead(LM35_pin) / 9.3;
tKelvin = tCelsius + 2732; // convert tenths °C to tenths Kelvin
tFahrenheit = tCelsius * 9/5 + 320 ; // convert tenths °C to tenths °Fahrenheit
// print temperature in degree Celsius
if (tCelsius >= 1000) // if temperature >= 100.0 °C
sprintf(_buffer, "%03u.%1u C", tCelsius / 10, tCelsius % 10);
else
sprintf(_buffer, " %02u.%1u C", tCelsius / 10, tCelsius % 10);
display.setCursor(23, 10);
display.print(_buffer);
// print temperature in degree Fahrenheit
if (tFahrenheit >= 1000) // if temperature >= 100.0 °F
sprintf(_buffer, "%03u.%1u F", tFahrenheit / 10, tFahrenheit % 10);
else
sprintf(_buffer, " %02u.%1u F", tFahrenheit / 10, tFahrenheit % 10);
display.setCursor(23, 30);
display.print(_buffer);
// print temperature in Kelvin
sprintf(_buffer, "%03u.%1u K", tKelvin/10, tKelvin%10);
display.setCursor(23, 50);
display.print(_buffer);
// print degree symbols ( ° )
display.drawCircle(88, 12, 2, WHITE);
display.drawCircle(88, 32, 2, WHITE);
// update the display
display.display();
delay(1000); // wait a second
}
// end of code.
|
