MAKER: banjowise/Translated by: Fun Endless
What do you want to do when the night is deep and you can’t sleep? Why not create a drum machine like I did, pick up the ukulele that has been gathering dust for years, and entertain the kids upstairs playing ball? You can watch a video first:
In the tutorial below, I will explain in detail how it works. Many everyday items are used here, such as: cans, wooden spoons, piano hammers, bottle caps, and fish nets. It is highly interactive.
Of course, you can unleash your creativity while building your own project.There are two ways to control it: 1. A browser-based step sequencer, which I call: PiBeat. It allows you to interactively control your machine drum through the Raspberry Pi or any other device on the same network (phone, tablet, or computer). I will install it on the Raspberry Pi later. You can preview it here: http://pibeat.banjowise.com/
The code is available for download on GitHub: https://github.com/mnkii/pibeat
2. A Python script for coding drum patterns. You can create your own scores and even coordinate with your guitar. Are you talented? Hurry up and build your own drum machine!
Material List
Raspberry Pi (x1), 5V 8-channel relay (x1), female-to-female jumper wires (x10), AMP terminal blocks (x2), 12V 10A power supply (x1), 12V 2A solenoid valve (x8), 1N5401 rectifier diodes (x8), 0.5mm wide 50cm long cable (x1), wire stripper (x1), pliers (x1), 3mm flat screwdriver (x1), Phillips screwdriver (x1)
Connecting the Raspberry Pi to the Relay
1. The maximum voltage supplied by the pins on the Raspberry Pi is 5V. The Raspberry Pi directly powers the 5V solenoid valve, which will not affect the performance of the machine drum.
Therefore, the purpose of installing the relay is to drive a higher voltage circuit with a lower voltage from the GPIO (this project includes a 12V solenoid valve circuit).
2. The relay has eight channels that can independently open and close eight solenoid valves. Each channel contains four connectors, three of which are used in the high voltage circuit, which will be seen later. The remaining one connects to the low voltage circuit’s IN pin.
When the GPIO pin of the Raspberry Pi sends 5V to the given channel’s IN pin, the relay will connect to the corresponding 12V circuit.
3. On the low voltage side of the relay, there is also a GND (ground) pin that needs to be grounded with the Raspberry Pi and a VCC pin connected, powering the Raspberry Pi’s 5V supply.
4. After shutting down the Raspberry Pi, connect the relay to the Raspberry Pi using jumper wires according to the diagram.
Get It Drumming
In this step, although it is not a finished product yet, you can try to let the drum produce sound through the control of the relay. Next, I will introduce how to write a Python script for drum patterns while testing the current status of the project.
Please click here to view the key points of the script.
Start your Raspberry Pi, open a terminal on the Raspberry Pi, and run the downloaded script:
wget https://gist.githubusercontent.com/mnkii/8ab0d749c26379936c14e96cfaa92f7e/raw/array-sequencer.py
You might want to see what the code can achieve, so why not run it directly:
python3 array-sequencer.py
If everything runs smoothly, you will hear the sound of the relay opening and closing contacts and the corresponding channel’s indicator light flashing. Check the sequence variable in the script to see if everything is working properly.
All channels will trigger together, and then each channel will be triggered individually. It will keep running until you press Ctrl+C to exit the script.
In the next steps, it’s best to turn off the Raspberry Pi wiring to avoid short circuits.
Prepare the Positive Terminal Circuit
This project will power eight solenoid valves, and I will create a parallel circuit. As shown, you can see a complete 12V circuit diagram.1. Use terminal blocks to secure the wires, and you can choose to use a breadboard or perforated board. 2. Connect all solenoid valves and the diodes for each solenoid valve (there will be more diodes later) to a single positive line of the power supply. 3. Use a cutter to cut a pair of eight terminal blocks, cutting the plastic that connects the two blocks together. But be careful not to cut any metal. 4. Connect all terminals to one side of the terminal block. Cut seven red wires about 35mm long, and strip about 5mm of insulation from both ends of each wire.5. Connect all terminals in a daisy chain manner along one side of the terminal block, using screws to secure the wires in place. The first and last screws will have only one wire, while the others will have two wires.
Install the Solenoid Valves and Diodes
Since the solenoid valves come with electromagnets, it is recommended to use diodes to protect the circuit from back EMF (please click here for details). Therefore, each solenoid valve is equipped with a diode to protect the relay.In the previous step, all terminals were connected to one side of the terminal block; now start from the first hole. Insert one wire of the solenoid valve and then add one end of the diode to the same hole.
Since the diode only allows current to flow in one direction, ensure that the silver stripe on the diode is facing the terminal. Secure it in place with a screw. Do the same for the remaining seven holes.
Connect the Negative Terminal to the Solenoid Valves and Diodes
Like preparing the positive terminal, in this step, a negative terminal will also be made, again with eight pairs of terminals. As shown, connect the diodes and solenoid valves to the terminal, aligning with the positive terminal.
Create the Relay Circuit
1. Prepare eight black wires about 70mm long, stripping about 5mm from each wire’s end.2. Connect each wire to the remaining eight connectors on the negative terminal.
Connect the COM Terminal of the Relay in Series
1. Use jumper wires to connect the relay to the Raspberry Pi on one side. Each channel has three contacts, referred to from left to right as Normally Open (NO), Common (COM), and Normally Closed (NC).
2. The solenoid valve opens when there is high voltage on the channel’s IN pin, so use the normally open contact. If the opposite is true, use the normally closed contact, and the solenoid valve will stay open until high voltage is applied to the IN pin. Finally, the common contact will be used to complete the circuit.
3. Since this is a parallel circuit, connect all common contacts on the relay using a daisy chain connection. Cut seven black wires about 60mm long, stripping about 5mm from each wire’s end.
Complete the Remaining Connections of the Relay
Now connect the relay to the other parts of the circuit. Connect the unconnected end of the black wire from the negative terminal to the first or last normally open (NO) contact on the relay. Do the same for the other seven wires, connecting each wire to the next NO contact.
Connect the 12V Power Adapter
1. To avoid any circuit issues, turn off the power and unplug the power plug. As shown, the power plug for this project has been unplugged. If your power supply has a plug, you can purchase a matching female DC connector or cut off the plug and strip two wires, red for positive and white for negative.
2. Connect the positive wire of the power supply to the first contact on the positive terminal, and connect the negative to the first common contact on the relay. I used red and black wires about 150mm long, stripping the ends, and connected them using terminal blocks.
Get It Moving
1. Turn off the power and quickly check all the connections. Once everything is ready, restart the Raspberry Pi. Run the script again:
python3 array-sequencer.py
2. If the solenoid valves do not move but you can hear the relay clicking and the lights from the previous steps are on, terminate the script with Ctrl+C and wait. 3. Turn on the power supply and run the script again; all the solenoid valves should move.
Edit array-sequencer.py
Take some time to edit the array-sequencer.py file. Try the following actions, re-running the script after each change to see the effect:
1. Replace the bpm variable from 120 with another value, such as 200, to increase speed. 2. In the sequence variable, replace some 0s with 1s to increase the struck items. 3. Copy the last three lines before the right bracket in the sequence variable to loop and add more beats.
Install the Drum Sequencer
This is the very interesting part of artistic creation. 1. Connect the sequencer to the Raspberry Pi. There is a web interface that allows Python to trigger GPIO pins via web sockets.2. The source code can be downloaded from the project repository. https://make.quwj.com/project/122
If you follow the wiring instructions in the tutorial, you can download and run the precompiled version. Open a terminal on the Raspberry Pi and run the following commands:
# Create and navigate into a directory for our project
mkdir pibeat
cd pibeat
# Download the source code
wget http://pibeat.banjowise.com/release/pibeat.tar.gz
# Extract the files
tar -zxf pibeat.tar.gz
# Install the python requirements
pip3 install -r requirements.txt
# Run the web server
python3 server.py
3. In the output, if everything is normal, you will see the following output:
======== Running on <a href="http://0.0.0.0:8080" rel="nofollow">http://0.0.0.0:8080 </a> ========
(Press CTRL+C to quit)
4. Find the IP address of the Raspberry Pi. Open a web browser and enter http://RaspberryPiIP:8080/index.html; the sequencer should now appear.
5. Click the play button, and your machine drum should start playing. Debug the sequencer until it meets your standards.
As long as your Raspberry Pi has network access, you can access the Raspberry Pi’s web interface from any device. You can try it on your phone or tablet.
Making the Machine Drum and the Bottom Box
This step is the soul of the project and the key to whether the machine drum is interesting. You can give it a different meaning.
I used many everyday items, such as beer bottles, cans, shakers, bottle caps, fishing nets, table clocks, crocodile soundboards, and spoons.
I fixed the table clock in place with a wooden tap, and my metal rod can rotate and hold the spoon in place.Each drum is an independent component, and if you don’t like it, you can replace it at any time. The solenoid valves have bolt holes and need M3 bolts for secure fastening. Make drilling marks in advance to ensure secure installation.
I made the drums from 6mm medium density fiberboard, then glued or screwed them together. The hammers on the cans and beer bottles are meant to enhance the atmosphere; the sound of the solenoid valves striking is enough, and these add visual fun.
Bottom Box PartThe bottom box part is very simple, made of 3.6mm plywood, 18mm medium density fiberboard, and some wooden strips. The front of the base uses thin plywood, which resonates when the spoon strikes. The base not only accommodates all electronic devices but also serves as a platform for the drums.
The making steps are as follows: 1. Cut two pieces of medium density fiberboard to make the top and bottom. 2. Cut four pieces of 34mmx12mm wooden strips, shorter than the width of the box. 3. Form the shape of the box with the four cut wooden strips and the two pieces of medium density fiberboard. Place the wooden strips about 1cm from the top and bottom of the box. 4. Cut two pieces of plywood to match the width and height of the box. Secure them to the front and back of the box. 5. Cut another piece of plywood to place inside the box, securing the electronic components at the bottom. 6. Cut another piece of plywood to connect the drums. This is the wooden board for the top of the platform. 7. Drill a hole near the bottom platform to pass the power wire through.
Finally, use acrylic primer to paint your favorite color. Once everything is done, you can have fun playing!
Project Repository Address:
http://make.quwj.com/project/122
via instructables.com/id/A-Raspberry-Pi-Powered-Junk-Drum-Machine/
Links in the text can be clicked to read the original text at the end
More Exciting Content
Create a Colorful Clock with 128 Ping Pong Balls
DIY NES Handheld with ESP32 Development Board
Dormitory Internet Shutdown Device: DIY Wireless Router UPS
Raspberry Pi Video Surveillance Solution motionEyeOS
Arduino + Servo Create a Finger Spinner Robot
Arduino + 3D Printing Create a Persistence of Vision Display
Quirky Black Technology: Charming Eyes with Motion Tracking
Make LED Matrix Color Lights with Raspberry Pi and Arduino
Play with micro:bit MicroPython on Raspberry Pi
How cool is it to combine your Raspberry Pi with a night vision camera?
Leave a Comment
Your email address will not be published. Required fields are marked *