#include <Servo.h>
#include <LiquidCrystal.h>
Servo myservo;
int pos = 0;
const int trigPin1 = 9;
const int echoPin1 = 8;
const int trigPin2 = 7;
const int echoPin2 = 6;
const int led = 13;
int sensorPin = A0;
int sensorValue;
int limit = 950;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
float moisture;
bool wet = false, obs2 = false;
void setup()
{
lcd.begin(16, 2);
lcd.print("Waste Segregator");
myservo.attach(10);
pinMode(trigPin1, OUTPUT);
pinMode(echoPin1, INPUT);
pinMode(trigPin2, OUTPUT);
pinMode(echoPin2, INPUT);
pinMode(led, OUTPUT);
myservo.write(pos);
}
// UV Obstacle Sensing Function
bool obstacle(int trigPin, int echoPin, String s1){
//for(int i=0;i<5;i++){
//UV code
long duration, distance;
digitalWrite(trigPin, HIGH);
delayMicroseconds(1000);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.1;
Serial.print(distance);
Serial.println("CM"+s1);
delay(10);
if(distance<=12) return true;
else return false;
//}
}
// Soil Moisture Sensor Code
bool wetSense(){
for(int i = 0; i < 8 ; i++) {
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;
}
//LCD Display
void printer(String s){
lcd.setCursor(0, 1);
lcd.print(s);
delay(2000);
}
void loop()
{
Serial.begin(9600);
printer(" Monitoring... ");
if(obstacle(trigPin1, echoPin1,"one") == true){
delay(11500);
for(int i = 0 ; i < 5 ; i++ ) {
obs2 = obstacle(trigPin2, echoPin2,"two");
delay(200);
if(obs2 == true) {
delay(5300);
wet = (wetSense());
break;
}
}
if(obs2==true && wet==true){
myservo.write(pos+190);
printer(" Wet Waste ");
}
else if(obs2==true && wet==false){
myservo.write(pos);
printer(" Dry Waste ");
myservo.write(pos);
}
else if(obs2==false)
printer(" Magnetic Waste ");
delay(2000);
}
delay(1000);
Comments