Things used in this project

Hardware components:
Ard nano
Arduino Arduino Nano R3
×1
R8326274 01
Raspberry Pi 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 Arduino IDE
Vs2015logo
Microsoft Visual Studio 2015
10
Microsoft Windows 10 IoT Core

Schematics

Schematic (Fritzing)
Windwows IoT - UltraSonic Distance Mapper-Anurag-PC.fzz
Schematic
Windwows%20iot%20 %20ultrasonic%20distance%20mapper bb

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);
}
Improved Code (by Dave Glover)
Profile Ref: https://www.hackster.io/glovebox

Issues

RPi2 works on 3.3v while Arduino works on 5v. Thus voltage level conversion is needed. Schematic I've provided uses voltage divider to convert from 5v to 3.3v. It is better to use bi-directional logic level converter than voltage divider. It is more safer with the bi-directional logic level converter than voltage divider.
See all issues

Credits

Replications

Did you replicate this project? Share it!

I made one

Love this project? Think it could be improved? Tell us what you think!

Give feedback

Comments

Similar projects you might like

Arduino on Internal Oscillator Crystal as Clock Source
Intermediate
  • 670
  • 46

Protip

Want to make an Arduino having only an ATmega328 chip and nothing else? Not even the crystal oscillator!

Wireless Sensor Node
Intermediate
  • 14
  • 2

Work in progress

This project is a compact wireless sensor node that connects directly to a smart phone or tablet to display data from connected sensors.

CNC Controller in Python
Intermediate
  • 509
  • 8

Full instructions

First ever CNC machine controller implementation in pure Python.

Distance Measurement Vehicle via Websocket
Intermediate
  • 2,676
  • 21

Full instructions

A vehicle measures distance with an encoder on its wheel. It is remotely controlled and transmits the distance via Websocket.

Pi Zero Speaker - DIY Audio HAT and Audio Player
Intermediate
  • 385
  • 6

Work in progress

Convert an old speaker into something cool powered by Pi Zero.

Barbot: Cocktail Mixing Robot
Intermediate
  • 4,093
  • 29

Full instructions

Barbot is an open source Arduino cocktail mixing robot controlled with the hybrid mobile app via Bluetooth.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login