Showing posts with label Arduino. Show all posts
Showing posts with label Arduino. Show all posts

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()

Friday, November 14, 2014

Common Anode 7 Segment 4 Digit Display

Device:

 

Common anode 5461BS

Datasheet:





About:

I have search the web for a simple tutorial of how to connect and use a 7 Segment 4 Digit display,
I had a small idea to create a digital temperature monitor with the LM35 temperature sensor, but before that i had to understand how to work with the 7 segment 4 digit display.

I have connected the 5461BS device to the Arduino board as describe below -
























my device is a common anode device, and since, i had to connect a resistor between each LED to the Arduino digital pin in order to lower the voltage and not to damage the LED light, i choose a 330ohm resistor, because this is what i had at the moment. An higher resistor number, means a dimmed LED.


The Code:

I found a very good and sufficient library from the following link -
http://playground.arduino.cc/Main/SevenSeg

All i had to do is to read the "How To" manual and very quickly understand how to control the 7 segment 4 digit device.

the below example code will count from 0 to 2014 and will stay on 2014 on the 7 Seg device -

// Include 7 Segment 4 Digit library
#include <SevenSeg.h>

// Define the connection between the segment to the arduino,
// Example - Arduino Pin 2 equiles LED a on the display
SevenSeg disp(2, 3, 4, 5, 6, 7, 8);
// Set number of digit to display
const int numOfDigits = 4;
// Define which Arduino Digital Pins will control the Digits
int digitPins [numOfDigits] = {
  10, 11, 12, 13};
// Declare x variable to the IF statment below
int x = 0;

void setup() {

  // Define SevenSeg to use 4 digits and where they are located
  disp.setDigitPins(numOfDigits, digitPins);
  Serial.begin(9600);
  disp.setDPPin(9); // Setup the Decimal Point
  disp.setRefreshRate(50); // Lower number means flickring LED

}
void loop(){

  // A very basic code that will count to 2014 and then stop 
  if (x == 0) {
    for(x = 0; x <= 2014; x++){
      disp.write(x);
      Serial.println(x);
    }
  } 
  else {
    disp.write(2014);
  }

}