Hello Everyone!!
I am trying to write the Arduino code for the temperature sensor where after a certain value of temperature (more than 25C) the LED shifts to blue from red and the temperature is displayed. I used the following code which is given below, but there were some issues with the display as the display was not showing the output at the same time the LED is not shifting to blue when I am trying to put the temperature sensor in the sample. I have no clue seems I am missing something in the code or there are some errors. I was trying to look into the forum for some answers, but couldn't find some. Please do help. Following is the code below which I am using.
#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#define RELAY1 4 // Relay heating
#define RELAY2 6 // Relay cooling
#define SENSOR_RESOLUTION 9
int red = 8 ; // red light heating
int blue = 2; // blue LED cooling
#define int sensorPin = 0;
#define BACKLIGHT_PIN 13
#define ONE_WIRE_BUS 7
LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
OneWire oneWire(ONE_WIRE_BUS);
DallasTemperature sensors(&oneWire);
void setup() {
Serial.begin(9600);
sensors.begin();
pinMode(red, OUTPUT);
pinMode(blue, OUTPUT);
pinMode(RELAY1, OUTPUT);
pinMode(RELAY2, OUTPUT);
}
void loop() {
lcd.setCursor(0, 0);
lcd.print("TEMP CONTROL");
sensors.requestTemperatures();
float temperature = sensors.getTempCByIndex(0);
float temp;
temp= temperature * 999999;
lcd.setCursor(0, 2);
lcd.print(" ");
lcd.print(temp);
lcd.print("\337C");
if (temp < 25)
{
digitalWrite(red, HIGH);
digitalWrite(blue, LOW);
lcd.setCursor(0, 3);
lcd.print("heating ");
digitalWrite(RELAY1, 1);
digitalWrite(RELAY2, 0);
digitalWrite(red, HIGH);
digitalWrite(blue, LOW);
}
else if (temp > 25)
{
digitalWrite(RELAY1, 0);
digitalWrite(RELAY2, 1);
digitalWrite(red, LOW);
digitalWrite(blue, HIGH);
lcd.setCursor(0, 4);
lcd.print("Cooling ");
lcd.setCursor(0, 3);
}
}