Ever wonder that we can make a device just like RADAR and LiDAR using these sensors! Yes it is possible; but with some limitation. RADAR are the most precise but are much expensive. So let’s make our own distance mapper device which acts like RADAR using UltraSonic Distance Sensor (HC-SR04) and a Servo.
UltraSonic and IrfraRed are basic fundamental sensor for measurement of distance. These sensor measures the distance in the visible sight of them with the range of 80cm to 500cm. Both sensor have their pros and cons. IR are susceptible to sun-lite and are not good in open field.
Concept
Mapping distance like RADAR requires a rotating sensor that picks up distance at different level and maps into 2D view. Just like RADAR, to rotate UltraSonic Distance sensor, we need a servo that accurately rotates it. Once RPi2 rotates servo at specific angle, RPi2 then measures distance and plot it into 2D view as shown in title image of the article. But we can’t directly operate servo from RPi2 because, Windows IoT buil 10531 provides access to ADC and PWM via external chips. It means we can’t directly control servo from RPi2 and requires extra components. Thus I found a way to operate servo via Arduino. Arduino will communicate with RPi2 via I2C bus and operates servo:
Software
It is clear that we need to develop two firmware. One for Arduino and another for RPi2 (UWP). You don’t have to bother with the complexity of the communication as I have already provided library that will provide easy way for communication between Arduino and RPi2.
I am developing gateway firmware for Arduino. With the gateway firmware, you will be able to operate Arduino directly from Windows IoT code just like you wrote in Arduino sketch. It means that you will be able to manipulate Arduino’s digital, analog, PWM and Serial pins directly from RPi2 with minimal coding. I have already developed gateway firmware for Arduino but right now there are lots of stability issues with it. Thus I’m improving the firmware and going to write PowerTip article for that. Will update here when it will be ready.
Gateway Sketch
Here, gateway is an I2C slave device. Which will serves the task requested by RPi2. There is no special requirement to understand for gateway sketch as it is already provided at the end of the article. It is simple and well commented.
Universal Windows App
Universal Windows App will communicate with gateway via I2C and requests gateway to move servo at specified position. After successful move of servo, UWApp will measures distance and plot it into 2D view.
Do not take immediate distance reading after moving servo because it will take some time (in milliseconds) to set servo at an angle. Take multiple sample of a specific direction to get accurate distance reading. Higher the sampling, more accuracy but with less resolution (it means it will take some time to process samples). So we need to balance sampling and performance.
Schematic
An issue has been found with Arduino Nano. RPi2 won’t be able to communicate via I2C with Arduino Nano if you have implemented voltage divider circuit (Green rectangle in above image) for I2C. Try direct connection for I2C between Arduino Nano and RPi2. It not good for RPi2 (because RPi2 works at 3.3v while Arduino works on 5v) but it worked for me and there is no any side effect has been seen on RPi2.
I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt out if you wish.ACCEPTCheck Privacy Policy
Manage consent
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.