Home
»Unlabelled
» Arduino Servo motor code 1
// This code depends on the Servo Software Library. You can get
// this lib from http://www.arduino.cc/playground/ComponentLib/Servo
// To use this app just send the board a number followed by an 's'
// to set the angle of the servo (0-180 are valid)
#include
// This is the pin you need to attach the servo to
#define SERVO_1_PIN 2
Servo g_servo1;
void setup()
{
pinMode(SERVO_1_PIN, OUTPUT);
g_servo1.attach(SERVO_1_PIN);
Serial.begin(9600);
Serial.println("Enter number and press 's' to send it to servo.");
}
void loop()
{
static int val = 0;
if (Serial.available())
{
char ch = Serial.read();
switch(ch)
{
case '0'...'9':
val = val * 10 + ch - '0';
break;
case 's':
g_servo1.write(val);
Serial.print("Servo1 is set to: ");
Serial.print(val, DEC);
Serial.println(" degrees");
val = 0;
break;
}
}
Servo::refresh(); // Should try to call this every 20 ms to insure servo stays set
}
Disclaimer: All the information in this blog is just gathered from different sites in the web and placed here and I am not the owner for these content
Popular Projects
-
I just recently talked about me starting a saltwater reef aquarium. A lot of time and money goes into starting such a device, and the reward...
-
intro Arduino EMF (Electromagnetic Field) Detector A while back I saw an EMF (Electromagnetic Field) Detector at makezine.com that used a le...
-
intro Temperature Control For Kitchen Appliances In this Instructable, I will step through controlling the temperature of most kitchen appli...
-
intro Logger Shield: Datalogging for Arduino Data logging shield Here's a handy Arduino shield: we've had a lot of people looking fo...
-
intro Arduino Home automation This is a relatively simple controller for controlling equipment in your home. At the moment I control my cent...
-
int switchPin = 2; // switch input int motor1Pin1 = 3; // pin 2 on L293D int motor1Pin2 = 4; // pin 7 on L293D int enablePin = 9; ...