How to add LCD display with water sensor??
What's wrong!!
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
//-----------------------------------------
//water sensor
int water;
int led1=7, led2=6, led3=5; // وضع أسماء لأرقام بعض الأرجل
int sensorPin=A0;
//-----------------------------------
int ThermistorPin = 2 ;
//float temp2;
int Vo, LED=13;
//float hum;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup() {
//------------
//water sensor.
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
Serial.begin(9600);
//-------------
dht.begin();
pinMode(LED,OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
}
void loop() {
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0)/ 5.0 + 32.0;
Serial.print(" %, Temperature: ");
Serial.print(Tc);
Serial.println(" C");
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Temp: ");
lcd.print(Tc);
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
delay(500);
if (Tc>=40)
{
digitalWrite(LED,LOW);
}
else
{
digitalWrite(LED,HIGH);
}
//---------------------------
//water sensor.
water=analogRead(sensorPin);
Serial.println(water);
if((water>100) && (water<450))
{
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("1");
}
else if((water>=500) && (water<650))
{
digitalWrite(led2,HIGH);
digitalWrite(led1,HIGH);
digitalWrite(led3,LOW);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("2");
}
else if((water>=700) && (water<900))
{
digitalWrite(led2,HIGH);
digitalWrite(led1,HIGH);
digitalWrite(led3,HIGH);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("3");
}
else
{
digitalWrite(led2,LOW);
digitalWrite(led1,LOW);
digitalWrite(led3,LOW);
lcd.clear();
lcd.setCursor(0,1);
lcd.print("0");
}
//------------------------------
Line 47 dht.begin(); You have not included the library nor constructed a dht object.
Line 146 is missing a } to close the loop() function.
After commenting out line 47 and inserting a } to close loop(), the code compiles. If there is anything else wrong, you will have to explain what is wrong better than "it doesn't work".
That's work.
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
//-----------------------------------------
//water sensor
int water;
int led1=7, led2=6, led3=5;
int sensorPin=A0;
//-----------------------------------
int ThermistorPin = 2 ;
int Vo, LED=3;
float R1 = 10000;
float logR2, R2, T, Tc, Tf;
float c1 = 1.009249522e-03, c2 = 2.378405444e-04, c3 = 2.019202697e-07;
#define I2C_ADDR 0x27
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
LiquidCrystal_I2C lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);
void setup() {
//------------
//water sensor.
pinMode(led1,OUTPUT);
pinMode(led2,OUTPUT);
pinMode(led3,OUTPUT);
Serial.begin(9600);
//-------------
pinMode(LED,OUTPUT);
Serial.begin(9600);
lcd.begin(16,2);
lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
lcd.setBacklight(HIGH);
}
void loop() {
Vo = analogRead(ThermistorPin);
R2 = R1 * (1023.0 / (float)Vo - 1.0);
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2));
Tc = T - 273.15;
Tf = (Tc * 9.0)/ 5.0 + 32.0;
Serial.print(" %, Temperature: ");
Serial.print(Tc);
Serial.println(" C");
delay(500);
//---------------------------
water=analogRead(sensorPin);
Serial.println(water);
if (Tc>=40)
{
digitalWrite(LED,HIGH);
delay(50);
digitalWrite(LED,LOW);
delay(50);
}
else
{
digitalWrite(LED,LOW);
}
if((water>100) && (water<450))
{
digitalWrite(led1,HIGH);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("W.Temp: ");
lcd.print(Tc);
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("LOW water");
}
else if((water>=500) && (water<650))
{
digitalWrite(led2,HIGH);
digitalWrite(led1,HIGH);
digitalWrite(led3,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("W.Temp: ");
lcd.print(Tc);
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("CENTER water");
}
else if((water>=700) && (water<900))
{
digitalWrite(led2,HIGH);
digitalWrite(led1,HIGH);
digitalWrite(led3,HIGH);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("W.Temp: ");
lcd.print(Tc);
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("FUL water");
}
else
{
digitalWrite(led2,LOW);
digitalWrite(led1,LOW);
digitalWrite(led3,LOW);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("W.Temp: ");
lcd.print(Tc);
lcd.print(" ");
lcd.print((char)223);
lcd.print("C");
lcd.setCursor(0,1);
lcd.print("NO water");
}
}