1

I'm currently working on a project in which I'm supposed to make an Arduino car dodge any kinds of obstacles. I know how to do without using Interruptions but as I was searching online I found out that this is something that is used and would turn out better. Is it really possible? And if so, I don't exactly grasp the concept of using it to make (for example) the car stop once it senses an object. I know that it is supposed to be the first thing it will do if I program it that way but, can I program how the Interrupt will act upon the machine? And if so, how exactly?

Thanks

3 Answers 3

1

Interrupts help if an event needs to be dealt with over the time period of a few processor clock cycles. Such as the deployment of air bags. If the accumulated delay of not responding in a few processor clock cycles adds up to considerable error. Such as a Real Time Clock (RTC). Or, if an event is so short that it might be missed during periodic polling (checking). Such as counting flashes of lighting during a storm.

If this type of response time is not needed, interrupts may be more trouble than they are worth.

This is because interrupts can stop the processor from executing the normal program and force it to execute the interrupt program. This can be very confusing to new programmers. At any moment an interrupt may stop their program and possibly erase or change what that program was working on. Both the program that is running and the interrupt program need to be written to tolerate this processor behavior.

It is almost always easier to "poll" the state of obstacle sensors (in this case) rather than tying its state to an "interrupt". Using the Arduino paradigm, the purposes of the loop() entry point is to do just this. A function which will be called over and over again. Each time it is called you can "poll" the sensor and cause the model car to vier around an obstacle.

1
  • Yeah, your bot would have to be moving awfully fast to really need an interrupt to respond to an obstacle. For most of these types of bots you have a few milliseconds to react.
    – Delta_G
    Commented Oct 1, 2017 at 21:20
0

See How do interrupts work on the Arduino Uno and similar boards?

I was searching online I found out that this is something that is used and would turn out better. Is it really possible?

That's very vague. What did you find online?

And if so, I don't exactly grasp the concept of using it to make (for example) the car stop once it senses an object.

Set a flag in the interrupt, which you detect in your main loop. In the main loop make the car stop when the flag becomes true.

0

Is it really possible?

anything is possible.

And if so, I don't exactly grasp the concept of using it to make (for example) the car stop once it senses an object.

all an interrupt does is to take the execution to a different place. in practical terms, an interrupt would execute some quick functions and set some flags for the main loop to execute.

interrupts are critical to embedded engineering and it is very difficult for a real-world code to run without interrupts.

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.