Hey guys. Im fairly new to all of this and i have hit a road block. Before i made a heater controller for my aquarium using an uno, DS18B20, and some relays. it works well but its been a while and now i want to make a better version.
ive just started on my new version, this time using two ds18b20, averaging the temps between the two and then using that number to turn the aquarium heaters on and off. I know my code is probably a horrible way to accomplish this but it seems to be kind of working. my problem is i need my average temp reading to two decimal points like the two ds18b20 are reading. currently i get
temp1: xx.xx F
temp2: xx.xx F
Average: xx F
Can anyone offer some advice?
this is what i have so far
#include <LiquidCrystal.h>
#include <OneWire.h>
#include <DallasTemperature.h>
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
#define ONE_WIRE_BUS 6
#define TWO_WIRE_BUS 7
OneWire oneWire(ONE_WIRE_BUS);
OneWire twoWire(TWO_WIRE_BUS);
DallasTemperature sensor1(&oneWire);
DallasTemperature sensor2(&twoWire);
void setup()
{
lcd.begin(20, 4);
sensor1.begin();
sensor2.begin();
//Temp1
lcd.setCursor (0, 0);
lcd.print ("Temp 1:");
lcd.setCursor (14, 0);
lcd.print ("F");
//Temp2
lcd.setCursor (0, 1);
lcd.print ("Temp 2:");
lcd.setCursor (14, 1);
lcd.print ("F");
//Average
lcd.setCursor (0, 2);
lcd.print ("Average:");
lcd.setCursor (14, 2);
lcd.print ("F");
}
void loop()
{
sensor1.requestTemperatures();
sensor2.requestTemperatures();
//Average temp reading
int a = sensor1.getTempFByIndex(0);
int b = sensor2.getTempFByIndex(0);
int c = 2;
int sum = a + b;
int average = sum / c;
//Temp1 Reading
lcd.setCursor(9, 0);
lcd.print(sensor1.getTempFByIndex(0));
//Temp2 Reading
lcd.setCursor(9, 1);
lcd.print(sensor2.getTempFByIndex(0));
//Average of two readings
lcd.setCursor (9, 2);
lcd.print (average);
delay(500);
}