/*********
Rui Santos
Complete project details at https://randomnerdtutorials.com
Based on the Dallas Temperature Library example
*********/
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is conntec to the Arduino digital pin 4
#define ONE_WIRE_BUS 4
int Led1 = 10;
int Led2 = 11;
int Led3 = 12;
// Setup a oneWire instance to communicate with any OneWire devices
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature sensor
DallasTemperature sensors(&oneWire);
void setup(void)
{
// Start serial communication for debugging purposes
Serial.begin(9600);
// Start up the library
sensors.begin();
}
void loop(void){
float Temperatura = 0;
// Call sensors.requestTemperatures() to issue a global temperature and Requests to all devices on the bus
sensors.requestTemperatures();
Temperatura = sensors.getTempCByIndex(0);
Serial.print("Celsius temperature: ");
// Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
Serial.print(sensors.getTempCByIndex(0));
Serial.print(" - Fahrenheit temperature: ");
Serial.println(sensors.getTempFByIndex(0));
delay(1000);
if(Temperatura < 20.00)
{
digitalWrite( Led1, HIGH);
digitalWrite( Led2, LOW);
digitalWrite( Led3, LOW);
}
if(Temperatura >= 25.0)
{
digitalWrite( Led1, LOW);
digitalWrite( Led2, LOW);
digitalWrite( Led3,HIGH);
}
if((Temperatura < 20.00) && (Temperatura > 25.00))
{
digitalWrite( Led1, LOW);
digitalWrite( Led2, HIGH);
digitalWrite( Led3, LOW);
}
}