I want to use both the ultrasonic sensor and IR sensor with Arduino + motors for a car project. Will I have to do any kind of multithreading on Arduino, or is it something else

  • No multithreading needed; it is something else. You may want to be more specific in your question, explain what you want to do and what you have already tried. As it stands, you won't get any useful answers.
    – ocrdu
    Oct 28 '20 at 14:47

Arduinos don't do multithreading. There are a number of attempts at implementing such things, but they're a waste of time and resources.

Instead you need to get into the habit of two things:

  1. Write non-blocking code
  2. Make use of the internal hardware peripherals when possible

The motors, using the hardware PWM, are very much "fire and forget" - set them going and you can forget about them until you want to change their speed or direction.

Ultrasonic sensors can be made both more accurate and more "in the background" by using the Input Capture peripheral of the Arduino.

IR sensors (I assume you mean proximity sensors) are usually either just like a button or a potentiometer - you just read them when you want to know what it's doing.

It's your task to learn how to fit all that together into a single program that reacts to the inputs in the way you want and control the motors in the right way.

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.