This post shows how to interface Arduino with NOKIA 5110 LCD and DHT22 (AM2302) digital humidity and temperature sensor. Values of the relative humidity and the temperature are displayed on the Nokia 5110 (Nokia 3310) LCD screen which has a resolution of 84 x 48 pixel.
To see how to interface Arduino with Nokia 5110 LCD, visit the following post:
Interfacing Arduino with Nokia 5110 LCD
And for interfacing Arduino with DHT22 sensor, see the post below:
Arduino with DHT22 sensor and LCD
Hardware Required:
- Arduino board
- Nokia 5110 (3310) LCD module
- DHT22 (AM2302, RHT03) sensor — datasheet
- 5 x 3.3k ohm resistor
- 5 x 2.2k ohm resistor
- 4.7k ohm resistor
- Breadboard
- Jumper wires
Arduino with Nokia 5110 LCD and DHT22 sensor circuit:
Project circuit diagram is shown below.
The Nokia 5110 which is shown in the circuit diagram has 8 pins (from left to right): RST (reset), CE (chip enable), DC (or D/C: data/command), Din (data in), Clk (clock), VCC (3.3V), BL (back light) and Gnd (ground).
The Nokia 5110 LCD works with 3.3V only (power supply and control lines). The LCD module is supplied with 3.3V which comes from the Arduino board (VCC pin of the LCD is connected to Arduino 3V3 pin), BL pin is also connected to 3.3V.
All Arduino UNO board output pins are 5V, connecting a 5V pin to the Nokia 5110 LCD may damage its controller circuit.
To connect the Arduino to the LCD module, I used voltage divider for each line which means there are 5 voltage dividers. Each voltage divider consists of 2.2k and 3.3k resistors, this drops the 5V into 3V which is sufficient.
The DHT22 sensor has 4 pins (from left to right):
VCC: connected to Arduino 5V pin
Data pin: connected to Arduino analog pin 0 (A0)
Not connected pin
GND: connected to Arduino GND pin.
Arduino with Nokia 5110 LCD and DHT22 sensor code:
The following Arduino code requires 3 libraries from Adafruit Industries:
The first library is a driver for the Nokia 5110 LCD (PCD8544 controller) which can be installed from Arduino IDE library manager (Sketch —> Include Library —> Manage Libraries …, in the search box write “nokia” and install the one from Adafruit).
The second library is Adafruit graphics library which can be installed also from Arduino IDE library manager.
The third library is for the DHT22 sensor, also it can be installed from the library manager.
The previous 3 libraries can also be installed manually, download links are below:
Adafruit Nokia 5110 LCD library —-> direct link
Adafruit graphics library —-> direct link
Adafruit DHT library —-> direct link
After the download, go to Arduino IDE —> Sketch —> Include Library —> Add .ZIP Library … and browse for the .zip file (previously downloaded).
The same thing for all library files.
So, the code uses 4 libraries, they are included as shown below:
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 <DHT.h> // include DHT library code |
Rest of code is described through comments!
Full Arduino code:
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 86 87 88 89 90 91 | /* * Interfacing Arduino with Nokia 5110 LCD and DHT22 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 <DHT.h> // include DHT library code // Nokia 5110 LCD module connections (CLK, DIN, D/C, CS, RST) Adafruit_PCD8544 display = Adafruit_PCD8544(7, 6, 5, 4, 3); #define DHTPIN A0 // DHT22 data pin is connected to Arduino analog pin 0 #define DHTTYPE DHT22 // DHT22 sensor is used DHT dht22(DHTPIN, DHTTYPE); // configure DHT library char temperature[] = "000.0 C"; char humidity[] = "000.0 %"; void setup() { delay(1000); // wait 1 second // initialize the display display.begin(); // initialize the DHT library dht22.begin(); // you can change the contrast around to adapt the display // for the best viewing! display.setContrast(50); display.clearDisplay(); // clear the screen and buffer display.display(); display.drawFastHLine(0, 23, display.width(), BLACK); display.setTextSize(1); display.setTextColor(BLACK, WHITE); display.setCursor(6, 0); display.print("TEMPERATURE:"); display.setCursor(15, 28); display.print("HUMIDITY:"); display.display(); } // main loop void loop() { // read humidity int RH = dht22.readHumidity() * 10; // read temperature in degree Celsius int Temp = dht22.readTemperature() * 10; // update temperature and humidity arrays if(Temp < 0) { temperature[0] = '-'; Temp = abs(Temp); } else temperature[0] = ' '; temperature[1] = (Temp / 100) % 10 + '0'; temperature[2] = (Temp / 10) % 10 + '0'; temperature[4] = Temp % 10 + '0'; if(RH >= 1000) humidity[0] = '1'; else humidity[0] = ' '; humidity[1] = (RH / 100) % 10 + '0'; humidity[2] = (RH / 10) % 10 + '0'; humidity[4] = RH % 10 + '0'; // print temperature display.setCursor(18, 12); display.print(temperature); // print degree symbol ( ° ) display.drawRect(50, 12, 3, 3, BLACK); // print humidity display.setCursor(18, 40); display.print(humidity); // now update the display display.display(); delay(1000); // wait 1 second } // end of code. |
The following video shows Proteus simulation of the project (note that simulation circuit is not the same as real hardware circuit, hardware circuit diagram is shown above):
Proteus simulation file download link is below, use version 8.6 or later to open it:
Arduino with Nokia 5110 LCD and DHT22 sensor
Discover more from Simple Circuit
Subscribe to get the latest posts sent to your email.