Tuesday, December 13, 2016

Show Temperature on 16x2 LCD with LM35 and Arduino

Good evening everyone so in my Arduino series last two posts were about temperature reading, displaying it on Serial monitor and using a 16x2 LCD display. Now allow me to merge them together to show the temperature reading in that display.

Parts Needed:

1. Any Arduino board ( And yes I'm using the UNO);
2. USB Type A to Type B cable to connect to computer and upload the code.
3. 16x2 LCD Display.
4. Male to Male Jumper Wire.
5. Practice Board.
6. 220ohm Resistor.
7. 10kohm Variable Resistor.
8. LM35.
9. Arduino IDE.


Connection:

Let's start with the display.

Pin 1 - Ground.
Pin 2 - +5V.

Pin 3 - Connect to the Wiper Terminal of the variable resistor. Variable resistor needs both Ground and +5V on it's other two terminal. This resistor is used as contrast control.

Pin 4 - Register select, connect this to Arduino pin 12.

Pin 5 - Read or Write pin. Connect it to the Ground to enable Write mode.

Pin 6 - LCD Enable Pin, connect it to the Arduino pin 11.


Pin 11 - D4 to Arduino pin 5.

Pin 12 - D5 to Arduino pin 4.

Pin 13 - D6 to Arduino pin 3.

Pin 14 - D8 to Arduino pin 2.


Pin 15 - LED+ to 5V/3.3V with a series resistor maybe a 220ohm one. I'm using a 1K one though.
Pin 16 - LED- to Ground. 


Now let's hook up the Temperature sensor.

Pin 1 - +5V
Pin 3 - GND

Pin 2 - Arduino Analog input pin 5.

That's pretty much the connection that we need.


The Code:

Here is the code with necessary explanations.

// Let's start with including the LCD Library.

#include  <LiquidCrystal.h>

// Define the Input pin for LM35, in this case it is A5.
int  tempPin  =  5     ;

// Declare variable
int  value;

// Initialize the library with the numbers of the interface pins.
LiquidCrystal  lcd    (12, 11, 5, 4, 3, 2);

void  setup()

{
  // Sets the data rate in bits per second (baud) for serial data transmission.
  Serial.begin(9600);

  // Set up the LCD's number of columns and rows.
  lcd.begin(16, 2);

  // Print a message to the LCD.
  lcd.print("Temperature: ");

}

void  loop()

{ // taking in the value from input pin.
  value = analogRead(tempPin);

  // convert the voltage information, as LM35 is already calibrated in celcius to get the celcius output not much code is needed.
  float mv = ( value / 1023.0) * 5000;
  float cel = mv / 10;

  // convert the celcius value to farenhite, uncomment this and print it to get the fahrenheit result.
  //float farh = (cel * 9) / 5 + 32;

  // Serial Print will print value to serial monitor.
  Serial.print("Temperature = ");
  Serial.print(cel);
  Serial.print("*C");
  Serial.println();

  // Let's give it a vertical shift so it will be on the bottom line.
  lcd.setCursor(0, 1);

  // Print a message on the bottom line.
  lcd.print(cel);
  lcd.print(" *C") ;

  //Start again after 300ms.
  delay(300);

}


So how does it work?

Well I have separately written how the display and the temperature monitoring works so I will just put links to those post at the bottom of this post where you can find details on them.

Let's look at the completed project.


Here you can see the display, Arduino and the LM35. The reason there is no variable resistor is because I don't need to control the contrast in this one. So I just left it out.


Applications:

Temperature sensor can be really helpful and putting it on a display can be even more helpful. It not only can be used as a visual modification for your project but can be used in many different projects where it is necessary to show the temperature. You can also control other devices using temperature as the trigger point. One thing you can do is to make something like the following image and cover the wires with heat shrink material and can be used as a temperature probe to lower it in a liquid or reach in a place where it wouldn't be practical to put the practice board in.


In Here I'm Just using three Male to Female jumper wire, the one that is used with Raspberry Pi.

So that's pretty much it, hope this has been helpful.


Links:

1. Temperature monitor using LM35.
2. Using 16x2 display with Arduino.
3. Read my other posts here.


No comments:

Post a Comment