Making Things Interactive

February 19, 2008

Spinning Color Wheel and Servo Motor

Filed under: 6: More Motion,Tiffany Yang — tyang1 @ 3:19 pm

Originally I wanted to create a drive belt that had numbers on them with a DC motor and rubber band. This would be a game where a solenoid controlled by a button would hit the numbers as they moved by.  The higher the numbers the more points you get.  However, the DC motor with 9V could not take any load.  When I put the rubber band on the motor, it stalled the motor.  Plus I could not get the solenoid to work.  So I moved to a new plan.  I couldn’t think of anything except sticking a color wheel on the DC motor.  The DC motor is controlled by a potentiometer so the faster you turn the potentiometer, the more merging of colors you get.  Since we had to control two things, I decided to control a servo motor.  I could not think of anything cool to do with the servo motor so all I ended up with is a spinning color wheel and servo motor.  The servo motor on its own works well but with the DC motor, the servo motor’s movement is a bit jerky.  I am guessing it is from the noise of the DC motor.         

int motPin = 9; // sets base of motor transistor to PWM 9
int potPin = 0; // sets potentiometer to analog 0
int potValue = 0; // value returned from the potentiometer

int servoPin = 3; // sets servo control pin to PWM 3
int angle;
int pulseWidth; // amount to pulse the servo

void servoPulse(int servoPin, int angle) { // creating a subroutine
pulseWidth = (angle * 9) + 300; //
digitalWrite(servoPin, HIGH); // turn servo on
delayMicroseconds(pulseWidth); // length of pulse sets the motor position
digitalWrite(servoPin, LOW); // turn servo off

void setup() {
pinMode(motPin, OUTPUT); // sets motor transistor pin as output
pinMode(potPin, INPUT); // sets potentiometer pin as input
pinMode(servoPin, OUTPUT); // sets servo transistor pin as output

void loop() {
potValue = analogRead(potPin) / 4; // read potentiometer, convert to 0 – 255
analogWrite(9, potValue); // use potentiometer to control motor

for (angle = 0; angle <=180; angle++) { // for eaching angle from 0 to 180... servoPulse(servoPin, angle); // call subroutine } delay(1000); }[/sourcecode]    


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: Logo

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

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s

Blog at

%d bloggers like this: