Using a Servo SG90 with Arduino

Featured Video Play Icon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include <Servo.h>
Servo servo;

void setup() {
  servo.attach(8);
  servo.write(angle);
}

void loop()
{
 // scan from 0 to 180 degrees
  for(angle = 10; angle < 180; angle++)  
  {                                  
    servo.write(angle);              
    delay(15);                  
  }
  // now scan back from 180 to 0 degrees
  for(angle = 180; angle > 10; angle--)    
  {                                
    servo.write(angle);          
    delay(15);      
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *