Hello All
I am a complete newbie with a Ardunio UNO, but have managed to get two of the Maxim DS18B20 thermometers working on one digital pin on my Uno and have the output temperatures displayed on separate lines of a 16x2 Robot LCD shield.
That part of my code works exactly as i want it too
But !!
What I am banging my head against a brick wall with is trying to get 3 LEDs to work that I am going to use as warning lights along with the temps displayed on the LCD shield.
These would light up to show temperatures below 70 degC a blue led would light up to show too cold
71 to 99 degC a green would light up to show normal temperature
and 100 degC and above a red led would light up to show too hot.
I know that my sketch does not show this, but I need to be able to warm or cool the DS18B20 to prove that the LED thing works
I could really do with some help in getting the LED thing to work as I have now spent 4 nights trying to find the code I need to get this to work and I am not getting anywhere as the last thing I attempted to programme on was my trusty old Atari STFM !!...
I have attached my attempt so far for you guys to laugh at !!
So if some one could help me with this sketch I would much appreciate the help and any hints on best way to construct the code needed would be vastly welcomed
Thank you
// DS18B20 2 sensors with LCD
// This Arduino sketch reads DS18B20 "1-Wire" digital
// temperature sensors.
// Tutorial:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-tutorial.html
#include <OneWire.h>
#include <DallasTemperature.h>B20
#include <LiquidCrystal.h>
#include <SPI.h>
// Connections:
// rs (LCD pin 4) to Arduino pin 8
// rw (LCD pin 5) to Arduino pin ground
// enable (LCD pin 6) to Arduino pin 10
// LCD pin 15 to Arduino pin 13
// LCD pins d4, d5, d6, d7 to Arduino pins 4, 5, 6, 7
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
int backLight = 13; // pin 13 will control the backlight
// 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
OneWire oneWire(ONE_WIRE_BUS);
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
// Assign the addresses of your 1-Wire temp sensors.
// See the tutorial on how to obtain these addresses:
// http://www.hacktronics.com/Tutorials/arduino-1-wire-address-finder.html
DeviceAddress roomTemp = {
0x28, 0xF8, 0x2C, 0x47, 0x05, 0x00, 0x00, 0x47 };
DeviceAddress ductTemp = {
0x28, 0xD6, 0x8F, 0x47, 0x05, 0x00, 0x00, 0x9F
};
void setup(void)
{
// Start up the library
sensors.begin();
// set the resolution to 10 bit (good enough?)
sensors.setResolution(roomTemp, 10);
sensors.setResolution(ductTemp, 10);
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH); // turn backlight on. Replace 'HIGH' with 'LOW' to turn it off.
lcd.begin(16,2); // columns, rows. use 16,2 for a 16x2 LCD, etc.
lcd.clear(); // start with a blank screen
}
void printTemperature(DeviceAddress deviceAddress)
{
float tempC = sensors.getTempC(deviceAddress);
if (tempC == -127.00) {
lcd.print("Error");
}
else {
tempC=tempC*1.8+32;
lcd.print(tempC);
lcd.print("/");
lcd.print(DallasTemperature::toFahrenheit(tempC));
}
}
void loop(void)
{
delay(0);
sensors.requestTemperatures();
lcd.setCursor(0,0);
lcd.print("Outs Temp: ");
printTemperature(roomTemp);
lcd.setCursor(0,1);
lcd.print("Insi Temp: ");
printTemperature(ductTemp);
}
//set ledPin variables
#define bluePin 3 //dig pin 3
#define greenPin 4 //dig pin 4
#define redPin 5 //dig pin 5
//set as output so LEDs work
pinMode(bluePin, OUTPUT);
pinMode(greenPin, OUTPUT);
pinMode(redPin, OUTPUT);
tr = data[0]; if(temp <= 75) //cool
{
digitalWrite(bluePin, HIGH);
digitalWrite(greenPin, LOW);
digitalWrite(redPin, LOW);
}
else if(temp >= 76 && temp <= 80) //mid
{
digitalWrite(greenPin, HIGH);
digitalWrite(bluePin, LOW);
digitalWrite(redPin, LOW);
}
else if(temp >= 81) //hot
{
digitalWrite(bluePin, LOW);
digitalWrite(greenPin, LOW);
digitalWrite(redPin, HIGH);
}