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

Dasdata i4zi6jkmzv
Marius Dima

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

Contact

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

Self Balancing Robot Using Mpu6050 Accelerometer
Intermediate
  • 46
  • 5

Protip

this is self balancing robot on two wheels using mpu6050 accelerometer based on arduino..

Arduino on Internal Oscillator Crystal as Clock Source
Intermediate
  • 968
  • 72

Protip

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

Dancing Autobot
Intermediate
  • 41
  • 3

Protip

this is our project..and new thats called autobot with dancing like michael jackson....

Tweeting Garden Assistant
Intermediate
  • 113
  • 2

Full instructions

This project, titled Plant Monitoring Assistant, aims to help its users monitor their beloved plants.

Barbot: Cocktail Mixing Robot
Intermediate
  • 5,402
  • 37

Full instructions

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

Distance Measurement Vehicle via Websocket
Intermediate
  • 4,640
  • 32

Full instructions

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

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login