a project with a servo motor :)

hello everyone , i'm a french student , i have to present a project in about a month
my project is :
how to make my servomotor continue rotation ?
i have to turn it when " DETECTION_MOUV" and "DETECTION_US" are HIGH and if the "DETECTION_US" is LOW i have to stop it :
i MADE THIS :

DETECTION_MOUV and DETECTION_US is a sensors

#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 to the servo object PIR_MOTION_SENSOR2_value.attach(2);

digitalWrite(pinServo,LOW);

}

void loop()
{

if (DETECTION_MOUV==HIGH and DETECTION_US==LOW)
{ myservo.write(180); // tell servo to go to position in variable 'pos'
}

if (DETECTION_MOUV==HIGH and DETECTION_US==HIGH)
{ myservo.write(90) ; // tell servo to go to position in variable 'pos'
}

if (DETECTION_MOUV==LOW and DETECTION_US==LOW)

{ myservo.write(90); // tell servo to go to position in variable 'pos'
}
}

thanks for your help :slight_smile:

read this
Then fix the layout of your code, make it readable. Ctrl-T in the IDE helps in formatting. Curly braces on their own line (opening ones at the end of the previous line are OK), and repost cleaned up code between code tags as explained in the link.

oyho:
how to make my servomotor continue rotation ?

First thought "get a continuous rotation servo".
Second thought "what is it what you're trying to do, really?".

Microcontrollers 101: The pin number is not the same as the value that the pin reads back.

digitalRead is your friend.

Servo motors do not continuously rotate. They provide closed loop position control typically over 180 deg. To make the servo rotate continuously you would have to physically modify it, It then becomes a motor with speed control.

So is your project to take a standard servo and modify it?

oyho:

 { myservo.write(180);             // tell servo to go to position in variable 'pos'

What you do in code does not match what your comment says.

Thanks for your answers
1- I have to rotate it when DETECTION_MOUV (a sensor) is detecting something and then I have to stop it when DETECTION_US is detecting something so ...
DETECTION_MOUV is a movement sensor
DETECTION_US is an ultrasound sensor :slight_smile:
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 :frowning: )

• I use a continuous rotation servomotor ^-^
Thank you for helping me and sorry if my English is not good
And last thing I disn’ Understand why I have to use digitalWrite

You have to use digitalRead to read the state of the pin.