I have two DS18B20 digital temp sensors hooked up to my Arduino (for indoor and outdoor temps) which then displays each onto my 20x4 LCD.
All works nicely, except occasionally, very occasionally I'll get bogus readings for one or both of the sensors. Usually the reading is -127.00C but occasionally it'll jump up to 85.00C.
Now the outdoor sensor is attached to a piece of cat5 cable which is around 5 metres long, so I thought maybe this was the problem. But I'm wondering if there's any way I can code it to "ignore" these readings?
I wouldn't be so fussed if it didn't affect the LCD's readout, i.e.:
The display shows "20.50c" for instance, but when the -127.00 reading occurs, it writes these chars to the LCD which don't get 'erased' so the next correct reading will show up as "20.50c0" for example.
I hope that makes sense. I'm a total Arduino and programming noob so these questions may be very dumb. And here's my code for you to all laugh at:
LiquidCrystal lcd(4, 5, 6, 7, 8, 9);
#define CONTRAST_PIN 9
#define BACKLIGHT_PIN 7
#define CONTRAST 100
// 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)
// Pass our oneWire reference to Dallas Temperature.
analogWrite (CONTRAST_PIN, CONTRAST);
lcd.begin(4,20); // initialize the lcd
// Start up the library
sensors.begin(); // IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
float outdoors = sensors.getTempCByIndex(0);
float indoors = sensors.getTempCByIndex(1);
// call sensors.requestTemperatures() to issue a global temperature
// request to all devices on the bus
sensors.requestTemperatures(); // Send the command to get temperatures
Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"? You can have more than one IC on the same bus. 0 refers to the first IC on the wire
if (indoors>= 25)
digitalWrite (reLED, HIGH);
digitalWrite (grLED, LOW);
digitalWrite (reLED, LOW);
digitalWrite (grLED, HIGH);
if (outdoors< 1.0)
digitalWrite (blLED, HIGH);
digitalWrite (blLED, LOW);
Oh I should add that if I power it from USB the bogus readings are frequent, but if I power it from my usual source of a 12v wall wart, they're very infrequent. I left it running all evening and it was fine but I got up this morning and saw one