// Include the libraries we need
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 3    // Data wire is plugged into port 3 on the motor base shield
#define ledPin 5    //connect led to port 5 on the motor base shield

// Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature. 
DallasTemperature sensors(&oneWire);


void setup(void)
{
  // start serial port
  Serial.begin(9600);
  Serial.println("Dallas Temperature IC Control Library Demo");
  // Start up the library
  sensors.begin();  //start the sensors here
  pinMode(ledPin,OUTPUT);
}

/*
 * Main function, get and show the temperature
 */
void loop(void)
{ 
  float t;
  // call sensors.requestTemperatures() to issue a global temperature 
  // request to all devices on the bus
  Serial.print("Requesting temperatures...");
  sensors.requestTemperatures(); // Send the command to get temperatures
  Serial.println("DONE");
  // After we got the temperatures, we can print them here.
  // We use the function ByIndex, and as an example get the temperature from the first sensor only.
  t = sensors.getTempCByIndex(0);
  Serial.print("Temperature: ");
  Serial.print(t);  
  Serial.println(" *C");
  if(t>40){
    digitalWrite(ledPin,HIGH);
    }
    else{
      digitalWrite(ledPin,LOW);
      }   
   delay(1000);
}
