Things used in this project

Hardware components:
Abx00004 iso both
Arduino MKR1000 & Genuino MKR1000
×1
HC-SR04 Ultrasonic Sensor
×1
Software apps and online services:
Vs2015logo
Microsoft Visual Studio 2015
DasData - cloud channel

Schematics

face_detection.pdf

Code

aRest - DistanceC/C++
/*
 * 
  Face detectino - gets distance from HC-SR04 Sensor using
  aREST Library for the Arduino/Genuino MKR1000 board. 
  Written in 2016 by Marco Schwartz under a GPL license.
*/

// Import required libraries
#include <SPI.h>
#include <WiFi101.h>
#include <aREST.h>
#define echoPin A0 // Echo pin A0
#define trigPin A1 // Trigger pin A1

long duration ; // duration to calculate distance
int HR_dist = 0; // Calculated distance

int minimumRange=5; //Min Sonar range
int maximumRange=200; //Max Sonar range

// Status
int status = WL_IDLE_STATUS;
 
// Create aREST instance
aREST rest = aREST();

// WiFi parameters
char ssid[] = "DASDATA";
char password[] = "WIFI_PASSWORD";

// The port to listen for incoming TCP connections
#define LISTEN_PORT           80

// Create an instance of the server
WiFiServer server(LISTEN_PORT);

// Declare functions to be exposed to the API
int ledControl(String command);

void setup(void)
{
  // Start Serial
//  Serial.begin(115200); 
 pinMode(trigPin, OUTPUT);
 pinMode(echoPin, INPUT);
  // Init variables and expose them to REST API

  // Function to be exposed
  rest.function("led",ledControl);

  // Give name and ID to device
  rest.set_id("1");
  rest.set_name("dasX");

  // Connect to WiFi
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    status = WiFi.begin(ssid, password);

    // Wait 10 seconds for connection:
    delay(5000);
  }
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");
 
  // Print the IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip); 

  rest.variable("Distance",&HR_dist );
  
}

void loop() {
  getDistance();
  // Handle REST calls
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  while(!client.available()){
    delay(1);
  }
  rest.handle(client);
  
}

void getDistance() {
  digitalWrite(trigPin,LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin,HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin,LOW);

  duration = pulseIn(echoPin,HIGH);
  //calculate distance
  HR_dist = duration/58.2;

  if (HR_dist >= maximumRange || HR_dist <= minimumRange) {
    //Serial.println("0");
    }
    else {
  Serial.println(HR_dist); 
      }

      delay(100);
  }

// Custom function accessible by the API
int ledControl(String command) {

  // Get state from command
  int state = command.toInt();

  digitalWrite(6,state);
  return 1;
}
DasCognitive services
Visual Studio - project

Credits

Img 0168
Marius Dima

interested in data exploration and finding innovative solutions to help enterprises.

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

Flightduino 101
Intermediate
  • 206
  • 7

Full instructions

A drone project that uses the Neural Pattern Recognition Module and other aspects of the Curie Module to advantage for creating a cool drone

Solar Smart Greenhouse Using Vertical Aquaponic Towers
Intermediate
  • 2,429
  • 36

Work in progress

Feed your family with 22 sqm greenhousing by combining permaculture, aquaponic vertical towers and IoT.

Arduino 101 BLE App
Intermediate
  • 1,550
  • 21

Work in progress

I want to show you how to make an application and connect it with the Arduino 101 platform for Internet of things applications.

Bluetooth smart home
Intermediate
  • 261
  • 5

Full instructions

A concept showing smart home control and automation with Arduino 101, accompanied by a custom Android application.

Measure wind speed with Eltako windsensor and Win10 IoT Core
Intermediate
  • 28
  • 1

Full instructions

This Project will help you track wind Speeds using Windows 10 IoT Core and the Eltako Windsensor.

FM radio
Intermediate
  • 7,568
  • 33

Full instructions

Build a great sounding FM radio with a cool display using an Arduino Nano and the Sparkfun Si4703 FM tuner breakout

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback