-1

My program has a hardware interrupt to digital pin 2, it is an IR obstacle detection sensor which gives “open collector” signal. My program is executing an array — “for” loop. At some point it has to wait for the input from the IR sensor, so I am using a “while” loop to pause and wait for the input.

When the program gets the signal from the sensor at which point the interrupt occurs, the program collects the data (millis) and goes on for another round. Everything works fine, but I would like to limit the time that the program is waiting for the interrupt signal, let’s say to 5 or 10 seconds. I do not want it to just sit there forever if the signal is not coming for some reason. So what I am trying to do is to trigger the same interrupt pin (2) by another digital pin. I set this pin (7) on OUTPUT wrote a little “if-then” statement so it will go HIGH when the time is up and connected this pin (7) to pin 2.

The scheme works partially. When the pins are connected and the time limit is reached the pin 2 gets signal and gets triggered. But the IR signal seems to be disabled and not functioning while it is waiting for the time limit. I tried to connect pull-up and pull-down resistors to no avail. It seems that when the pins are linked the IR signal disappears. I do not even get any voltage readings on that wire. If I disconnect the pins the IR signal works again and I get voltage readings on the wire.

Can anyone tell me what is going on and how can I make it work. Is even possible? Or what I have concocted is just plain silly?

Thank you!

  • To be honest, how you are working around your interrupt problem is confusing. There may be a better way. Regardless, how to OR together open collector outputs is an interesting problem to solve. – st2000 Apr 26 '16 at 2:05
  • 2
    I hope you see that by "working around" your first problem, you created another problem. Why don't you just break out of your while when it is holding on too long? Fixing software issues in hardware is just not the path to go. – Paul Apr 26 '16 at 8:16
  • Thanks everybody for the help, and God Bless this forum and its members. I do not know what I could have done without it… Software solution is exactly what I needed, but because my knowledge of Arduino and programming is so meager I just did not know how to get out of the “while” loop properly. The “break” was exactly what I needed All works great! I was so caught up in trying to trigger the interrupt pin I could not see the forest for the trees. Here is the link to the video of the prototype I am working on. youtube.com/watch?v=--y6LWQXjzw Thanks again! Vladimir. – Vladimir Apr 28 '16 at 20:14
0

It is likely that the Arduino's digital output is of a totem poll type. That is, it is both actively being driven high and low. And when high, is probably over powering the IR sensor's signal. You should not use this setup!! As it could possibly short out both your processor and IR sensor.

Instead you could emulate an open collector Arduino output. By switching the second pin from a digital input to a digital output sending 0 then back to a digital input. (Never set this pin to digital output and send a 1 as this could short to ground through the IR open collector.)

I am assuming that the IR sensor, when activated, is momentarily pulling a pull up resistor low through the open collector to ground. Let us know if this is incorrect as the above description would then not apply.

  • Thanks everybody for the help, and God Bless this forum and its members. I do not know what I could have done without it… Software solution is exactly what I needed, but because my knowledge of Arduino and programming is so meager I just did not know how to get out of the “while” loop properly. The “break” was exactly what I needed All works great! I was so caught up in trying to trigger the interrupt pin I could not see the forest for the trees. Here is the link to the video of the prototype I am working on. youtube.com/watch?v=--y6LWQXjzw Thanks again! Vladimir. – Vladimir Apr 28 '16 at 20:14
0

Wouldn't it be easier just to have the interrupt call a function, that you also call after 5 seconds are up? This sounds a round-about way of doing it.

If you must do this, setting your other pin to output is not correct, because then the IR sensor and your other pin (7) are fighting each other. You should set the pin to input, and when you want it to do something briefly make it OUTPUT, and send HIGH. Then send LOW, and go back to INPUT.

However this might still make the output pin "fight" the IR sensor pin.


But the IR signal seems to be disabled and not functioning while it is waiting for the time limit.

Naturally, as your output pin is holding the line low.


If the sensor just uses a pull-down resistor (and not actively drive the line low) then my scheme should work.


However a simpler scheme is just to set a flag in the ISR, (which you test for in the main loop) and if the flag isn't set within your timeout period, do whatever you want to do if it times out. Then you don't need to try to trigger the interrupt yourself.

  • Thanks everybody for the help, and God Bless this forum and its members. I do not know what I could have done without it… Software solution is exactly what I needed, but because my knowledge of Arduino and programming is so meager I just did not know how to get out of the “while” loop properly. The “break” was exactly what I needed All works great! I was so caught up in trying to trigger the interrupt pin I could not see the forest for the trees. Here is the link to the video of the prototype I am working on. youtube.com/watch?v=--y6LWQXjzw Thanks again! Vladimir. – Vladimir Apr 28 '16 at 20:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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