Anurag S. Vasanwala
Published © GPL3+

Windows 10 IoT Core: UltraSonic Distance Mapper

Scan and draw ruff sketch of distances ahead just like RADAR using UltraSonic Distance Sensor.

IntermediateShowcase (no instructions)70,203

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Raspberry Pi 2 Model B
Raspberry Pi 2 Model B
×1
Ultrasonic Distance Sensor (HC-SR04)
×1
Servos (Tower Pro MG996R)
×1
Resistor (1K)
×3
Resistor (2K)
×3
Jumper wires (generic)
Jumper wires (generic)
×1
Breadboard (generic)
Breadboard (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Visual Studio 2015
Microsoft Visual Studio 2015
Windows 10 IoT Core
Microsoft Windows 10 IoT Core

Story

Read more

Schematics

Schematic (Fritzing)

Schematic

Code

Gateway (Arduino Nano)

C/C++
/*
  Gateway sketch for UltraSonic Distance Mapper (RPi2 + WinIoT)
  https://www.hackster.io/AnuragVasanwala/windows-10-iot-core-ultrasonic-distance-mapper-d94d63

  Objectives:
    + Initialize Servo
    + Initialize I2C Slave in address 0x40 (64 DEC)
    + Move servo to specified position when master (WinIoT) sends position byte
*/
#include <Wire.h>
#include <Servo.h> 

#define MyAddress 0x40
#define Pin_Servo 3

/* Create object for servo motor */
Servo MyServo;

/* Initial servo position */
byte Position = 70;

void setup()
{
  /* Initialize servo and move to initial position */
  MyServo.attach(Pin_Servo);
  MyServo.write(Position);

  /* Initialize I2C Slave & assign call-back function 'onReceive' */
  Wire.begin(MyAddress);
  Wire.onReceive(I2CReceived);
}

void loop(){ /* Do nothing. Just wait for call-back 'onReceive' */ }

/* This function will automatically be called when RPi2 sends data to this I2C slave */
void I2CReceived(int NumberOfBytes)
{
  /* WinIoT have sent position byte; read it */
  Position = Wire.read();

  /* Move servo to specified the position */
  MyServo.write(Position);
}

Universal Windows App (RPi2)

Improved Code (by Dave Glover)

Profile Ref: https://www.hackster.io/glovebox

Credits

Anurag S. Vasanwala

Anurag S. Vasanwala

8 projects • 510 followers
Thanks to Jerry Nixon.

Comments