Laser Harp Resistor Question

Hey, Im fairly new to all of this but Im building a 6 laser harp for a uni project. I have built everything, all the lasers work and the LDRs are wired up in its frame but i have no idea what sort of resistors to use. I have been following this guide:

Its a good guide but Im using different LDRs, im using G5528 LDRs, Maximum voltage 150v DC.

Wattage. 100 mW.

Any help would be greatly appreciated as Im completely clueless and don't want to damage what iv already made by using the wrong resistors.

Thanks, Jamie.

That link uses photo transistors not LDRs the two are very different.

Measure the resistance of your LDR in normal light and then use a resistor that is roughly the same value.

Here is my version of the same thing without the lasers.

Im even worse then i thought i was! Thanks for the help and i will use your advice. luckily i have about every resistor going so il have some that i can use.

Can i still use the same code from that guide once i have the resistors sorted or will it need to be changed?

PS. Nice video, I wish mine worked as well as that!

Can i still use the same code from that guide once i have the resistors sorted or will it need to be changed?

No idea, you might have to change the trigger reference value, but as I said it is an LDR not a photo transistor.
An LDR will produce a proportional drop in resistance as the light gets brighter, where a photo transistor will produce a more abrupt transition.

I have checked my LDRs, when the lasers on them there at about 10K ohms and in low lighting its around 400k ohms or so. Im just trying to get one of them to work and once I have that I can add the other 5.

This is the code Im unsuccessfully using :

const int analogPin0 = A0;
const int speaker = 8;
const int threshold = 100;
const int threshold2 = 1;

#include “pitches.h”

void setup() {
pinMode(speaker, OUTPUT);
Serial.begin(9600);
}

void loop() {
int analogValue0 = analogRead(analogPin0);

if (analogValue0 < threshold) {
for (int thisNote = 0; thisNote < 8; thisNote++) {
tone(8,NOTE_A2,8);
noTone(8);
}
}
Serial.println(analogValue0);
}

I’ve included a photo of how it is currently.

-Right yellow wire - Digital in 8
-Left yellow wire - GND
-Top Black wire - 5V
-Red wire - A0
-Bottom black wires - Speaker
-10K resistor with the LDR
-100 ohm resistor with the speaker wires

If anyone could help it would be really useful, It needs to be demo’ed tomorrow so im panicking and im sure iv got lots of things that need adjusting.

Thanks

When I run it now it does make sound and if I change the NOTE value in the code the sound does change but its constantly on, how can i adjust the values so when the LDR is 250k+ Ohms it triggers the sounds.

const int threshold = 100;

Is the line which sets the threshold, adjust this number to change the trigger point.

What is this all about?

if (analogValue0 < threshold) {
for (int thisNote = 0; thisNote < 8; thisNote++) {
tone(8,NOTE_A2,8);
noTone(8);
}

Just read that it is very wrong. It is turning the note off just as soon as you turn it on and why do it 8 times?

I did think it was that as if i change that to 35000+ theres no constant sound which is another step closer i guess. As i said i’m very new to Ardunio so i just used the code provided in the guide I linked in my first post.

Would you know how I could clean it up? Thanks for all the help Mike, thanks to you I might actually have a working model to display tomorrow instead :smiley:

As the output of the analogue to digital converter is only 0 to 1023 then setting it to 35000 is a bit silly. Even more this number is bigger than the biggest number you can get in an int.

You need to look at the readings you are getting from the analogue read by using a serial print, then you will know what value to set the threshold to.

I didnt know it maxed out at 1023, strange how it stops making a sound past 35K but will at anything lower then that. Well if I can get the sound turning off and on with the LDR which means sorting out that dodgy code I could just play around with the threshold until its working correctly in the right lighting.

35k resistance is not the same as the 10 bit range of the ADC.

As i said i’m very new to Ardunio so i just used the code provided in the guide I linked in my first post.

As you are new so you are excused, but instructables are simply crap. You should never read them if you do not know what you are doing. There is absolutely no quality control. I have yet to see one in electronics that has not got something wrong with it.

Try this:-

const int analogPin0 = A0;
const int speaker = 8;
const int threshold = 100;
const int threshold2 = 1;

#include "pitches.h"

void setup() {
pinMode(speaker, OUTPUT);
Serial.begin(9600);
}

void loop() {
int analogValue0 = analogRead(analogPin0);

if (analogValue0 < threshold) {
tone(8,NOTE_A2,8);
delay(100);
noTone(8);
delay(50);
}
Serial.println(analogValue0);
}

Look at the value that is given in the serial monitor. Tell me what it is printing.

When I run that code the sound isnt constant, but in a beat instead, but it wont turn off once i shine a light on it or laser.

in the monitor it reads 0 every beat untill i cover the LDR and it starts reading from 20-50 when i put my finger over it but still reads 0 even if i cover it up.

Thanks so much for the help again!

Set the threshold to 10 and change the < in the if statement to a >

When i change it to 10 and edit the if statement the sound is still constantly looping, even when i shine a light on it. Do you think it might have something todo with the resistor im using?

Yes the readings you reported do not look right. If you had followed my instructions and wired them up right you should see a reading of 500 and then you see changes after that. Time to post a picture of how you have wired them, not more than 1000 pixels wide.

Heres a current photo. Ignore the two green wires at the top of the board, they just run to the speaker. The black wire goes to 5v but dont think its even doing anything?? The red wire to A0. Bottom yellow to D8 and the top yellow goes to ground. I have a 4.7K resistor next to the LDR and a 100 ohm resistor before the speaker cables.

OK - this is not wired up right.
The red wire that feeds into the analogue input should be at the junction of the LDR and the resistor.
The other end of the LDR should be at ground and the other end of the resistor at +5V.

EDIT - Did you just swap the picture over while I was replying?

I uploaded a photo that i used yesterday instead of my current one, the one up now is correct. the photos just on its side.

OK still wired up wrong though.