Hello , I have to make my servo rotate and stop thanks to two sensors (a movement sensor an an ultrasound sensor)
1- I have to rotate it when DETECTION_MOUV (a sensor) is detecting something and I have to stop it when DETECTION_US is detecting something so ...
DETECTION_MOUV is a movement sensor
DETECTION_US is an ultrasound sensor
The program is simple, but I don't know what to do it's not work on proteus (I tried to modify it but nothing has changed
)
• I use a continuous rotation servomotor
Thank you for helping me and sorry if my English is not good
Here is my program :
#include <Servo.h>
Servo myservo;
int pinServo=6;
int DETECTION_MOUV;
int DETECTION_US;
void setup() {
DETECTION_US=2;
pinMode(DETECTION_US,INPUT);
DETECTION_MOUV=3;
pinMode(DETECTION_MOUV,INPUT);
myservo.attach(6); // attaches the servo on pin 6
digitalWrite(6,LOW);
}
void loop()
{
if (DETECTION_MOUV==HIGH and DETECTION_US==LOW)
{ myservo.write(120); // tell servo to rotate
}
if (DETECTION_MOUV==HIGH and DETECTION_US==HIGH)
{ myservo.write(0) ; // tell the servo to stop
}
if (DETECTION_MOUV==LOW and DETECTION_US==LOW)
{ myservo.write(0); // tell servo to stop or to just don’t move
}
}
PS: i hesitated to use else , so I tried but it didn’t work , I just don’t know where is the problem (this is the first time I program something so I don’t know anything about programmation )
Thanks for your help ^-^