Need help making speaker make a noise through motion sensor activation.

Basically my set up is as such:
I ripped a speaker off an earbud, now I have it connected to ground and pin 8.
I also have two photoresistor circuits connected to 5v, 3.5v, GND, GND, and A0 and A1.
So photoresistor 1 is 5v, GND, A0
and Photoresistor 2 is 3.5v GND, A1

Now I have one laser pointer pointing at each photoresistor.
When photoresistor 1 is tripped I want the speaker to turn on and play a frequency of say 600Hz continuously until photoresistor 2 is tripped.
Could anyone help me out?

Envy:
Could anyone help me out?

With what? What issues are you having with the project your have described?

Arrch:

Envy:
Could anyone help me out?

With what? What issues are you having with the project your have described?

Sorry about that.
Well, the last project I did with the arduino I did with a friend who did all the coding.
So, I'm slightly familiar with the code, but I really don't know where to start with this.

Our last project had to do with double laser trip wire, so basically we had a sensor in the code read the current coming through the photocells and when it dropped (meaning the photocell had been tripped) it would activate a switch, which is basically what I want to happen here. However, this time I want it to activate a speaker to play a specific frequency.

Envy:
Our last project had to do with double laser trip wire, so basically we had a sensor in the code read the current coming through the photocells and when it dropped (meaning the photocell had been tripped) it would activate a switch, which is basically what I want to happen here. However, this time I want it to activate a speaker to play a specific frequency.

So it sounds like you already have the logic for the sensors in place, you just need to replace a few blocks of code that tell it what action to perform. To play a sound on a speaker, you can use something like this:

http://arduino.cc/en/Reference/Tone

Arrch:

Envy:
Our last project had to do with double laser trip wire, so basically we had a sensor in the code read the current coming through the photocells and when it dropped (meaning the photocell had been tripped) it would activate a switch, which is basically what I want to happen here. However, this time I want it to activate a speaker to play a specific frequency.

So it sounds like you already have the logic for the sensors in place, you just need to replace a few blocks of code that tell it what action to perform. To play a sound on a speaker, you can use something like this:

http://arduino.cc/en/Reference/Tone

Thanks for the source,
Do you think you could write a quick sample code to have the speaker make a continuous noise so I can test if it works? After that I'm sure I could figure it out in the code I have now.

Envy:
Thanks for the source,
Do you think you could write a quick sample code to have the speaker make a continuous noise so I can test if it works? After that I'm sure I could figure it out in the code I have now.

There are already examples that come with the Arduino IDE, try one of those.

Arrch:

Envy:
Thanks for the source,
Do you think you could write a quick sample code to have the speaker make a continuous noise so I can test if it works? After that I'm sure I could figure it out in the code I have now.

There are already examples that come with the Arduino IDE, try one of those.

Okay, this is my code:

void setup(){
pinMode (8, OUTPUT);
}
void loop (){
tone (8, 600);
}

and this is how it is set-up:

Copper coloured wire to red jumper to red wire (GND)
Green wire to black jumper to green wire (pin 8 )

Currently, it is not making any sound.

Currently, it is not making any sound.

Then something is wrong with the speaker, the connections or you did not upload the program to the Arduino.

UKHeliBob:

Currently, it is not making any sound.

Then something is wrong with the speaker, the connections or you did not upload the program to the Arduino.

The code is uploading fine, and I'm fairly confident in the connections (i've switched both to make sure I'm not mixing up GND and pin 8 ), so it must be the speaker.

EDIT:
OU, according to:
http://arduino.cc/en/Tutorial/tone

I need a 1000OHM Resistor, maybe that would help?

That should be 100 ohm, and it is to limit the current out of the Arduino pin. 5V/108 ohm = ~46 mA.

If you connect the 8 ohm speaker directly, you will draw ~625 mA and could burn out the pin.

C2:
That should be 100 ohm, and it is to limit the current out of the Arduino pin. 5V/108 ohm = ~46 mA.

If you connect the 8 ohm speaker directly, you will draw ~625 mA and could burn out the pin.

It is a 32 ohm speaker as it's from a headphone, I had it directly connected to the 8 pin, is it possible the 32 ohm speaker blew the pin?

Entirely possible

I= V/R = 5/32 = 156mA

AWOL:
Entirely possible

I= V/R = 5/32 = 156mA

Hmmm, I don't think I have a 100 ohm resistor, I have a few assorted ones however.
I'm currently using a protoshield, would that have protected the arduinos pin?

Envy:

AWOL:
Entirely possible

I= V/R = 5/32 = 156mA

Hmmm, I don't think I have a 100 ohm resistor, I have a few assorted ones however.
I'm currently using a protoshield, would that have protected the arduinos pin?

No, there are no components on it.
Try another pin.

Try it with a 100ohm resistor in series with the speaker. (1kohm might make the sound too soft. I haven't done the dB math though...) If it still doesn't work, try on another pin with the resistor in series with your speaker. If that works you have likely blown pin 8 of your Arduino. If it doesn't work there is more troubleshooting required. (You may have blown more than just pin 8, or there is truly something wrong with the speaker, or a loose wire somewhere, but this test won't tell you any of those details...)

As you don't have a 100ohm resistor, try any resistor that you have between 200 and 100. (You can also 'manufacture' one by playing with resistors in series and parallel. What values do you have lying around?)

Edit: correct "on" to "one". Stupid lazy fingers not hitting the keys I want... :wink:

Sembazuru:
Try it with a 100ohm resistor in series with the speaker. (1kohm might make the sound too soft. I haven't done the dB math though...) If it still doesn't work, try on another pin with the resistor in series with your speaker. If that works you have likely blown pin 8 of your Arduino. If it doesn't work there is more troubleshooting required. (You may have blown more than just pin 8, or there is truly something wrong with the speaker, or a loose wire somewhere, but this test won't tell you any of those details...)

As you don't have a 100ohm resistor, try any resistor that you have between 200 and 100. (You can also 'manufacture' one by playing with resistors in series and parallel. What values do you have lying around?)

Edit: correct "on" to "one". Stupid lazy fingers not hitting the keys I want... :wink:

I have two very high value resistors only and it's a civic holiday here in Canada. So i'll look into getting resistors tomorrow and post back, thanks a lot guys!

Another option for manufacturing your own resistor values (if you don't want to wait for tomorrow) is if you have a potentiometer and an ohm meter. Set the potentiometer so it is about the value you want from one end to the wiper (usually the center connection). Then wire those two pins to your circuit. (Don't accidentally adjust the potentiometer after setting it with your ohm meter...)

If you do decide to wait until the shops open tomorrow, see if the store you go to sells assortments of resistors. Something similar to this: RadioShack.com Official Site - America's Technology Store (I don't know if RadioShack exists in Canada...) Keep the assortment with your prototyping stuff and the next time you need an odd-ball resistor you should have it (then have a pint for me). :wink:

have two very high value resistors only

So, figure out the parallel resistance, which will be lower.
See if that would work.
For example, two 1k resistors in parallel give 500 ohms.

Ear bud speaker is a piezo isn't it? You shouldn't get much current through a piezo speaker!

In a pinch, a pencil "lead" (really graphite) works as a resistor and so can many-many common objects/substances. Use a multimeter to find out how much. Even pencil lines on paper (draw heavy and thick for less resistance) will do, use paper clips to hold contact.

Ear bud speaker is a piezo isn't it?

No, especially as he said it was 8 ohms.