Tuesday, November 18, 2014

Display Room Temperature Using LM35 Temp Sensor

Required

  • 1 x Arduino Board
  • 1 x 7 Segment 4 Digit Display (in my case common anode)
  • 1 x LM35 Temperature Sensor
  • 1 x Bread Board
  • 8 x 330 Ohm resistors
  • 15 x Wires (for the connections)

The Basics


Most of the guides i came across with on the Internet instructed how to connect and retrieve the temperature from the LM35 sensor and display them using the Arduino serial monitor.
I want to do something a bit different, i'm sure there is already a guide on the Internet about it, but i wanted to do something of my own.

In this guide you will learn how to connect both 7 segment 4 digit display and LM35, and, finally display the room temperature on the display.

Connecting the 7 Segment 4 Digit Display:

You may refer to my previous blog on 7 Segment 4 Digit Display at located here
 

Connecting the LM35 Temperature Sensor:


+Vs    --> 5V pin on Arudino
Vout   --> Analog 0 pin on Arduino
GND  --> GND pin on Arduino










Example -


















Finally you should have something like this (Including the 7 Segment):

An overview look of how i have connected my device.











A closer look at the LM35 temp sensor.













 

The Code

#include <SevenSeg.h>

// Seven Seg Global Variables
SevenSeg disp(2, 3, 4, 5, 6, 7, 8);
const int numOfDigits = 4;
int digitPins [numOfDigits] = {10, 11, 12, 13};

// LM35 Temp Sensor Global Variables
// Based on http://playground.arduino.cc/Main/LM35HigherResolution
int LM35Pin = 0; //Analog pin connected to LM35
//float referenceVoltage;
float SensorValue = 0; // a variable that will hold the temp sensor input

void setup() {

  // Serial Interface Setup
  Serial.begin(9600);

  // Seven Seg Setup: 
  // define number of digits and the location on Arduino pins
  disp.setDigitPins(numOfDigits, digitPins);
  // define decimal point Arduino pin
  disp.setDPPin(9);
  // set refresh rate, how many times the display will refresh in seconds, more is faster.
  disp.setRefreshRate(60);

  // LM35 Temp Sensor Setup
  analogReference(INTERNAL); // This will limit the current to 1.1V for higher resultion
  //referenceVoltage = 1.1; //Set to 5, 3.3, 2.56 or 1.1 depending on analogReference Setting
  // The LM35 with this configuration is limit to 0 - 110 Celisus
  // For more information see: http://arduino.cc/en/Reference/AnalogReference//END setup()

void loop(){

  SensorValue = float(analogRead(LM35Pin)) * 110 / 1024;
  SensorValue = SensorValue * 100;
  Serial.print("TempC = ");
  Serial.print(SensorValue);
  Serial.println();

  for(int i = 0; i <= 100; i++) {
    disp.write(SensorValue, 2);
  }

} // END loop()

No comments:

Post a Comment