donmike25 icon

servo motor for smarties

donmike25 | PRO | 03/18/16 09:53:24 AM UTC | 0 ⭐ | 151 👁️ | Never ⏰ | []
C |

650 B

|

None

|

0 👍

/

0 👎

// Mini-project for candy dispenser (Smarties) using servo motor and Arduino
 
#include  <SoftwareServo.h> //header file for servo motor
Servo servol;
int switchstate=0;
void setup()
{
pinMode(6,OUTPUT); // digital pin 6 as output
servol.attach(9); // digital pin 9 as output
}
void loop()
{
switchstate=digitalRead(5); //digitalRead checks the chosen pin 
if(switchstate==LOW) //conditional statement
{
servol.write(1); //it commands the servo motor to set its position to degree 1
}
if(switchstate==HIGH)
{
servol.write(179); //it commands the servo motor to set its position to degree 179
}
delay(2000); //it calls a delay for 2 seconds
}

Comments