Use CTRL-T to auto format your code in the IDE. It makes it easier to read, lines up brackets and is just better.
Which LED is misbehaving? You have 3.
I do see a delay between turning on and LED and turning it off, but no delay after turning it off.
For your middle condition, where both sensors are low, it will look like the LED never turns off.
In reality it IS turning off, but only for a few, un-noticeable microseconds. Then it turns back on.
doh! I spent quite a while looking at the program and missed it. I knew it had to do with the fact that loop() loops (ie., re-executes repeatedly). I see it now. I believe he has the problem with all three LEDs, 2 never turn on and 1 never turns off.
OP: it is one of two issues.
Either
A. You haven't assimilated the fact that loop() re-executes repeatedly. Loop() is not a one time execution, only setup is. Therefore as soon as the LED turns off, it will turn back on during the next loop() execution.
or
B. You know that but, like I did, forgot to evaluate what happens between the loop close bracket { and the if statement.
Try moving the code to setup. It will fire once and then be done. Or, add a delay(5000) just before the closed brace } for loop(). Then the LED will change states for 5 second intervals (5 on, 5 off)
I notice that the first two statements do a HIGH, wait 5 seconds, LOW sequence, while the third does a LOW, wait five seconds, HIGH sequence. Assuming the LEDs are wired all the same and port HIGH means the LED is on, that will make the third LED switch on 5 seconds after the buttons are pressed and not switch off until the same combination is detected.
Ok, what I'm trying to do should be simple but, since I'm new to this I am probably doing this all wrong.
What I'm trying to do is with sensor1 detect a part is in place,
light a blue led, wait for X amount of milliseconds,
then if sensor2 detects metal,
lights a green led for x amount of milliseconds, then turn off led.
then go back to the beginning of the loop.
Or if it doesn't detect metal, lights a red led for x amount of milliseconds, then turn off led
then go back to the beginning of the loop.
Well you're using delay() in your sketch so when one LED is on, no further action is taken. So you won't see both LEDs go on in case a metal part is detected. Instead you'll have to use millis() based timing - see "blink without delay" on how that works. Then you can continue the loop() so if a part is detected the blue LED lights, and then either the green or the red one can switch on as well.
Here is the link to the project on tinkercad.
I used 2 sliding switches in place of 1 Capacitive (sensor1) proximity switch and 1 inductive proximity switch (sensor2)
ronlh1:
I just checked it and the link works for me.
Thanks for trying.
Try your own link without being logged in or logging in using a different account. The thing is probably linked to your account. Or indeed post a jpg (at the worst you can take a screen shot).
ronlh1: I am not concerned with the resistors at this time. I have attached a PDF explaining (I hope) a little more what I am trying to do.
Thanks
Oh yes you should be, when ever you turn an output ON to turn a LED ON, you will be OVERLOADING that output and may damage the controller.
Can you tell us your electronics, programming, Arduino, hardware experience?
Thanks.. Tom..
Make it a habit to include all components right away, especially essentials such as current limiting resistor, as otherwise you may break your Arduino and/or LEDs and/or other things. It's very to forget you still have to add them later.