jomar
Published © CC BY

Measuring temperatures with LM35 and DS18B20

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

BeginnerFull instructions provided7,524
Measuring temperatures with LM35 and DS18B20

Things used in this project

Hardware components

LED (generic)
LED (generic)
×8
Resistor 221 ohm
Resistor 221 ohm
×9
Texas Instruments LM35
×1
DS18B20 Programmable Resolution 1-Wire Digital Thermometer
Maxim Integrated DS18B20 Programmable Resolution 1-Wire Digital Thermometer
×1
Arduino Mega 2560
Arduino Mega 2560
You can use any other arduino as long as the analog and digital ports are changed.
×1
HC-05 Bluetooth Module
HC-05 Bluetooth Module
×1
Resistor 100 ohm
Resistor 100 ohm
×1
Resistor 4.75k ohm
Resistor 4.75k ohm
×1

Software apps and online services

Arduino IDE
Arduino IDE
Bluetooth Terminal

Story

Read more

Schematics

Full schematic

Just conect wires and components as it is.

Full image

Just conect as it is in image.

Code

Temperatures with LM35 and DS18B20

Arduino
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);
  }
}

Credits

jomar

jomar

1 project • 0 followers

Comments