Arduino! Servo motor control
Arduino! Servo motor control
Arduino! Open-Source micro controller!
I have been spending a considerable amount of time over the recent months experimenting and learning with an ‘Arduino’. For folks who haven’t heard of it, it’s an very popular and relatively-new open source hardware microcontroller. In laymans terms, it’s a cheap ($30) and easy (USB!) way to do really cool stuff - like control motors based on sensor inputs. There is a huge online arduino community - and while I intend on posting some snippets of my arduino adventures on NYCCNC, my blog will only begin to scratch the surface of the Arduino’s potential. For folks looking to learn more, check out the links at the bottom, youtube, or do a little google-hunting.
My interest in Arduino is twofold: 1) learn more about ‘EE’ stuff - resistors, capacitors, regulators, voltage, etc and 2) make cool stuff! The great thing about Arduino being open-source and cheap is that there is a PLETHORA of information online - whether it’s tutorials or examples.
I also think that as a CNC’er, knowing more about electronics is a requisite skillset. Especially servo’s!
The example below is very simple and very do-able for anyone, regardless of prior experience. As always, post a comment with any questions.
See below the video for links & the source code
Arduino Links:
Project Source Code:
// Servo Button Program
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
int pos = 0; // variable to store the servo position
int inputPin = 2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
void setup()
{
myservo.attach(9); // attaches the servo on pin 9 to the servo object
pinMode(inputPin, INPUT); // declare pushbutton as input
}
void loop()
{
val = digitalRead(inputPin); //reads value of input
val = digitalRead(inputPin); // read input value
if (val == HIGH) // check if the input is HIGH
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(7); // waits 15ms for the servo to reach the position
}
myservo.write(180);
}
else { }
}
Sunday, March 8, 2009