Servo button

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() {
  pinMode(buttonPin, INPUT);

void loop() {

  if(directionState == 0){
    if (buttonState=HIGH) {

else if(directionState==1){

if(directionState == 0){
    if (buttonState=HIGH)

One of these comparisons is wrong.

Can you tell us what that code should do ? Should it turn the servo by some angle after you press the button ? What is going wrong ? How we'll know whats wrong if you don't tell us ? Please check this-


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...

Have you fixed the code?
Why doesn’t the first conditional pair move the servo?

i can’t see what’s wrong with code, any suggestions?

Have another look at reply #1

AWOL: Have another look at reply #1

I looked at it again... still can't see what's wrong with it. Beginnings are so frustrating :(


directionState == 0 or buttonState=HIGH

is NOT being set (correctly)

*usually = means assignment == means conditional check