Hello,
I am working with my students on a project and we could surely use some help. Our goal is to have a dog collar that reads the temperature and lights up an LED based on the value as determined by the DS18B20. You can see how we've cobbled it together in the picture. We're using LED Sequins, so each LED has its own pin.
I have confirmed that the temp sensor works properly by using the DS18B20 example code to simply read ambient temperature. The code below sort of works, but it's not looping properly and not constantly reading the temperature(well, constantly would be a drain on battery, so a reading every 5 or 10 seconds would be preferable for something beyond this proof of concept). It seems to read it ok when first initialized, but then the light never changes.
Any help is appreciated.
Here is the code I have compiled thus far..
#include <OneWire.h>
#include <DallasTemperature.h>
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
int TempF;
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
int redled = 12;
int blueled = 6;
int whiteled = 9;
int pinkled = 10;
void setup(void)
{
Serial.begin(9600);
sensors.begin();
sensors.requestTemperatures();
float getTempF(uint8_t*);
TempF = sensors.getTempFByIndex(0);
Serial.print(sensors.getTempFByIndex(0));
pinMode(redled, OUTPUT);
pinMode(blueled, OUTPUT);
pinMode(whiteled, OUTPUT);
pinMode(pinkled, OUTPUT);
}
void loop(void)
{
if (TempF > 100)
{
digitalWrite(redled, HIGH);
}
else if (TempF > 90)
{
digitalWrite(pinkled, HIGH);
}
else if (TempF > 80)
{
digitalWrite(whiteled, HIGH);
}
else
{
digitalWrite(blueled, HIGH);
}
}