Guys I need help plz…help me actually I m creating one project and in that I m using moisture sensor+ir sensor+servo motor.
I need help regarding code like I want to control servo motor with moisture sensor ,if any dry object will come in contact with moisture sensor then ir sensor have to detect it and rotate the sevo motor left and if any wet object will come in contact with moisture sensor then ir sensor have to detect it and rotate the servo motor right side. I wrote one code but in that code my servo motor is rotating only right side when any wet object is coming in contact.so plz… help me for modifying the code Or plz…send the correct code so that it will work for both condition left(dry) and right (wet)
#include <Servo.h>
Servo servo;
int moisture_sensor = D2;
int servo_motor =16;
int ir_sensor=5;
int val;
void setup(){
servo.attach( servo_motor );
pinMode(moisture_sensor,INPUT);
pinMode(ir_sensor,INPUT);
}
void loop(){
val=digitalRead(moisture_sensor );
if (digitalRead(ir_sensor)==LOW && val==0)
{
servo.write(0);
}
else if (digitalRead(ir_sensor)==HIGH && val==1)
{
servo.write(180);
}
else
{
servo.write(0);
}
}