Merry Go Round

by sharah zafar in Circuits > Arduino

152 Views, 1 Favorites, 0 Comments

Merry Go Round

download.jpg

In this tutorial you'll learn to make a merry go round toy. The horses will rotate using potentiometer which controls the servo motors. This way you can control the direction and speed in which the horses will turn. Next, there is a Touch Switch which works side by side with a buzzer which plays classical music. The intended audience of this toy is young kids who wish to control a simulation of a playground.

Supplies

Screenshot 2023-01-25 09.57.25.png

Here are the components you will need:

  • 2 Microservos (https://www.amazon.ca/Micro-Servos-Helicopter-Airplane-Controls/dp/B07MLR1498?nstoken=7SOY%2FFbMog3%2FTQb%2Fbc1Qv%2FcNPITu7wYhDgXLnaLB%2BtwHkThOMV%2F%2Bf9OfldJ1%2F3qC3wjru4emXLtQpPZ%2FIBPVj7rGLJkdsyrnZdxLa%2FzVEkpcncDicpXqLAHsfht9Jl20C7fnj0JErFsFC0Hh5WBBViEBGcBSA7DpXChd73nht9IZuJYuJp0aktV%2B29p8HczBhxhixCgaIkPgug4B6F53P6ntV7dt8Gc8LxhEtEVHD2KpUjfXhxwenK2Epk6kySM1EPrPElsOICc7qyWMmo%2F8ZKjq2%2BMdZ7O5Ctus1qpaaT3SUam7ovM%2FKKQzLUU80sma5Cur39gUkEqcdszfgbNGOyAy5J15vYnOsA1JZ%2BuV1XlGde62%2FmeaRSW63eCFO4Ddy6zLVNMQRwznUjjluK1hCwE01NvbiJf4xEv7cMMd3tc3fmLAl42ykIx9&nscheck=kmEBEmYMIRp0zlOLzyFB9A%3D%3D)


  • 2 potentiometers (https://www.amazon.ca/UKCOCO-Potentiometer-Assortment-Breadboard-Arduino/dp/B08MTVS38M/ref=sr_1_15?crid=T2T2EDSYGCME&keywords=potentiometers&qid=1674757266&sprefix=potentiometers%2Caps%2C280&sr=8-15)


  • Jumper cables (https://www.amazon.ca/RGBZONE-Multicolored-Breadboard-Arduino-Raspberry/dp/B08TWSV2DY/ref=sr_1_1_sspa?crid=3VYIZXF6H5F8K&keywords=jumper+cables+arduino&qid=1674757322&sprefix=Jumper+cables%2Caps%2C478&sr=8-1-spons&psc=1&smid=A3H1S8HVHBGDBK&spLa=ZW5jcnlwdGVkUXVhbGlmaWVyPUExNkZLQlNYT082VUg4JmVuY3J5cHRlZElkPUEwNzMzMjUyTTdZOFlNOFdETFFXJmVuY3J5cHRlZEFkSWQ9QTA3MzQyOTEzRk8yNkdZMVZDTlFGJndpZGdldE5hbWU9c3BfYXRmJmFjdGlvbj1jbGlja1JlZGlyZWN0JmRvTm90TG9nQ2xpY2s9dHJ1ZQ==)


  • Buzzer (https://www.amazon.ca/Tegg-Passive-Speaker-Arduino-Raspberry/dp/B07PRTMF89/ref=sr_1_6?keywords=buzzer+arduino&qid=1674757389&sprefix=buzzer%2Caps%2C213&sr=8-6)


  • Touch Sensor (https://www.amazon.ca/Capacitive-TTP223-Switch-Digital-Arduino/dp/B078WDNLTK/ref=sr_1_4?crid=2AH5ETE606XTQ&keywords=touch+sensor+arduino&qid=1674757438&sprefix=touch+sensor+arduino%2Caps%2C201&sr=8-4)


  • Slide Switch (https://www.amazon.ca/Cylewet-Vertical-Switch-Arduino-CYT1016/dp/B01N7NCW8N/ref=sr_1_5?crid=3IIC9JOAP4HE9&keywords=slide+switch+arduino&qid=1674757486&sprefix=slide+switch+arduino%2Caps%2C168&sr=8-5)


  • Arduino (https://www.amazon.ca/ARDUINO-A000066-Uno-DIP-1-5/dp/B008GRTSV6/ref=sr_1_6?crid=3JX67Y2A0HJ9U&keywords=arduino&qid=1674757515&sprefix=sarduino%2Caps%2C153&sr=8-6)

Wiring

Screenshot 2023-01-25 09.40.29.png
unnamed.jpg

The first step is to wire the project! Use the schematic and photo of tinkercad to attach your components to the correct pins.

Coding

#include <Servo.h>

#define S0 8

#define S1 9

Servo SERVO1;

Servo SERVO2;   

int data1, data2; 

int buzzer = 13;

int pir = 12;

int MotSens;

int sw=6;

int state;

int count;

int sound_freq;

void setup() 

{

 pinMode(13, OUTPUT);

 pinMode(12, INPUT);

 pinMode(6, INPUT);

  Serial.begin(10000);

  int i;

 SERVO1.attach(S0);

 SERVO2.attach(S1);

 SERVO1.write(0);

 SERVO2.write(0);

 delay(0);

}

void title()

{

 for(int i=0; i<1; i++)

 {

  Serial.println("Mary Go Round Data:");

 break;

 }

}

void off()

{

 digitalWrite(13, LOW);

  SERVO1.write(0);

  SERVO1.write(0);

}

void servo()

{

 data1=analogRead(A0);

   data2=analogRead(A1);

  //  Serial.println(data1);

  //  Serial.println(data2);

   data1=map(data1, 0, 1023, 0, 180);

   data2=map(data2, 0, 1023, 0, 180);    

  SERVO1.write(data1);

  SERVO2.write(data2);

     Serial.println(data1);

  Serial.println(data2);

     delay(100); 

}

void music()

{

 sound_freq = 500;

 count = 0;

 while(count < 5){

  tone(buzzer, sound_freq, 400);

  delay(800);

  sound_freq += 500;

  count++;

 }

count = 0;

 sound_freq = 1500;

 while( count < 4 ) {

  tone(buzzer, sound_freq, 150);

  delay(300);

  count++;

 }

}

void loop()

{

   title();

   {

 int i;

  servo();  

 state = digitalRead(6);

 Serial.println(state);

 if (state == HIGH)

  {  

 MotSens = digitalRead(12);

   Serial.println("touch sensed!");

  if (MotSens == HIGH)

  {

   music();

 }

   else

     digitalWrite(13, LOW);

}

}

  

 if(state==LOW)

  off();

}

Understanding the Project

Here is a brief explanation of the code:

  1. Define the variables by writing the components and which pin it is attached to.
  2. Declare whether its an input or output.
  3. Create different functions (void servo controls the servos with the potentiometer, void music plays the buzzer, void off turns the buzzer off, void title displays the title on the serial monitor).
  4. In void loop, declare the functions when necessary in accordance to the project, by adding if ststaments. (If the slide switch is turned on-- play the music when touch is sensed. If the slide switch is low--dont play the music even when touch is sensed)

Putting It All Together

Make a Merry go Round out of the supplies you have. Put the code into the software and watch your toy come to life.