Double-clap light switch
Clap twice and the lights come on. Clap twice again to switch them off.
Shop by category
Shop all componentsTurn the keypad into a small instrument where each key sounds a different musical note. Pitch is frequency: 262 Hz is middle C, and doubling a frequency raises it by exactly one octave, the 523 Hz at the end of the array is the C above. The keypad's sixteen keys map onto sixteen entries in a frequency array, so finding the right note is just a matter of locating the pressed key's position. tone() generates a square wave on the buzzer pin in the background, and noTone() silences it when the key is released.
Every part for this build comes in the Geekobot Explorer Kit box, a Geekobot exclusive, together with the parts for all 61 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
The brain of every Explorer Kit project
Male-to-female and female-to-female leads for the modules
16x2 LCD with I2C backpack: four wires, two lines of text
Nano I/O shield from the kit: every pin has its own S, V, G header, so modules plug in with jumpers
Follow the colours: red is power, dark grey is ground, blue is a signal.
explorer_kit_51_mini_piano.inoVerify & upload in Electrolark#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] =
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {9, 8, 7, 6};
byte colPins[COLS] = {5, 4, 3, 2};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 16, 2);
int buzzer = 11;
char keyOrder[16] =
{'1','2','3','A','4','5','6','B','7','8','9','C','*','0','#','D'};
int noteFreq[16] = {262, 277, 294, 311, 330, 349, 370, 392,
415, 440, 466, 494, 523, 554, 587, 622};
String noteName[16] = {"C4","C#4","D4","D#4","E4","F4","F#4","G4",
"G#4","A4","A#4","B4","C5","C#5","D5","D#5"};
int findNote(char key)
{
for (int i = 0; i < 16; i++)
{
if (keyOrder[i] == key)
{
return i;
}
}
return -1;
}
void setup()
{
pinMode(buzzer, OUTPUT);
Serial.begin(9600);
lcd.init();
lcd.backlight();
lcd.setCursor(0, 0);
lcd.print("Mini Piano");
lcd.setCursor(0, 1);
lcd.print("Press any key");
}
void loop()
{
char key = keypad.getKey();
if (key == NO_KEY)
{
return;
}
int index = findNote(key);
if (index < 0)
{
return;
}
tone(buzzer, noteFreq[index]);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Note: ");
lcd.print(noteName[index]);
lcd.setCursor(0, 1);
lcd.print(noteFreq[index]);
lcd.print(" Hz");
Serial.print(noteName[index]);
Serial.print(" ");
Serial.println(noteFreq[index]);
// Hold the note while the key is down
while (keypad.getState() == PRESSED)
{
keypad.getKey();
delay(5);
}
noTone(buzzer);
}
Use the kit's mini-USB cable, install the CH340 driver on Windows if no port appears, pick Tools > Board > Arduino Nano and try Tools > Processor > ATmega328P (Old Bootloader) if the upload times out.
This project needs the passive buzzer (the one that plays notes with tone()), not the active one.
Turn the small contrast pot on the back of the I2C board. If still blank, change 0x27 in the sketch to 0x3F.
Lay the keypad face up: the eight pins run left to right as row 1 to 4, then column 1 to 4, and go to D9 down to D2.
Pitch is frequency: 262 Hz is middle C, and doubling a frequency raises it by exactly one octave, the 523 Hz at the end of the array is the C above. The keypad's sixteen keys map onto sixteen entries in a frequency array, so finding the right note is just a matter of locating the pressed key's position. tone() generates a square wave on the buzzer pin in the background, and noTone() silences it when the key is released.
Press 1 for middle C: the LCD reads Note: C4 / 262 Hz. Each key up to D sounds a higher semitone. The note holds while the key is down and stops on release.
Yes. It is project 51 of 61 in the Geekobot Explorer Kit, in level 9 (Interactive games). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Explorer Kit project is wired on the Nano I/O shield and the breadboard with jumper wires.
7 parts: Generic Nano CH340 Development Board (Soldered), USB Cable, Dupont Jumper Wires (40 pcs), Buzzer Module 3.3–5V, LCD1602 16x2 Character LCD Display, Membrane Matrix Keypad and Arduino Nano IO Expansion Shield (328P Compatible). On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 45 minutes. The build on this page has 6 steps.
No. This page has the complete, tested code (explorer_kit_51_mini_piano.ino).
About ₹596 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Frequency mapping and keypad matrices; How pitch relates to frequency and octaves; tone() and noTone() for background sound; Searching an array to find a key's position.
Clap twice and the lights come on. Clap twice again to switch them off.
Plays a friendly ding-dong whenever someone walks into the shop or room.
Beeps and flashes any message in Morse, or key your own by hand.
Turn a membrane keypad into a two-octave piano.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.