Programming a servo with sensors , need help please for my project :)

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 :frowning: )

Thanks for your help ^-^

Does the program verify? Have you tried it on a real Arduino and not just in whatever "Proteus" is? Does it run? What exactly does it do? What do you want it to do that is different?

Just saying "it's not work" doesn't tell us anything useful.

BTW if you have a continuous rotation servo then write(0) will not normally make it stop. The way they work write(90) is normally stop, write(0) is full speed one way and write(180) is full speed the other way. It might be a good idea to try the servo with the example Knob sketch to find out how it actually works.

Steve

DETECTION_US=2;
DETECTION_US==LOW)

If I tell you that LOW has the value 0 (always), does that tell you anything about your comparison?

You need to READ the pin called "DETECTION_US", and compare that value to LOW, not the pin number.

Please don't struggle with a foreign language, when the forum has a French section under the "International " section

PLEASE DO NOT POST THE SAME QUESTION IN SEVERAL DIFFERENT FORUMS

Duplicate of Programming a servo with sensors , need help please for my project :) - Programming Questions - Arduino Forum

Yes I re-post the same question because I didn’t know how to reply and if my response will be seen by others so I decided to repost it with more details :frowning: sorry , and i don’t use the French version because there where not many people who can reply me , in the international forum I can touch more people and have many responses...