Windows 10 IoT Core: UltraSonic Distance Mapper

Hardware components:
Ard nano
Arduino Nano R3
× 1
R8326274 01
Raspberry Pi 2 Model B
× 1
Ultrasonic Distance Sensor (HC-SR04)
× 1
Servo (generic)
× 1
Resistor (1K)
× 3
Resistor (2K)
× 3
11026 02
Jumper wires (generic)
× 1
12002 04
Breadboard (generic)
× 1
Software apps and online services:
Ide web
Arduino IDE
Vs2015logo
Microsoft Visual Studio 2015
10
Microsoft Windows 10 IoT Core

STORY

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:

Concept of UltraSonic Distance Mapper

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

schematic diagram of UltraSonic Distance Mapper

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.

Read More: Windows 10 IoT Core: UltraSonic Distance Mapper


About The Author

Ibrar Ayyub

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.

Follow Us:
LinkedinTwitter

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top