HERE IS MY CODE:
void setup() {
pinMode(3,INPUT);
pinMode(8,OUTPUT);
}
void loop() {
if(digitalRead(3)==HIGH){
digitalWrite(13,HIGH);
if(millis()==5000){
digitalWrite(13,LOW);
}
else{
digitalWrite(13,LOW);
}
}
}
THE LED LIGHT SEEMS TO STAY ON AND NOT RESPECT MY TIMER CODE. HOW TO ADD A TIMER IN THIS IR SENSOR?
HERE IS MY CODE:
void setup() {
pinMode(3,INPUT);
pinMode(8,OUTPUT);
}
void loop() {
if(digitalRead(3)==HIGH){
digitalWrite(13,HIGH);
if(millis()==5000){
digitalWrite(13,LOW);
}
else{
digitalWrite(13,LOW);
}
}
}
THE LED LIGHT SEEMS TO STAY ON AND NOT RESPECT MY TIMER CODE. HOW TO ADD A TIMER IN THIS IR SENSOR?
What IR sensor are you using?
This is certainly NOT the right code for an IR sensor.
You can't just declare pin 3 as an input. You gotta use a library.
How to use an IR sensor
By the way from what angle is this code a timer? This will only turn the light on once that is after reaching 5 seconds after activation of the Arduino.
Use the autoformat in the IDE, Use code tags for the code.
Why use the if... millis == 5000.?
That will only happend once after reset.
You take the same action whatever value of milli, digitalWrite LOW.
Take a look again!
I am a newbie so I dont really much know anything. But I am familiar with the if statements.
Thats my problem, After 5 seconds, The led light is still on. It is not turning off
I am using a E18-D80NK IR Obstacle Avoidance Proximity Sensor
@karlcorporal7
TOPIC MERGED.
Could you take a few moments to Learn How To Use The Forum .
Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum.
Please do NOT cross post / duplicate as it wastes peoples time and efforts to have more than one post for a single topic.
Continued cross posting could result in a time out from the forum.
karlcorporal7:
Thats my problem, After 5 seconds, The led light is still on. It is not turning off
I am using a E18-D80NK IR Obstacle Avoidance Proximity Sensor
Exactly! The code you have written may not receive a proper input from the sensor. Always learn to search the internet before posting . Also make sure your wiring is correct.
Maybe this solves your LED problem:
int value;
if ( digitalRead ( 3 ) == HIGH )
{
digitalWrite ( 13, HIGH );
while ( value == HIGH )
{
value = digitalRead ( 3 );
}
digitalWrite ( 13, LOW );
}
@TheUNOGuy
thank you for this, but how do I include that after 5 seconds, the output 13 will go to low even if the sensor is still detecting something?
Like how will I include the millis() here, should I insert "if" inside that while loop?
jimLee
September 29, 2020, 6:24pm
10
thank you for this, but how do I include that after 5 seconds, the output 13 will go to low even if the sensor is still detecting something?
Here's a way of doing that.
Create the global.
timeObj LEDTimer(5000);
In Setup() put.
while (!LEDTimer.ding()) delay(10);
In loop() put the line..
digitalWrite(13, !LEDTimer.ding());
When you want the LED on call.
LEDTimer.start();
Grab library :LC_baseTools from the library manager in the IDE. Add it to your project.
-jim lee
TheUNOGuy:
Maybe this solves your LED problem:
int value;
if ( digitalRead ( 3 ) == HIGH )
{
digitalWrite ( 13, HIGH );
while ( value == HIGH )
{
value = digitalRead ( 3 );
}
digitalWrite ( 13, LOW );
}
Seriously?
Did you try it?