Hi everyone, I am hoping to make my arduino count time under stimuli and I need your help.
I want to make my arduino turn on the light by servo-motor when my phone alarm rings.
But since it should not turn it on any random sounds, I want to make it move after 10 seconds of consecutive noise.
#include <Servo.h>
Servo myServo;
int threshold=1000;
int sound;
int i=0;
void setup(){
myServo.attach(11);
myServo.write(0);
Serial.begin(9600);
}
void loop(){
sound=analogRead(A0);
int ValA0=analogRead(A0);
Serial.println(ValA0);
if(sound >= threshold){
i++;
if(i=20){
myServo.write(180);
i=0;
}
}
}
this is my code, but it seems it doesn't work.
I try to add 1 in integer 'i' whenever sounds larger than certain threshold come and
if i becomes 20, I tried to make the servomotor move.
I know even if it does work it contains problems like it cannot count sounds in serial, but
in this stage, I don't even know why this basic function doesn't even work.
Can you give me a help?