In this session we’re going to create a simple electronic drum kit with interactive lights. We will use red LEDs in this experiment, but you can use RGB ones or even an LED strip for better effects. We will be using a vibration sensor this time.
COMPONENTS
HARDWARE CONNECTIONS
Connect the Piezo Disk Vibration Sensor V2 to analog pin 0.
Connect the Digital Piranha LED-R to digital pin 10.
See the diagram below for reference:
Be sure that your power, ground and signal connections are correct or you risk damaging your components.
When you have connected the components and checked your connections, plug the Arduino in to your PC with the USB cable so you can upload a program.
CODE INPUT
Sample Code 7-1:
// Electronic Drum Kit
int sensorPin = 0; // Piezo Disk Vibration Sensor V2 is to be attached to analog pin 0
int ledPin = 10; // Digital Piranha LED-R is to be attached to digital pin 10.
void setup() {
pinMode(ledPin, OUTPUT);
}
void loop() {
int sensorValue = analogRead(sensorPin); //collect value at analog pin 0
// A value between 0 and 1023 to mapped to a value between 0 and 255
int outputValue = map(sensorValue, 0, 1023, 0, 255);
analogWrite(ledPin, outputValue*10); //write corresponding value for LED
delay(10);
}
Use this sample code to implement the behavior we want.
You can copy and paste it in to the Arduino IDE, but if you want to develop you skills we recommend typing it out.
When you have finished, click “Verify” to check the code for syntax errors. If the code verifies successfully, you can upload it to your Arduino.
Carefully press the Piezo Disk Vibration Sensor. The LED should be dimly lit.
Press harder on the Piezo Disk. The brightness of the LED should increase.
Tap the Pieze Disk with your finger like a drum. The LED will flash in sync with it!
HARDWARE ANALYSIS (ANALOG INPUT-ANALOG OUTPUT)
You might have found out that the Electric Drum and light-regulator have similar procedures to build. The only thing different is the forms of the sensors.
The Piezo Disk Vibration Sensor is the input unit.
The Piranha LED is the output unit.
The code is similar to that in Experiment 6: LED Dimmer. You can refer to that for code analysis.