Hi guys, this is my first post, and i'm not the best with arduino yet. I'm trying to build a circuit which will turn on/off servo when the button is pressed. And i can't get it to work at all at the moment. What am I doing wrong?
#include <Servo.h>
const int servoPin=8;
const int buttonPin=2;
int buttonState=0;
int directionState=0;
Servo myservo;
int pos=0;
void setup() {
myservo.attach(8);
pinMode(buttonPin, INPUT);
}
void loop() {
buttonState=digitalRead(buttonPin);
if(directionState == 0){
if (buttonState=HIGH) {
directionState=1;
for(pos=0;pos<180;pos=pos+1){
}
}
}
else if(directionState==1){
if(buttonState==HIGH){
directionState=0;
for(pos=180;pos>=1;pos=pos-1)
{
myservo.write(pos);
delay(15);
}
}
}
}
Servo should be turning an angle when the button is pressed, as I said earlier. My circuit is connected as you can see on attached picture. However, my circuit and / or code don't seem to be working together, and at the end I'm getting no reaction...