Mobile Motor

Assignment: DC Motor: Actuation Assignment 1

Collaborators:

Description

I created a mobile (very loosely based on this mobile) that spins when the motor is on. The mobile is meant to be used over a baby's crib. When the lights are turned out, the mobile spins and Twinkle, Twinkle Little Star plays. I used a photocell to recognize when the lights are turned off and a Piezo speaker to play the melody.

 

Components Used

  • 220 ohm resistor
  • 10k resistor
  • 1k resistor
  • Arduino board
  • Bread board
  • Wires
  • Photocell
  • Piezo speaker
  • DC motor
  • battery pack
  • 1 diode
  • 1 transistor
  • colored paper
  • craft wire
  • string
  • cardboard
  • tape
  • screw eye
  • cork

Arduino Code

 

/*

* Baby Mobile

*

* When lights are turned off, motor causes mobile to spin

* and play Twinkle, Twinkle, Little Star.

*

* sound code modified from http://courses.ischool.berkeley.edu/i262/f09/sites/default/files/play_me...

*/

 

int lightSensor = 0;   // photocell is connected to analog pin 0

int motorPin = 9; // select the pin for the Motor

int val = 0;      // variable to store the value coming from the photocell

int speakerOut = 7;

byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};

int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};

byte melody[] = "4c2p4c2p4g2p4g2p4a2p4a2p8g4p4f2p4f2p4e2p4e2p4d2p4d2p8c4p4g2p4g2p4f2p4f2p4e2p4e2p8d4p4g2p4g2p4f2p4f2p4e2p4e2p8d2p4c2p4c2p4g2p4g2p4a2p4a2p8g4p4f2p4f2p4e2p4e2p4d2p4d2p8c4p";

// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0

//                                10                  20                  30

int ledPin = 13;

int count = 0;

int count2 = 0;

int count3 = 0;

int MAX_COUNT = 96; //melody count

int statePin = LOW;

 

void setup() {

pinMode(speakerOut, OUTPUT);

Serial.begin(9600);

}

void loop() {

val = analogRead(lightSensor);  // read the value from the photocell

Serial.println(val);

if (val < 800) {  //if light is turned off

analogWrite(motorPin, 100); // start motor

digitalWrite(speakerOut, LOW);     //play music

for (count = 0; count < MAX_COUNT; count++) {

statePin = !statePin;

digitalWrite(ledPin, statePin);

for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {

for (count2=0;count2<8;count2++) {

if (names[count2] == melody[count*2 + 1]) {

digitalWrite(speakerOut,HIGH);

delayMicroseconds(tones[count2]);

digitalWrite(speakerOut, LOW);

delayMicroseconds(tones[count2]);

}

if (melody[count*2 + 1] == 'p') {

// make a pause of a certain size

digitalWrite(speakerOut, 0);

delayMicroseconds(500);

}

}

}

}

}

}

Photos

Board set up

 

Mobile

 

 

Video

(The video was shot without the mobile starting by turning off the light. Turning off the light is bad for shooting video...)