0

I have spent quite a considerable time debugging my code that was triggering false interruptions. I have found out that the source of the error were the diode lights (on the picture). I would like to ask if anyone can point me to the possible source of such behaviour.

I will try to explain really briefly what the issue was providing only needed (from my point of view) details. If you would require more - tell me.

So, I have a board that looks like this: circuit

You can see two reed switches (close circuit in the presence of a magnet) which leads the INT0 (pin 2) and INT1 (pin 3) on arduino to trigger an interruption on their RISING behaviour. The pull down resistors are 1kOhm. This cirquit works perfectly.

The original version of this circuit had lights in positions D5-D10 and D19-D24 (between the reed switches and the connections to the interruptor pins). The lights are these: diod lights

The part of the circuit with the red light (connected to INT1) worked flawlessly, while the circuit with the green light (connected to INT0) every once in a while triggered a false interruption in INT1. The lights, however were always blinking correctly.

I have nearly no experience with circuits and hardware, so a pointer on where to start reading to understand the issue is also welcome. Hope to hear from someone who knows what the cause could have been. I would still like to use the lights somehow, because they give a nice feedback on what is happening to the system.

Thanks!

PS. I do not think the code is necessary here, but I will post it too if you like. I am however quite confident that the bug is not on the software side.

5
  • Could be mechanical. Like the reed switch triggering due to vibration. Try swapping the two reed switches.
    – Gerben
    Commented Nov 12, 2015 at 13:45
  • @Gerben, I though about it too. But the reed switches are far away from each other and while I test one, the other just rests on the table. The issue is definitely with the lights. When I take the lights out of the circuit everything works as intended.
    – niosus
    Commented Nov 12, 2015 at 14:46
  • 2
    What do you use the leds for? and.. They were with a series resistor, right?
    – frarugi87
    Commented Nov 12, 2015 at 14:52
  • @frarugi87, what do you mean by the series resistor? I'm afraid I don't understand that. I use them to indicate that the circuit has been closed. Just for visual information, that the magnet is close enough to trigger the reed switch. The actual functionality does not rely on lights of course. But it is nice to have such an indication.
    – niosus
    Commented Nov 12, 2015 at 14:55
  • Now I think I understood your problem ;) check my answer
    – frarugi87
    Commented Nov 12, 2015 at 17:37

1 Answer 1

2

Aaaaah, ok, now I see...

You put

+5V - Reed - LED - input pin - 1k resistor - ground

right?

If so the problem is that a red led has (usually) a voltage drop of about 1.5V, while the green one has a voltage drop of 1.8V-2.0V. The Atmega 328P has a Vih (i.e. the minimum voltage needed for a reliable high) of 0.6*Vcc, so for a 5V supply this value is 3V.

Consequently with a green LED you will have a value TOO CLOSE to the minimum acceptable value for the input pin. Note that the 2.0V value is an usual one, but different leds have different voltages.

Moreover the so-called high-brightness leds (the ones with a transparent case) have a more-than-3V voltage drop, so if you put for instance a blue led you will never receive a signal.

To solve the problem, you have three solutions:

1) use a (low brightness) red led also for the green path 2) remove the led from that path and drive it directly with the arduino (you will have also the notification that arduino has understood the command) 3) change the path to

+5V - Reed - input pin - LED - 1k resistor - ground

(i.e. take the voltage BEFORE the led, not after)

I think it'll work then :)

EDIT: according to the data I found on the internet the red led is usually 1.8V, while the green one is usually 2.1V. This does not change my answer, anyway.

And... You won't "fry" your pins with the 5V you are prividing to the circuit....

3
  • Thanks, that sounds about right! Thanks for the nice explanation! As the last small question - can you elaborate a bit more on your last sentence? "You won't "fry" your pins with the 5V you are providing to the circuit...." - am I on the way to doing this the way I've been addressing the problem?
    – niosus
    Commented Nov 17, 2015 at 11:25
  • That sentence was a reply to the edit to another answer (and the answerer removed the answer, so the sentence is meaningless now). He said that you'd better put the reed towards ground instead of vcc, otherwise you could fry the board. But this is not true, or at least this won't solve the problem. The only way to fry a pin with 5V is to connect it to Vcc and set it as an output in the arduino, but the same applies to a pin towards ground. If you set it as an input you can't fry it with 5V.
    – frarugi87
    Commented Nov 17, 2015 at 11:38
  • 1
    thanks! That agrees with what I know :) Then the issue is closed. Thank you again :)
    – niosus
    Commented Nov 17, 2015 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.