Introduction: Prima - a Robot That Plays Piano
The idea of a robot playing an instrument always fascinated me, and I always wanted to build one myself. However, I never had much knowledge about music and musical instruments, so never could figure out how actually would I start with that. Until recently, I got interested about making music, started learning music production stuffs, and after getting a MIDI keyboard, I've realized this isn't a hard instrument to play and I can actually build a robot that can play it. So, that's how making of Prima started.
I wasn't sure about the success of this project, so didn't bother documenting it. But since it turned out to be working great, I've decided to share the details with Instructables community. This won't be a step-to-step build log, rather more of a guideline to get you started. I'll be explaining how each part of this robot works, share the pictures of them and the code for the Arduino. Hope that'll be enough if you want to replicate this project.
And, the design was inspired by this instructables, shout out to JimRD!
So, let's get started!
Teachers! Did you use this instructable in your classroom?
Add a Teacher Note to share how you incorporated it into your lesson.
Step 1: Overview of the Whole Project
Prima is a robot that can play keyboard/piano or any similar key-based instrument. It has an Arduino Uno as the brain, an LCD screen for visual output and an ultrasonic sensor for touch-less starting. Any power adapter that delivers 5 volt 2 amp should be able to power it.
It has the following features -
- Programmable - Can be programmed to play any composition that is limited within an octave.
- Adjustable Tempo - The tempo it will be following while playing the instrument can be set in the code.
- Touch-less Starting - The user can trigger the playing just by swiping his/her hand on the sensor, which will come greatly helpful if the user is busy playing another instrument and wants Prima to play along with him/her after a specific time. Human player jamming with a robot player - even this can be achieved as well, by the help of this feature.
Step 2: Video
You may watch it playing a keyboard in the video.
Step 3: Making the 3D Model
After finalizing what it should be able to do, I designed the body on TinkerCAD so I could start building it with having a clear idea of what I was doing.
This approach helped me greatly to end up with a neat looking robot that works exactly the way it was designed to. Although I did have to modify the original design a bit while building it, still the 3D model saved me a lot of time and effort. You may see the 3D model in more details here.
Step 4: Parts and Tools
For the electronic part, you'll need -
- Arduino Uno (Quantity - 1)
- 16x2 LCD Screen (Quantity - 1)
- I2C Adapter for the LCD Screen (Quantity - 1)
- TowerPro SG90 Micro Servo (Quantity - 2)
- HC-SR04 Ultrasonic Sensor (Quantity - 1)
- Toggle Push Switch (Quantity - 1)
- Buzzer (Quantity - 1)
- Vero board/Dot Board/ Perf Board
- Male to Male and Male to Female jumper wires
For making the body -
- 5 mm PVC Sheet
- Cycle spoke (Quantity - 2)
- Pen refill holder tube
- Spray paint (If you want to paint it)
The tools you'll need -
- Hot Glue Gun
- Soldering Iron
- Anti-cutter (A.K.A Paper-cutter)
Step 5: Circuitry
The circuit part was quite easy. I'm explaining how I did each segment of it -
LCD Segment - I used an I2C adapter for the LCD so the Arduino could communicate to it over I2C, which wasn't necessary but simplified the circuit and lessened the number of wires. You can use a standard LCD by modifying the code a bit.
Power segment - I made a simple circuit on veroboard which consists a toggle push switch, a buzzer, a LED (which I decided not to use afterwards) and a 5V common power bus. Power bus as in, the 5V and ground pins of the servos, the sonar sensor, the LCD and the Arduino are all connected to each other respectively. One pin of the push switch is connected to the 5V+ line, and the another pin is connected to the power supply's VCC pin. The ground line is connected to the power supply's ground pin directly. So, Prima can be turned on/off using the switch. The buzzer and the LED are connected in parallel, and the VCC pin of them goes to pin 13 of the Arduino. Their ground is connected to the common power bus's ground.
Servos' connector modification - Since jumper wires often tend to disconnect from the servo's connector, I cut the VCC and the ground wire from both servos and soldered them directly to the power bus. For the signal pins, however, I used jumper wires to connect them to Arduino.
Sonar sensor - Soldered two wires respectively to the VCC and ground pin of the sonar sensor, which go to the common power bus, and used jumper wires for connecting the trigger and echo pin to the Arduino.
Arduino - Powered through the barrel jack connector.
Which goes to which -
Sonar Sensor's trigger pin -> Arduino's A2 pin
Sonar Sensor's echo pin -> Arduino's A3 pin
I2C Adapter's SDA pin -> Arduino's A4 pin
I2C Adapter's SCL pin -> Arduino's A5 pin
Buzzer's VCC -> Arduino's D13 pin
Key pressing servo's signal pin -> Arduino's D9 pin
X axis servo's signal pin -> Arduino's D8 pin
All VCC and ground pins are connected to the common power bus.
Step 6: Sonar Sensor Mount
The picture is self explanatory, just super-glued a L shaped shelf on the "wall" and hot-glued the sonar sensor on the shelf.
Step 7: Making the X Axis Rail
I borrowed the concept of the X axis rail from CNC machines. It's just two cycle spokes placed parallel to each other, and the "walls" have holes through which the cycle spokes go. On the other ends of the walls, the cycle spokes are hot-glued to the walls so they don't move. The cycle spokes are strong enough to support the X axis platform.
Step 8: X Axis Platform
It's the part that goes sideways to reach to certain keys and has a servo that has an arm attached to it which presses the key.
It has two pen refill holder tube hot-glued on bottom of it through which the cycle spokes go allowing it to slide on them. I got this tube from a pen, you may use anything that fits the spokes such as drinking straw.
Then, in the middle of the bottom PVC sheet, there's another PVC sheet standing straightly. It has a hole cut in the lower portion which fits the servo body and the servo is inserted through it.The servo has been secured using hot glue.
The servo has an arm connected to it. When the robot has to press a key, the servo rotates the arm downwards resulting a key press and rotates it to its former position afterwards.
Step 9: Moving the X Axis Platform
The "X axis mover" servo is attached to an elevated platform which is on the left side of the robot. The X axis platform has a shelf on the top where an arm is jointed using a screw. On the other end of the arm, another arm is jointed using screw and this one is connected to the servo horn. All joints are movable, and the servo can drive the X axis platform on the X axis rails by rotating its horn left/right which would make the arms to push/pull the platform on the rails.
The joints are made using screw.
Step 10: Code
After finishing building the body and the circuit, upload the code on Arduino. Put the robot in parallel with the keyboard/piano The x axis platform will first start moving towards left and stop at a certain point. Move the robot until the C key of the piano meets that point. This is a crucial step, because without positioning the robot this way, it won't be playing the melody correctly. Then turn on the robot, it should start playing a melody within a few seconds.
The code is pretty basic and has room for improvement. If you want the robot to play your own melody, you'd just have to put it in the code which's pretty easy.
Step 11: Painting It.
If you want to paint it like mine (I would highly suggest to do so, it looks way better painted), make all the body parts first, make sure they are cut correctly. Then, wash them using soap so they are free of oil and dirt. People usually sand the surface before painting it, but here you don't need to. Spray a layer on them first, give it enough time to dry (A few hours), then paint another layer. You may start assembling the parts and gluing them together after the paint dries out.
I used spray paint to paint mine.
Step 12: Placing and Organizing the Electronics
I screwed the Arduino to the base PVC sheet and hot-glued both the power circuit and the LCD on the base board. Organized the wires with hot glue.
Step 13: Conclusion : Thank You for Reading the Instructables.
So, this is how I built Prima. Hope the build log was clear and easy to understand. If you have any questions, feel free to leave them in the comment section, I will try to reply as early as possible.
Future plans with this project -
- Making a software for programming Prima more easily.
- Adding tempo tapping feature so you can just tap a button for adjusting the tempo.
- Swapping the servos with quieter and faster ones
If you build this, do drop pictures in comment, I would love to see yours! :)
Don't forget to vote me if you liked it. Thank you.
Participated in the
Audio Contest 2018