Devices & Components
Arduino Uno Rev3
SG90 Micro-servo motor
2x2 brick
2x2 flat with stud
Software & Tools
Arduino IDE
Project description
Code
Sweep example
c_cpp
Go to examples in the editor go down to servo and use sweep and change the servo.attach from a 9 to a 12
1/* Sweep 2 by BARRAGAN <http://barraganstudio.com> 3 This example code is in the public domain. 4 5 modified 8 Nov 2013 6 by Scott Fitzgerald 7 https://www.arduino.cc/en/Tutorial/LibraryExamples/Sweep 8*/ 9 10#include <Servo.h> 11 12Servo myservo; // create servo object to control a servo 13// twelve servo objects can be created on most boards 14 15int pos = 0; // variable to store the servo position 16 17void setup() { 18 myservo.attach(9); // attaches the servo on pin 9 to the servo object 19} 20 21void loop() { 22 for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees 23 // in steps of 1 degree 24 myservo.write(pos); // tell servo to go to position in variable 'pos' 25 delay(15); // waits 15 ms for the servo to reach the position 26 } 27 for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 28 myservo.write(pos); // tell servo to go to position in variable 'pos' 29 delay(15); // waits 15 ms for the servo to reach the position 30 } 31}
Downloadable files
Text schematic
I dont have fritzing so this will do
Text schematic
Comments
Only logged in users can leave comments