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, 2020 at 14:47

2 Answers 2


While it is completely possible to hook two or more sensors to Arduino, once you talk about multithreading, you need to think about RTOS support. You can achieve parallel processing by creating 2 diffenent tasks using xTaskCreate in freeRTOS. Latest development support in Arduino allow to create such tasks.


While the concepts of RTOS are vast, you can quickstart with Arduino freeRTOS library and check whether it meets your requirements. I used to do such project for obstable avoider bot and faced lot of challenges if there is no parallel processing. I am sure you'll be able to acheive much better results with multithreading.

Regarding sensor, make sure ultrasonic sensor is giving reliable data for every readings and don't use IR sensor under sunlight conditions otherwise it'll give erratic results. All the best with your project!


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 and acknowledge you have read our privacy policy.

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