Problem with Proximity Sensor, Light stay on/off when triggered
i'm trying make led stay on when triggered proximity sensor , turn off , stay off when triggered again. got sensor work fine when wanted turn light on when being touched , turn light off when not being touched.
but since made change code partially works. when touch sensor react (slower want to) , turn light on , leave on. when touch again led dim , once i'm done touching led either stay on or turn off , stay off. it's inconsistent slow reaction time. input help
here's code. thanks!
int sensorval;
#define bulb 12
void setup(){
//configure pin2 input , enable internal pull-up resistor
serial.begin (9600); //start serial monitor
pinmode(2, input_pullup);
pinmode(12, output);
}
void loop(){
sensorval = digitalread(2);
// logic inverted low on pin 2 means sinking switch activated
// , high on pin 2 means switch unactivated , pulled internal resistor
// not problem since controller can interpret data way tell to
if (sensorval == low){
light(); //execute light subroutine below
}
}
void light() //start light subroutine
{ int reading; //turn on light
reading = digitalread(12);
if (reading == high){digitalwrite (12,low);}
else{digitalwrite (12, high);}
}
but since made change code partially works. when touch sensor react (slower want to) , turn light on , leave on. when touch again led dim , once i'm done touching led either stay on or turn off , stay off. it's inconsistent slow reaction time. input help
here's code. thanks!
int sensorval;
#define bulb 12
void setup(){
//configure pin2 input , enable internal pull-up resistor
serial.begin (9600); //start serial monitor
pinmode(2, input_pullup);
pinmode(12, output);
}
void loop(){
sensorval = digitalread(2);
// logic inverted low on pin 2 means sinking switch activated
// , high on pin 2 means switch unactivated , pulled internal resistor
// not problem since controller can interpret data way tell to
if (sensorval == low){
light(); //execute light subroutine below
}
}
void light() //start light subroutine
{ int reading; //turn on light
reading = digitalread(12);
if (reading == high){digitalwrite (12,low);}
else{digitalwrite (12, high);}
}
Arduino Forum > Using Arduino > Sensors > Problem with Proximity Sensor, Light stay on/off when triggered
arduino
Comments
Post a Comment