Christopher MonrealNick Udell
Published

Interactive Toddler Music Box Toy

Musical toy for toddlers.

IntermediateFull instructions provided4,095
Interactive Toddler Music Box Toy

Things used in this project

Hardware components

SparkFun 2 pin momentary button
×8
SparkFun thin speaker
×1
RGB Diffused Common Cathode
RGB Diffused Common Cathode
×2
Arduino UNO
Arduino UNO
×1
Rotary potentiometer (generic)
Rotary potentiometer (generic)
×1
SparkFun Black Metal Knob - 14x24mm
×1
SparkFun SoftPot Membrane Potentiometer - 50mm
×1
Breadboard (generic)
Breadboard (generic)
×1
Resistor 330 ohm
Resistor 330 ohm
×3

Hand tools and fabrication machines

Cordless drill
Soldering iron (generic)
Soldering iron (generic)
Hot glue gun (generic)
Hot glue gun (generic)

Story

Read more

Schematics

20180129_083139_lXv8xktQzA.jpg

20180126_121609_n61SXLpxH7.jpg

wiring_diagram_2KL8Z1Mu6K.png

Wiring Diagram For The Project (Note: Buttons displayed are not the same as those used in the project)

Code

Music Box Toy Code

Arduino
const int butt0 = 0;
const int butt1 = 8;
const int butt2 = 2; 
const int butt3 = 3; 
const int butt4 = 4; 
const int butt5 = 5; 
const int butt6 = 6;  
const int butt7 = 7; 
const int pot = 2;
const int soft = 1;
const int buzzerPin = 12;

 
void setup() {
  //start serial connection
  Serial.begin(9600);
  pinMode(butt0, INPUT_PULLUP);
  pinMode(butt1, INPUT_PULLUP);
  pinMode(butt2, INPUT_PULLUP);
  pinMode(butt3, INPUT_PULLUP);
  pinMode(butt4, INPUT_PULLUP);
  pinMode(butt5, INPUT_PULLUP);
  pinMode(butt6, INPUT_PULLUP);
  pinMode(butt7, INPUT_PULLUP);
  pinMode(buzzerPin, OUTPUT);


}

void loop() {
  //read the pushbutton value into a variable
  int val0 = digitalRead(butt0);
  int val1 = digitalRead(butt1);
  int val2 = digitalRead(butt2);
  int val3 = digitalRead(butt3);
  int val4 = digitalRead(butt4);
  int val5 = digitalRead(butt5);
  int val6 = digitalRead(butt6);
  int val7 = digitalRead(butt7);
  int potVal = analogRead(pot);
  int full = potVal/4;
  int half = potVal/8;
  int softVal = analogRead(soft);
  int shift;
  Serial.println(softVal);

  if (softVal >= 15)
  {
    shift = (softVal - 500)/5;
  }
  else
  {
     shift == 0;
  }
  if (val0 == LOW) 
  {
    analogWrite(9, full);
    analogWrite(10, 0);
    analogWrite(11, 0);
    tone(buzzerPin, 220.6 + shift, 100);
  } 
  else if (val1 == LOW)
  {
    analogWrite(9, full);
    analogWrite(10, half);
    analogWrite(11, 0);
    tone(buzzerPin, 246.9 + shift, 100);
  }
  else if (val2 == LOW)
  {
    analogWrite(9, full);
    analogWrite(10, full);
    analogWrite(11, 0);
    tone(buzzerPin, 261.6 + shift, 100);
  }
  else if (val3 == LOW)
  {
    analogWrite(9, 0);
    analogWrite(10, full);
    analogWrite(11, 0);
    tone(buzzerPin, 293.7 + shift, 100);
  }
  else if (val4 == LOW)
  {
    analogWrite(9, 0);
    analogWrite(10, full);
    analogWrite(11, full);
    tone(buzzerPin, 329.6 + shift, 100);
  }
  else if (val5 == LOW)
   {
    analogWrite(9, 0);
    analogWrite(10, 0);
    analogWrite(11, full);
    tone(buzzerPin, 349.2 + shift, 100);
  }
  else if (val6 == LOW)
    {
    analogWrite(9, full);
    analogWrite(10, 0);
    analogWrite(11, full);
    tone(buzzerPin, 392 + shift, 100);
  }
  else if (val7 == LOW)
    {
    analogWrite(9, full);
    analogWrite(10, full);
    analogWrite(11, full);
    tone(buzzerPin, 440 + shift , 100);  
  }
  else
  {
    analogWrite(9, 0);
    analogWrite(10, 0);
    analogWrite(11, 0);
  }
}

Credits

Christopher Monreal

Christopher Monreal

1 project • 0 followers
Nick Udell

Nick Udell

3 projects • 1 follower
Student, maker, roboticist, aspiring engineer

Comments