/*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);
}
}
Comments