#include <LiquidCrystal.h>
#include <Servo.h>
Servo myservo;
int pos = 0;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const int trigPin1 = 9;
const int echoPin1 = 8;
const int sensorPin = A0;
int sensorValue;
int limit = 950;
float moisture;
long duration;
long distance;
bool wet = false, obs = false;
void setup()
{
lcd.begin(16,2);
lcd.print("Waste Segregator");
myservo.attach(10);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
}
bool obstacle(int trigPin1, int echoPin1, String s1){
digitalWrite(trigPin1, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin1, LOW);
duration = pulseIn(echoPin1, HIGH);
distance = duration*0.034/2;
Serial.print(distance);
Serial.println("CM");
delay(10);
if(distance<=12) return true;
else return false;
}
bool wetSense(){
sensorValue = analogRead(sensorPin);
moisture = (100 - (sensorValue/1023.0)*100);
Serial.println("Analog Value : ");
Serial.println(sensorValue);
Serial.println("Moisture : ");
Serial.print(moisture);
Serial.println("%");
if(sensorValue < limit){
return true;
}
delay(500);
return false;
}
void display(String s){
delay(1000);
lcd.clear();
lcd.print(s);
delay(2000);
}
void loop() {
myservo.write(pos);
Serial.begin(9600);
display("Monitoring...");
lcd.clear();
lcd.print("Distance: ");
lcd.setCursor(0, 1);
lcd.print(distance);
lcd.print(" CM");
delay(2000);
lcd.clear();
lcd.print("Moisture: ");
lcd.setCursor(0, 1);
lcd.print(moisture);
lcd.print(" %");
if(obstacle(trigPin1, echoPin1,"one") == true){
delay(3000);
obs = obstacle;
delay(200);
if (obs==true){
wet = (wetSense());
}
}
if(obs==true && wet==true){
myservo.write(180);
display("Wet Waste");
}
else if(obs==true && wet==false){
myservo.write(90);
display("Dry Waste");
}
else {
myservo.write(pos);
}
delay(2000);
}
This is the code. I don't know what to do anymore. I tried everything that I could think of. LCD doesn't match sensors. What seems to be the problem?
