Introduction: EAL - Arduino Laser Harp

Hello and welcome to my instructables.

I'm going to tell you how I programmed and build my very own Laser Harp, using an arduino UNO. First off, I want to say that I am new to the arduino environment, and this was my first project.

This is a project I made in my elective subject at Erhvervsakademiet Lillebælt in Denmark. The idea was to build a frame with 3 lasers on one side pointing at 3 photoresistors on the opposite side. When the laser beam was cut, a tone would play from a piezo buzzer.

Here is a list of all the materials I used throughout this project:

1 Arduino UNO

3 Photoresistors

3 Lasers

1 Piezo buzzer

1 Piece of wood (plank)

1 Breadboard

A lot of wires!

I will divide the project into 4 steps:

Step 1: Building the frame

Step 2: Lasers and photoresistors

Step 3: The code

Step 4: The circuit

Step 1: Step 1: Building the Frame

Building the frame turned out to be more difficult than expected. I went to the local hardware store and bought an ordinary plank. Afterwards I lent a hand and some tools from my brother, and we cut the plank into 4 pieces. We made sure that the pieces would fit nicely together, however some corners turned out to be a bit uneven, which meant the frame turned out to be a bit crooked (though still good enough for this project). Nevertheless we managed to glue the frame together and make it sturdy.

With the frame done, it was time to place the lasers and photoresistors on the frame!

Step 2: Step 2: Lasers and Photoresistors

When I had to screw the lasers and photoresistors on the frame everything had to be perfect. The lasers had to be directly opposite of the photoresistors in order for the harp to be successful. This meant that when I placed the laser on the frame, I was constantly aware that the light would hit the opposite photoresistor; remember guys, being lazy is doing it right the first time!

As a final touch to the harp, I decided to screw the buzzer, the breadboard and the arduino UNO on the frame aswell, to make it look really awesome!

At this point there was basically only one thing left to do; the code!

Step 3: Step 3: the Code

Writing the code was the most challenging part of the project since I didn't know how text-programming worked.

Firstly I needed to figure out how to read the photoresistors. I knew they would give me feedback i could read, therefore i wrote Serial.print commands, and opened the serial monitor in the arduino software. On the serial monitor I could read the difference from when the laser hit the photoresistor and when it did not. With this information i searched the arduino website and found three useful functions. First off, I found a function called tone that plays a tone at a certain frequency. I then combined tone with an if... else function, so that if the laser-beam is cut a tone will play from the buzzer, or else a function called noTone would stop the sound wave created by the tone function, since the laser-beam would be intact and therefore hit the opposite photoresistor

With these three functions the laser harp was pretty much programmed, I just needed to figure out what frequencies sounded good. So I searched the internet and came across a forum where someone posted a formula on how to calculate notes into frequencies (I'll post a picture of the formula).

I will paste the code underneath.

<p>int sensor = 0;<br>int sensorr = 0;
int sensorrr = 0;</p><p>void setup() {
  pinMode (4, OUTPUT); // Buzzer
  pinMode (7, OUTPUT); // Laser 1
  pinMode (8, OUTPUT); // Laser 2
  pinMode (9, OUTPUT); // Laser 3
  }</p><p>void loop() {
digitalWrite (7, HIGH);
digitalWrite (8, HIGH);
digitalWrite (9, HIGH);
sensor = analogRead(A2);      // The first photoresistor
sensorr = analogRead(A4);     // The second photoresistor
sensorrr = analogRead (A5);   // The third photoresistor</p><p>float value = sensor * (5.0/1023.0);
float valuee = sensorr * (5.0/1023.0);
float valueee = sensorrr * (5.0/1023.0);</p><p>Serial.print ("sensor =");
Serial.print (sensor);
Serial.println ("   ");
Serial.print ("sensorr =");
Serial.print (sensorr);
Serial.println ("   ");
Serial.print ("sensorrr =");
Serial.print (sensorrr);
Serial.println ("   ");
delay (200);</p><p> // The Serial.prints above is so i can read the feedback from the three photoresistors via serial monitor
 </p><p>  if (sensor < 100){ 
  noTone (4);
  tone(4, 440); // 4 is the number of the buzzer-pin and 440 is the frequency
if (sensorr < 60){
   noTone (4); 
  tone (4, 622);
}</p><p>if (sensorrr < 100){
  noTone (4);
else {
  tone (4, 659);
    return;</p><p>  // 440 frequency is equivalent to an A, 622 is equivalent to a D#, 659 is equivalent to an E 

Step 4: Step 4: Circuit

Wiring the laser harp correct! I posted a couple of pictures on how i created the circuit, however I will explain shortly how each component should be wired. Further explanation; the green wires are ground, the red wires are +5V and the yellow wires are signal. I connected two wires from the arduino to the breadboard, a ground and a +5V, this meant that I had several more grounds and +5V's to play with.

I'll start off with the photoresistors (the ones on the topside of the pictures). The photoresistors have three legs; one for ground, one for +5V and one for signal (the photoresistors use an analogue input, I used analogue inputs A2, A3 and A5 in my program).

Next off is the lasers (bottom side of the picture). The laser have three legs as well; a leg for ground, one for +5V and one for signal (the lasers use digital inputs, in my program I used digital input 7, 8 and 9 for my lasers).

Lastly there is the Piezo buzzer (next to the arduino). Surprisingly the buzzer has three legs too, once again, a leg for ground, another for +5V and the last for signal (the buzzer uses a digital input as well, I used the digital input 4).