Having some noob trouble with a sketch, and an arduino uno, i'm sure anybody with more knowledge than me could help.
add me on skype, gabe.spound2
Having some noob trouble with a sketch, and an arduino uno, i'm sure anybody with more knowledge than me could help.
add me on skype, gabe.spound2
Can you please simply post your issue here with sketch, diagrams and description of the problem then many folks will be able to help
and then the answer will also help many
ok, im just not a hundred percent sure what the problem is any when i do that people just shoot what they think will work and don't help me out, i really just need somebody to skype w/ me so i can show them the issue, but ill try to sum it up.
Sketch Below.
Basically, i have analog read on A0 and if it's greater than 8 digital write pin 2 high, less than 2, write low. on an led it works great, led on when clap is heard, led off once more when clap is heard again. but when i hook it up toa relay, the relay just goes on then off, it doesn't stay off
int analogValue; // This is where we'll store our audio to digital value. More sound = higher number
#define LED 2 // Set up the LED indicator
boolean toggle = false; // setup a boolean function called toggle which will help us to choose which mode we're in
int numberOfClaps = 0;
void setup()
{
pinMode(LED,OUTPUT); // Pin#2 should be conencted to an LED through a 300-600 ohm resistor
Serial.begin(9600); // This is optional - It just helps you to calibrate sensitivity after the fact
}
void loop()
{
if (toggle == false) // When you power up your arduino, boolean "toggle" is set to false, so the following section of code will //commence. The "ELSE" is ignored for now.
{
digitalWrite(LED,LOW); // Turn the LED off
analogValue = analogRead(0); // Take an analog reading from A0 line. No sounds should be offer a returned value of "0"
if (analogValue > 8) // If higher than 8 is returned, then change state of boolean "toggle" to true, display analogValue to // serial monitor and wait 200ms.
// The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to // your wanted sensitivity =D
{
toggle = true;
Serial.println(analogValue);
delay(200);
}
}
else // If boolean "toggle" has beenchanged to true, then the above section of code will be ignored, and the // code below will commence.
{
digitalWrite(LED,HIGH); // Turn the LED on
analogValue = analogRead(0); // Take an analog reading from A0 line. No sounds should be offer a returned value of "0"
if (analogValue > 8) // If higher than 8 is returned, then change state of boolean "toggle" back to false, print analogValue // to serial monitor and wait 200ms.
// The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to // your wanted sensitivity =D
{
toggle = false;
Serial.println(analogValue);
delay(200);
}
}
}
Okay so you've included the code for the LED.
What about including what you did for the relay.
Note to include code paste the code, then select it.
Click on the >> and then select Syntax highlighting, and C++.
You find it then looks like below...
int analogValue; // This is where we'll store our audio to digital value. More sound = higher number #define LED 2 // Set up the LED indicator boolean toggle = false; // setup a boolean function called toggle which will help us to choose which mode we're in int numberOfClaps = 0; void setup() { pinMode(LED,OUTPUT); // Pin#2 should be conencted to an LED through a 300-600 ohm resistor Serial.begin(9600); // This is optional - It just helps you to calibrate sensitivity after the fact } void loop() { if (toggle == false) // When you power up your arduino, boolean "toggle" is set to false, so the following section of code will //commence. The "ELSE" is ignored for now. { digitalWrite(LED,LOW); // Turn the LED off analogValue = analogRead(0); // Take an analog reading from A0 line. No sounds should be offer a returned value of "0" if (analogValue > 8) // If higher than 8 is returned, then change state of boolean "toggle" to true, display analogValue to // serial monitor and wait 200ms. // The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to // your wanted sensitivity =D { toggle = true; Serial.println(analogValue); delay(200); } } else // If boolean "toggle" has beenchanged to true, then the above section of code will be ignored, and the // code below will commence. { digitalWrite(LED,HIGH); // Turn the LED on analogValue = analogRead(0); // Take an analog reading from A0 line. No sounds should be offer a returned value of "0" if (analogValue > 8) // If higher than 8 is returned, then change state of boolean "toggle" back to false, print analogValue // to serial monitor and wait 200ms. // The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to // your wanted sensitivity =D { toggle = false; Serial.println(analogValue); delay(200); } } }
Mark
thats what im using for the relay lol, what should i do to toggle a relay when analog input on a0 is greater than 9, i thought itd be the same
I have the suspect that maybe the circuit. Can you post the scheamtic of your relay circuit ?
Thank you. Enrico
can somebody just skype with me for five minutes, im sure its a simple issue, i just don't know much
if you havce a skype, im sure you could help me out very quickly
@gub11
Sorry but your photo is not that clear on where all the wires go to.
Your code uses Pin2 for the LED (which you say works fine), but the photo looks like you are using pin 6.
In the same manner your power looks like 5v and 3v3 rather than ground.
This may be an illusion but without clear schematic or picture no amount of skype will help.
Also this post serves as a reference to others, who may have similar issues.
Mark
well the problem isn't the circuit, i know that, that's the part im good at, the only thing i don't really know how to work is the relay