Close

Displaying Temperature on Nokia LCD Display with an Arduino

A project log for Connected Pool Monitor

The Connected Pool Monitor Measures the Water Quality in Your Pool and Sends You Wireless Updates

timothy-coyleTimothy Coyle 07/15/2017 at 19:400 Comments

I’m going to start off by reading the analog temperature sensor on pin

A0 and displaying to the serial monitor. Then I will add the Nokia LCD

and display the temperature to the Nokia display.

Here’s the pin connections and setup of the analog temperature sensor with the Arduino UNO R3:

Running the code the measured temperature in my house is 70.8 F:

Using a thermapen thermometer it says the air temperature in my house is 73 F:

Okay now onto the Nokia LCD display.

I’m using the Nokia 5110 LCD display from Sparkfun that will connect to the Arduino over the SPI interface:

Sparkfun has a good guide up on how to connect and program the display to an Arduino.

Here’s the LCD pinout for hookup from Sparkfun:

The LED backlight supply connection doesn’t have a current limiting resistor so if you hook this up to the supply on the Arduino directly it will pull a lot of current so you should put a limiting resistor in there if you’re going to backlight the display.

The connection of the display to the Arduino from Sparkfun:

It’s not a bad idea to add some limiting resistors in your data connection paths as alternative hookup shown below:

Below are some photos of my hook up:

Running the example Sparkfun example code you can see how bitmaps are loaded, shapes drawn etc.:

Using the Sparkfun LCD functions library and their example code I combined my analog temperature sensor code and can now read and display the sensor temperature to the display screen:

Below is the Arduino sketch:

/*

Date: 7/15/17

Version: 1.0

Attribution:

For Nokia LCD Display Code:

Nokia 5100 LCD Example Code

Graphics driver and PCD8544 interface code for SparkFun’s

84×48 Graphic LCD.

https://www.sparkfun.com/products/10168

by: Jim Lindblom

adapted from code by Nathan Seidle and mish-mashed with

code from the ColorLCDShield.

date: October 10, 2013

license: Officially, the MIT License. Review the included License.md file

Unofficially, Beerware. Feel free to use, reuse, and modify this

code as you see fit. If you find it useful, and we meet someday,

you can buy me a beer.

Comments:

This sketch reads an analog temperature sensor and writes the temperature in F to

a Nokia LCD display

Hardware Connections:

Analog Temperature Sensor Connection:

Vout Pin: Connect to analog input 0.

LCD Display Connections:

Graphic LCD Pin ———- Arduino Pin

1-VCC —————- 3.3 V

2-GND —————- GND

3-SCE —————- 7 (digital)

4-RST —————- 6 (digital)

5-D/C —————- 5 (digital)

6-DN(MOSI) —————- 11 (SPI)

7-SCLK —————- 13 (SPI)

8-LED – 330 Ohm res — 9 (PWM)

*/

#include <SPI.h>

#include “LCD_Functions.h”

// Setting up temperature sensor

// The AREF pin is tied to the 3.3V output pin to be used as an external reference for the ADC

#define aref_ext_voltage 3.3

// Assign Arduino analog input pin to be connected to temp sensor

int tempPin = 0;

// Assign a variable to hold the temperature sensor reading

int tempVal; // the analog reading from the sensor

void setup()

{

// Setup serial monitor to send temp readings to for debugging

Serial.begin(9600);

// This will setup the LCD pins and initialize the LCD

lcdBegin();

// Command to clear the screen

clearDisplay(WHITE);

// Trial and error values 40 to 60 to get right contrast on screen

setContrast(50);

// Need to tell Arduino that we are using an external voltage reference for ADC

// Always have to set this first before calling analogRead() or else you could short out your board

analogReference(EXTERNAL);

// Allow voltage on ADC to settle out before reading

analogRead(0);

}

void loop()

{

// Read the temperature sensor and store the value

tempVal = analogRead(tempPin);

// debug – print raw along reading to serial monitor

//Serial.print(tempReading);

// Convert the digitized number 0-1023 from the ADC into a voltage based on the reference voltage

// For an external reference voltage of 3.3V => (ADC value) * (3.3V/1024)

float voltageConvert = tempVal * aref_ext_voltage;

voltageConvert /= 1024.0;

// debug – print out the voltage

//Serial.print(” – “);

//Serial.print(voltageConvert); Serial.println(” volts”);

// Convert the voltage into temperature using the linear graph data from the TMP36 datasheet

// TMP36 has 500mV offset and 10mV/C degree scale

// Temp in C = (Voltage – 500mV)/10

// Voltage is in Volts so multiply by 100 instead of divide by 10 to get correct result (1000mV=1V)

float tempC = (voltageConvert – 0.5) * 100 ;

// Convert C to F

float tempF = (tempC * 9.0 / 5.0) + 32.0;

// Print temperature in F to serial monitor

Serial.print(tempF); Serial.println(” degrees F”);

// Convert tempF to string to be printed on LCD display

char templcdresult[8]; // Buffer big enough for 7-character float

dtostrf(tempF, 6, 2, templcdresult); // Leave room for too large numbers!

// Send to LCD Display

setStr(templcdresult, 0, LCD_HEIGHT-20, BLACK);

setStr(“deg F”, 50, LCD_HEIGHT-20, BLACK);

updateDisplay();

delay (1000); // add delay to set screen refresh of temperature

}

Discussions