Code below is to read 4 thermometers and use values to turn on or off the heaters (I'm stuck at reading).
I'm reading and displaying temperature very well, but it comes to the problem, where I want to set the limit of heating, a value of 37 degrees. It comes to the problem, when I want to read the value of "tempa", but the Arduino doesn't respond properly: it somehow reads the value as char or I get the output in hex instead of integer (although I never declared a character in whole program).
It can be seen in last 2 lines before "CHANNEL_2".
Lines are:
lcd.setCursor(10, 0); //termometer
lcd.write(tempa); //termometer
absoluta, absolutb, absolutc and absolutd are variables, which are technically values of temperature in Kelvin.
tempa, temb, tempc and tempd are variables, the temperature in celsius.
#include <LiquidCrystal.h>
#define LM335_pin 0 // LM335 output pin is connected to Arduino A0 pin
#define LM335_pio 1 // LM335 output pin is connected to Arduino A0 pin
#define LM335_pip 2 // LM335 output pin is connected to Arduino A0 pin
#define LM335_pir 3 // LM335 output pin is connected to Arduino A0 pin
const int rs = 7, en = 8, d4 = 5, d5 = 4, d6 = 3, d7 = 2; // LCD module connections (RS, E, D4, D5, D6, D7)
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
//-----------------------HEATERS----------------------------------------
//int grelea = 11; //heater_1
//int greleb = 10; //heater_2
//int grelec = 9; //heater_3
void setup() {
lcd.begin(20, 4);
// pinMode(grelea, OUTPUT);
// pinMode(greleb, OUTPUT);
// pinMode(grelec, OUTPUT);
}
int absoluta, tempa; //sensor_1
int absolutb, tempb; //sensor_2
int absolutc, tempc; //sensor_3
int absolutd, tempd; //sensor_4
void loop() {
delay(1000);
//-----------------------CHANNEL_1----------------------------------------
absoluta = analogRead(LM335_pin) * 0.489;
tempa = absoluta - 273;
lcd.setCursor(0, 0); //termometer
lcd.setCursor(0, 0); //termometer
lcd.write("Temp1="); //termometer
lcd.setCursor(8, 0); //termometer
lcd.write((tempa / 10)% 10 + 48); //termometer
lcd.setCursor(9, 0); //termometer
lcd.write(tempa % 10 + 48); //termometer
lcd.setCursor(10, 0); //termometer
lcd.write(char(223)); //termometer
lcd.setCursor(11, 0); //termometer
lcd.write("C"); //termometer
lcd.setCursor(15, 0); //termometer
lcd.write(tempa); //termometer
//---------------------------------------------------------------
//-----------------------CHANNEL_2----------------------------------------
absolutb = analogRead(LM335_pio) * 0.489;
tempb = absolutb - 273;
lcd.setCursor(0, 1); //termometer
lcd.write("Temp2="); //termometer
lcd.setCursor(8, 1); //termometer
lcd.write((tempb / 10) % 10 + 48); //termometer
lcd.setCursor(9, 1); //termometer
lcd.write(tempb % 10 + 48); //termometer
lcd.setCursor(10, 1); //termometer
lcd.write(char(223)); //termometer
lcd.setCursor(11, 1); //termometer
lcd.write("C"); //termometer
//---------------------------------------------------------------
//-----------------------CHANNEL_3----------------------------------------
absolutc = analogRead(LM335_pip) * 0.489;
tempc = absolutc - 273;
lcd.setCursor(0, 2); //termometer
lcd.write("Temp3="); //termometer
lcd.setCursor(8, 2); //termometer
lcd.write((tempc / 10) % 10 + 48); //termometer
lcd.setCursor(9, 2); //termometer
lcd.write(tempc % 10 + 48); //termometer
lcd.setCursor(10, 2); //termometer
lcd.write(char(223)); //termometer
lcd.setCursor(11, 2); //termometer
lcd.write("C"); //termometer
//---------------------------------------------------------------
//-----------------------CHANNEL_4----------------------------------------
absolutd = analogRead(LM335_pir) * 0.489;
tempd = absolutd - 273;
lcd.setCursor(0, 3); //termometer
lcd.write("Temp4="); //termometer
lcd.setCursor(8, 3); //termometer
lcd.write((tempd / 10) % 10 + 48); //termometer
lcd.setCursor(9, 3); //termometer
lcd.write(tempd % 10 + 48); //termometer
lcd.setCursor(10, 3); //termometer
lcd.write(char(223)); //termometer
lcd.setCursor(11, 3); //termometer
lcd.write("C"); //termometer
//---------------------------------------------------------------
}
lcd.print(tempa);
– Juraj Sep 17 '18 at 14:03