#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// 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);
const uint8_t ledPin = 13; // LED connected to digital pin 13
void setup(void)
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperature...");
sensors.requestTemperatures(); // Send the command to get temperatures
float temp = sensors.getTempCByIndex(0);
Serial.print(temp);
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
if (temp < 35 || temp > 39.4){
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Serial.println (" Celsius,outside the normal body temperature range");
}
else{
digitalWrite(ledPin, LOW);
Serial.println (" Celsius, within the normal body temperature range");
}
}
[code]
Turn it on. After a while, turn it off. After a while turn it on. After a while, turn it off. Repeat as many times as you want.
If you want the LED to blink as long as the temperature is out of range, look at the blink without delay example.
If the temperature is out of range, and the LED is on, and has been on long enough, turn it off.
if the temperature is out of eange, and the LED is off, and has been off long enough, turn it on.
What this has to do with error 50 or error 54, or what the hell those are, or what your code issues are are not at all clear.
I tried to format the code as best as I could. I am beginner . I just want the light to blink when it is outside range. Thanks
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
// 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);
const uint8_t ledPin = 13; // LED connected to digital pin 13
void setup(void)
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
// start serial port
Serial.begin(9600);
Serial.println("Dallas Temperature IC Control Library Demo");
// Start up the library
sensors.begin();
}
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperature...");
sensors.requestTemperatures(); // Send the command to get temperatures
float temp = sensors.getTempCByIndex(0);
Serial.print(temp);
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
if (temp < 35 || temp > 39.4)
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
}
Serial.println (" Celsius,outside the normal body temperature range");
}
else
{
digitalWrite(ledPin, LOW);
Serial.println (" Celsius, within the normal body temperature range");
}
}
[code]
Just to make clear what PaulS says
Your code, with some added comments :
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperature...");
sensors.requestTemperatures(); // Send the command to get temperatures
float temp = sensors.getTempCByIndex(0);
Serial.print(temp);
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
if (temp < 35 || temp > 39.4) { // better if alone in a line
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
} // oups.... end of if statement !! --> delete this line
Serial.println (" Celsius,outside the normal body temperature range");
} // oups ends loop() !!
else{
digitalWrite(ledPin, LOW);
Serial.println (" Celsius, within the normal body temperature range");
}
what it should be (with some other comments ) :
void loop(void)
{
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
Serial.print(" Requesting temperature...");
sensors.requestTemperatures(); // Send the command to get temperatures
float temp = sensors.getTempCByIndex(0);
Serial.print(temp);
// You can have more than one IC on the same bus.
// 0 refers to the first IC on the wire
if (temp < 35 || temp > 39.4)
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW); // sets the LED off
delay(1000); // waits for a second
Serial.println (" Celsius,outside the normal body temperature range");
} //end of if
else
{
digitalWrite(ledPin, LOW);
Serial.println (" Celsius, within the normal body temperature range");
} //end of else
} // end of loop()
and (also pointed out by PaulS ) , if you don't want to wait 2s (the T° has maybe already decreased ; ) ) , look at the blink without delay axample