hey, so i got this circuit wired up into my arduino Analog input, i got a condenser mic with a preamp and im getting some nice readings ranging from 0-700.. so what i want to do is start a motor or activate a relay once the readings surpass 200. I have no idea how to do this as im fairly new to the arduino interface and all its features i tried using an "IF" command but it didnt work out like i wanted it to., could anyone help me out with a simple command that will be able to do this? or/and guide me to where i can read more about this. thanks in advance!
It's better if you post your code and we talk it through to see where you went wrong.
but it didnt work out like i wanted it to
How was that then? Sorry for asking but my mind reading capabilities are rubbish.
if is exactly right. if is the most common way for a program to "make a decision". But somehow you've made a mistake in your code. Can we see it?
Don't put a semicolon at the end of your if-statement.
And if the true-condition is supposed to execute more than one line of code, use curly-brackets.
Something like:
if(analogRead(1) > 200)
digitalWrite(13, HIGH); // Turns-on LED
(I haven't checked that code snippet, so I hope I didn't make a stupid mistake myself. But that's the general idea.)
You can troubleshoot your code by simplifying... For example, turn on an LED instead of the motor. Or, take-out the if-statement, or force the if-statement to always return true by changing it to if(1), etc.
P.S.
You'll also have to decide what to do after turning-on the relay... For example, delay and hold the relay on for awhile. If you run your if-statement in a tight loop, the Arduino's output will switch on & off when the level goes over/under 200 and the relay will either "chatter" or never come on, since mechanical relays don't come-on instantly.