Making Things Interactive

February 12, 2008

Arduino + Servo + DC Motor

Filed under: 5: Making Motion,Jesse Chorng — Jesse @ 12:47 pm

Nothing crazy going on here. Just a pulsing status LED along with a DC motor speeding all the way up and all the way down. It is powered by the 9V batter clip the starter kit came with. The servo, powered by 5V from the board, is only moving between two positions.  You don’t see much in the video but you can hear the motors changing along with the LED. 

/*
 *  Arduino Motor Control
 */

int count = 5;                      
int statusPin = 11;                  
int servoPin = 10;               
int motorPin = 9;                  

void setup()                      
{
  pinMode(statusPin, OUTPUT);        
  pinMode(servoPin, OUTPUT);      
  pinMode(motorPin, OUTPUT);       
}

void loop()                       
{
  for (count = 5 ; count <= 255 ; count += 5)   // Count by 5 to gradually increase steps
  {
        analogWrite(statusPin, count);             
        analogWrite(servoPin, 180);           
        analogWrite(motorPin, count);             
        delay(50);                             
  }
  for (count = 255 ; count >= 5 ; count -= 5)   // Count down by 5 to gradually decrease steps
  {   
        analogWrite(statusPin, count);            
        analogWrite(servoPin, 60);           
        analogWrite(motorPin, count);             
        delay(50); 
  }
}

Advertisements

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: