I am trying to design a temperature sensor for environment control. the sensor shifts the LED when cooling occurs below 25C and vice versa for heating turning the LED to red, given below I have the code. But I am having issues as there is no display appearing, it is blank shining. Can anyone please suggest me ??
Also which LiquidCrystal_I2C library are you using? some require a lcd.init();orlcd.begin();==> check the examples provided with the library you picked
So, the Red LCD starts as I run the code, but then when I am putting the sensor in the cold medium for blue LED, the LED is not switching to blue also there is nth appearing on the display about the temperature reading.
It is not displaying anything!!
I have verified the connections, seems correct to me
given below is an image for your understanding and the latest code which I have used.
I believe the sensor will provide us a digital signal which has to be converted to voltage and then temperature for the display. Please do correct me if I am wrong
#include <Wire.h>
#include <DallasTemperature.h>
#include <LiquidCrystal_I2C.h>
#define RELAY1 4 // Relay heating
#define RELAY2 6 // Relay cooling
int red = 8 ; // red light heating
int blue = 2; // blue LED cooling
int ledPin = 13; // LED connected to digital pin 13
int inPin = 7; // pushbutton connected to digital pin 7
int val = 0;
int voltage = 0;
int temp = 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);
float reading;
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");
val = digitalRead(inPin); // read the input pin
digitalWrite(ledPin, val); // sets the LED to the button's value
voltage = val * (5000 / 1024);
temp = ([voltage - 500] / 10);
lcd.print("temp is", 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);
lcd.display();
}
}