Arduino with NOKIA 5110 LCD and BMP280 sensor
- Arduino board
- Nokia 5110 LCD screen
- BMP280 sensor module with 3.3V regulator and level shifter —-> BMP280 datasheet
- 5 x 3.3k ohm resistor
- 5 x 2.2k ohm resistor
- Breadboard
- Jumper wires


1
2
3
4
|
#include <SPI.h> // include SPI library
#include <Adafruit_GFX.h> // include adafruit graphics library
#include <Adafruit_PCD8544.h> // include adafruit PCD8544 (Nokia 5110) library
#include <Adafruit_BMP280.h> // include adafruit library for BMP280 sensor
|
1
2
|
// Nokia 5110 LCD module connections (CLK, DIN, D/C, CS, RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
|
1
2
|
// define device I2C address: 0x76 or 0x77 (0x77 is library default address)
#define BMP280_I2C_ADDRESS 0x76
|
1
|
bmp280.begin(BMP280_I2C_ADDRESS)
|
1
2
3
|
// get temperature, pressure and altitude from library
float temp = bmp280.readTemperature(); // get temperature
float pressure = bmp280.readPressure() / 100; // get pressure
|
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
81
82
83
84
85
|
/*
* Interfacing Arduino with BMP280 sensor and Nokia 5110 LCD.
* BMP280 is a pressure and temperature sensor.
* This is a free software with NO WARRANTY.
* http://simple-circuit.com/
*/
#include <SPI.h> // include SPI library
#include <Adafruit_GFX.h> // include adafruit graphics library
#include <Adafruit_PCD8544.h> // include adafruit PCD8544 (Nokia 5110) library
#include <Adafruit_BMP280.h> // include adafruit library for BMP280 sensor
// Nokia 5110 LCD module connections (CLK, DIN, D/C, CS, RST)
Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3);
// define device I2C address: 0x76 or 0x77 (0x77 is library default address)
#define BMP280_I2C_ADDRESS 0x76
Adafruit_BMP280 bmp280;
void setup()
{
// initialize the display
display.clearDisplay(); // clear the screen and buffer
display.begin();
// you can change the contrast around to adapt the display
// for the best viewing!
display.setContrast(50);
display.setTextSize(1);
display.setTextColor(BLACK, WHITE);
display.setCursor(3, 0);
display.print("BMP280 SENSOR");
display.display();
if ( !bmp280.begin(BMP280_I2C_ADDRESS) )
{ // connection error!
display.setCursor(0, 15);
display.println("Connection");
display.print("error!");
display.display();
while (1);
}
display.setCursor(7, 10);
display.print("TEMPERATURE:");
display.setCursor(16, 31);
display.print("PRESSURE:");
display.display();
}
// variable declaration
char text[12];
// main loop
void loop()
{
// get temperature and pressure from library
float temp = bmp280.readTemperature(); // get temperature
float pressure = bmp280.readPressure() / 100; // get pressure
// print data on the LCD screen
// 1: print temperature
display.setCursor(15, 20);
if(temp >= 0)
display.print(' ');
else
display.print('-');
sprintf(text, "%02u.%02u C", (int)abs(temp), (int)(abs(temp) * 100) % 100);
display.print(text);
display.drawRect(53, 20, 3, 3, BLACK); // print degree symbol ( ° )
// 2: print pressure
display.setCursor(9, 41);
sprintf(text, "%04u.%02u hPa", (int)pressure, (int)((uint32_t)(pressure * 100) % 100));
display.print(text);
// now update the display
display.display();
delay(2000); // wait 2 seconds
}
// end of code.
|