Arduino circuit turns on LED but not servo -


i have project have button on breadboard activates servo via programmed arduino. currently, code:

#include <servo.h>  servo sa;  int d=2;   // store on or off value  void setup(){   sa.attach(a0);   pinmode(2,input);   pinmode(a0,output);   pinmode(13,output);   sa.write(90); }  void loop(){   d=digitalread(2);   if(d==0){     sa.write(90);     digitalwrite(13,high);   }elsethe   sa.write(0);}   digitalwrite(13,low); }  

the led in here test of button (which had had issues with). when button pressed, led lights intended in if statement. servo (towerpro mg995) wired directly vex 7.2 volt battery power, know works power. however, button not activating servo or registering response @ all. there issue code? servo's data cord wired straight pin a0 in code.

i rewrote code, check conections , try code:

#include <servo.h>  servo sa;  int d=2;   // store on or off value void setup(){   pinmode(d, input);   sa.attach(9); //pin 9   //sa.write(90); //will move 90degrees }  void loop(){   if(digitalread(d)==high){   sa.write(90);   digitalwrite(13,high);   }   else{   sa.write(0);   digitalwrite(13,low);   }  } 

remember, servo move if button pressed, if release back.


Comments

Popular posts from this blog

javascript - Confirm a form & display message if form is valid with JQuery -

Retrieving ETA (estimated time of arrival) with Google Distance Matrix API and public transit as transport mode -

android - ConstraintLayout: Realign baseline constraint in case if dependent view visibility was set to GONE -