donmike25

servo motor for smarties

Mar 18th, 2016
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.65 KB | None | 0 0
  1. // Mini-project for candy dispenser (Smarties) using servo motor and Arduino
  2.  
  3. #include  <SoftwareServo.h> //header file for servo motor
  4. Servo servol;
  5. int switchstate=0;
  6. void setup()
  7. {
  8. pinMode(6,OUTPUT); // digital pin 6 as output
  9. servol.attach(9); // digital pin 9 as output
  10. }
  11. void loop()
  12. {
  13. switchstate=digitalRead(5); //digitalRead checks the chosen pin
  14. if(switchstate==LOW) //conditional statement
  15. {
  16. servol.write(1); //it commands the servo motor to set its position to degree 1
  17. }
  18. if(switchstate==HIGH)
  19. {
  20. servol.write(179); //it commands the servo motor to set its position to degree 179
  21. }
  22. delay(2000); //it calls a delay for 2 seconds
  23. }
Advertisement
Add Comment
Please, Sign In to add comment