Vous êtes sur la page 1sur 4

Arduino Piano Using LDR and Buzzer

A. G. Turtulea (30312)
T. S. Baltaretu (30312)

Technical University of Cluj-Napoca


Automation Department
Str. G. Baritiu nr 26-28, 400027 Cluj-Napoca, Romania

E-mail: alexadra_turtulea@yahoo.com
teodorstelian98@yahoo.com

Abstract. This article presents the implementation of an Arduino Piano using LDR Sensors and
a Piezo Buzzer.

1. Introduction

These guidelines show how you should proceed for implementing an Arduino “piano”, using LDRs,
LEDs and a Piezo Buzzer.

2. The Photoresistor (LDR)

A photoresistor or photocell is a light-controlled variable resistor. The resistance of a photoresistor


decreases with increasing incident light intensity. A photoresistor can be applied in light-sensitive
detector circuits, and light- and dark-activated switching circuits. It's also called light-dependent resistor
(LDR).

Figure 1 The Circuit


3. Piezo Buzzer

Figure 2 Piezo Buzzer connected to Arduino UNO

A piezo buzzer is an audio signalling device which may be driven by an oscillating electronic circuit or
other audio signal source, driven with a piezoelectric audio amplifier. Sounds commonly used to indicate
that a button has been pressed are a click, a ring or a beep.

4. Implementation

 We used :

 Six Resistors of 220 Ohm

 Six Resistors of 10 KOhm

 Six Different Color LEDs

 Six LRD Sensors

 One Piezo Buzzer

Each LED is connected to GND and to a digital pin, as will be shown in the following code, using digital
2, 3, 4, 5, 6, 7 inputs.

Each LDR sensor is connected to an analogue input (A0 – A5). Since the Arduino UNO board has only 6
analogue inputs, we used only 6 LDR sensor, even though a piano keyboard should be composed of at
least 7 sound tones (DO, RE, MI, FA, SOL, LA, SI).

The Piezo Buzzer is connected to analogue input 13 and is programmed to action when a certain LDR
sensor’s output value (in the Serial Monitor) decreases below 300. The following frequencies were used:
Do = 262, Re = 294, Mi = 330 , Fa = 349 , Sol = 392 , La = 440.
5. Programming

5.1. Segments of Code

//definitions of constants
const int ledPin[] = { 2, 3, 4, 5, 6, 7 };

int buzzerPin = 13;

int keyPins[] = { A0, A1, A2, A3, A4, A5};

int sensorValue = 0;

//void setup

void setup() {

Serial.begin(9600);

for (int i = 2; i < 8; i++)

pinMode(i, OUTPUT); }

//loop fragments

void loop() {

int led = 0; int analogs = 5;

sensorValue = analogRead(keyPins[analogs]);

Serial.println(sensorValue);

//an example of verification

if (sensorValue < 300)

digitalWrite (ledPin[led], HIGH);

tone(buzzerPin, 440, 1000);

delay(200);

noTone(buzzerPin);

}
else if (sensorValue > 300)

digitalWrite(ledPin[led], LOW);

noTone(buzzerPin);

//after a sequence of algorithms implented in the same way, we added a small delay between the
reading for stability

delay(200);

5.2. The Tone Function


The tone() function works with two arguments, but can take up to three arguments. Let’s address the two
required items first:

The pin number that you will use on the Arduino.

The frequency specified in hertz. Hertz are cycles per second.

The frequency is an unsigned integer and can take a value up to 65,535 – but if you are trying to make
tones for the human ear, then values between 2,000 and 5,000 are where our ears are most tuned.

6. Conclusions

In conclusion, this project was easy to implement but also, for us, a very interesting concept. Using
LDR Sensors and a Piezo Buzzer we can create an Arduino Piano.

+ BONUS: using buzzers we can set an “array” of desired frequencies to implement a theme song
we would like to hear.

7. References
1. https://programmingelectronics.com/an-easy-way-to-make-noise-with-arduino-using-tone/
2. http://www.instructables.com/id/How-to-use-a-photoresistor-or-photocell-Arduino-Tu/

Vous aimerez peut-être aussi