Project tutorial

Measuring temperatures with LM35 and DS18B20 © CC BY

Temperature is measured from two different sensors and send data through bluetooth and a set of LEDs is lit according to average temperature

  • 1,457 views
  • 0 comments
  • 4 respects

Components and supplies

Apps and online services

About this project

This design is a simple way to get temperatures from two sensors, thus obtaining an average value. All values are sent by bluetooth, but the average temperature makes a set of LEDs light up according to some parameters.

Code

Temperatures with LM35 and DS18B20Arduino
just open the file, modify to your arduino and be happy
/*Code adapted from many sources available in internet like http://www.instructables.com/id/ARDUINO-TEMPERATURE-SENSOR-LM35/
and http://www.instructables.com/id/How-to-use-DS18B20-Temperature-Sensor-Arduino-Tuto/
send me an e-mail if you need jomar.amaral@gmail.com
*/
#include <OneWire.h>
#include <DallasTemperature.h>

#define ONE_WIRE_BUS_1 2

OneWire oneWire_in(ONE_WIRE_BUS_1);

DallasTemperature sensor_inhouse(&oneWire_in);

float DS; //DS18B20 is conected to digital pin 2
int ledPin[] = {38, 40, 42, 44, 46, 48, 50, 52}; //pins used, you can modify to you arduino board
const int LM35 = A15; //define o pino que le a saida do lm35
float T; //variavel que armazena a temperatura medida
float valor;
float TM;

void setup(void)
{
    Serial.begin(9600);
   // Serial.println("Dallas Temperature Control Library Demo - TwoPin_DS18B20");

    sensor_inhouse.begin();
    for (int j=0; j<8; j++)
   {
    pinMode(ledPin[j], OUTPUT); // configura pino digital como sada
   }

}

void loop(void)
{
//    Serial.print("Requesting temperatures...");
    sensor_inhouse.requestTemperatures();
  //  Serial.println(" done");
DS = sensor_inhouse.getTempCByIndex(0);
    Serial.print("Temperatura em DS18: ");
 //   Serial.println(sensor_inhouse.getTempCByIndex(0));
   Serial.println(DS);
   delay(1000);
  
  valor = analogRead(LM35);
  T = ((5*(valor)*100)/1024);
  Serial.print("Temperatura em LM35: ");
  Serial.println(T);
  delay(1000);

TM = (DS + T)/2;
  Serial.print("***Temperatura mEdia em C: ");
  Serial.println(TM);
  delay(3000);

  if (TM < 20.00)
  {
  digitalWrite(52,HIGH);
  digitalWrite(50,LOW);
  digitalWrite(48,LOW);
  digitalWrite(46,LOW);
  digitalWrite(44,LOW);
  digitalWrite(42,LOW);
  digitalWrite(40,LOW);
  digitalWrite(38,LOW);
  }
  if ((TM >= 20.00) && (TM < 21.50))
  {
  digitalWrite(52,HIGH);
  digitalWrite(50,HIGH);
  digitalWrite(48,LOW);
  digitalWrite(46,LOW);
  digitalWrite(44,LOW);
  digitalWrite(42,LOW);
  digitalWrite(40,LOW);
  digitalWrite(38,LOW);
  }
  if ((TM >= 21.50) && (TM < 23.50))
  {
  digitalWrite(52,HIGH);
  digitalWrite(50,HIGH);
  digitalWrite(48,HIGH);
  digitalWrite(46,LOW);
  digitalWrite(44,LOW);
  digitalWrite(42,LOW);
  digitalWrite(40,LOW);
  digitalWrite(38,LOW);
  }
  if ((TM >= 23.50) && (TM < 25.50))
  {
  digitalWrite(52,HIGH);
  digitalWrite(50,HIGH);
  digitalWrite(48,HIGH);
  digitalWrite(46,HIGH);
  digitalWrite(44,LOW);
  digitalWrite(42,LOW);
  digitalWrite(40,LOW);
  digitalWrite(38,LOW);
  }
    if ((TM >= 25.50) && (TM < 27.50))
  {
  digitalWrite(52,HIGH);
  digitalWrite(50,HIGH);
  digitalWrite(48,HIGH);
  digitalWrite(46,HIGH);
  digitalWrite(44,HIGH);
  digitalWrite(42,LOW);
  digitalWrite(40,LOW);
  digitalWrite(38,LOW);
  }
  if ((TM >= 27.50) && (TM < 30.00))
  {
  digitalWrite(52,HIGH);
  digitalWrite(50,HIGH);
  digitalWrite(48,HIGH);
  digitalWrite(46,HIGH);
  digitalWrite(44,HIGH);
  digitalWrite(42,HIGH);
  digitalWrite(40,LOW);
  digitalWrite(38,LOW);
  }
  if ((TM >= 30.00) && (TM < 33.00))
  {
  digitalWrite(52,HIGH);
  digitalWrite(50,HIGH);
  digitalWrite(48,HIGH);
  digitalWrite(46,HIGH);
  digitalWrite(44,HIGH);
  digitalWrite(42,HIGH);
  digitalWrite(40,HIGH);
  digitalWrite(38,LOW);
  }  
  if (TM >= 33.00)
  {
  digitalWrite(52,HIGH);
  digitalWrite(50,HIGH);
  digitalWrite(48,HIGH);
  digitalWrite(46,HIGH);
  digitalWrite(44,HIGH);
  digitalWrite(42,HIGH);
  digitalWrite(40,HIGH);
  digitalWrite(38,HIGH);
  }
}

Schematics

Full schematic
Just conect wires and components as it is.
lm35_e_ds18b20_FuqSQaQkrQ.fzz
Full image
Just conect as it is in image.
Lm35 e ds18b20 bb kv76kxqydn

Comments

Similar projects you might like

CPU and RAM Usage Monitor (Windows & Linux)

Project showcase by thesahilsaluja

  • 4,797 views
  • 17 comments
  • 14 respects

TFT Graphing: Live History Graphs

Project tutorial by Andrei Florian

  • 879 views
  • 3 comments
  • 12 respects

AWS - Arduino Weather Station

Project tutorial by GilettaStefano

  • 7,212 views
  • 11 comments
  • 27 respects

Arduino Sunflower: An Electronic Sun-Dancer

Project tutorial by SURYATEJA

  • 3,774 views
  • 2 comments
  • 12 respects

Backpack Alarm

Project tutorial by Tomi Chen

  • 3,132 views
  • 12 comments
  • 31 respects

HUD Alarm Clock

Project in progress by Chukwuemeka Ike

  • 170 views
  • 0 comments
  • 1 respect
Add projectSign up / Login