Hello!
Im beginning to play around with my duemilanove and so far so good, but for some reason, what seems like a simple project in my head is not yielding the results id like.
Im running the 5 v through a fixed resistor and then an LDR and trying to use its return to generate a tone to play from a speaker, but for whatever reason its not working out...
#define speaker 0 #define SENSOR 1
int val = 0;
void setup() {
pinMode(speaker, OUTPUT);
}
void loop(){
val = analogRead(1); //taking a reading from sensor output before GND
tone(speaker, val*4, 500); // trying to multiply # from analog read to become my frequency
noTone(0); // used to stop tone to allow next reading to occur properly?
delay(100);
}
One thing I have noted, there is an error message any time i upload the sketch WHILE the speaker is in the circuit- removing the speaker and connecting after upload avoids this. Any thoughts on that, or the sketch? Having a blast with arduino hope to work it out soon.
Hey, good thought- i switched the pin over to 4, but still no luck. The speaker works in other sketches using the tone(), but is a .5W 8ohm out of some toy i opened up a bit ago.
I have also played around with the val multiplying, as im not entirely sure what number the sensor will return for the analogRead function, and im sure the hz range for this lil speaker isnt too great..
the error that occurs (only when uploading a sketch WHILE the Speakesr connected to the arduino's ground) isss...
avrdude: stk500_getsync(): not in sync: resp=0x00
and also says "programmer not responding"
Pretty sure the breadboard is setup right, used similar sketches to take readings for LEDs and other such classic examples.. Thanks for the reply!
Why you are using pin 0 for a tone ? The tone example show to use pin 8 - Digital 8 The pin 1 is the analog pin 1, for the analog reading.
When I do a project, the only pins are a "No No" is Digital pin 0 and Digital Pin 1 ( RX pin and TX pin). Let me put in this way... In a public washroom, when a toilet cubicle is occupy, you don't use an occupy toilet cubicle, you use an un-occupy toilet cubicle...
Sorry for the example...
About tone and notone... you play the pin 8, you shut the pin 8.
const byte speaker = 8;
const byte SENSOR = 1;
int val = 0;
void setup() {
pinMode(speaker, OUTPUT);
}
void loop(){
val = analogRead(1); //taking a reading from sensor output before GND
tone(speaker, val*4, 500); // trying to multiply # from analog read to become my frequency
noTone(speaker); // used to stop tone to allow next reading to occur properly?
delay(100);
}
F. i do not. arduinos can deliver 50mA, and i guess i used 625mA? i hope i didnt kill my board. its still responding to other sketches so i hope im ok. back to the drawing board for me. Does anyone suggest any material re/ working with external power? Im working with an "IRF520 YO8W AA" transistor at the moment, but all the videos ive found using transistors use ...
Catalog #: 276-1617
im familiar with the concept of transistors, atleast PNP ones, but i wonder if the difference between mine and that one is negligible or not... Thanks for the critique.