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

17796523 1518318691513285 4256250064588249581 n cpt00xjvia
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

An Arduino-Powered Easter Egg Printer
Intermediate
  • 1,206
  • 18

Have you started dyeing Easter eggs yet? We at ELEKS have created a smart Egg Printer powered by Arduino Uno R3.

DIGITAL BASCULE WITH ARDUINO UNO AND FSR SENSOR
Intermediate
  • 310
  • 1

Protip

The main goal is to make a practical digital bascule and using Arduino UNO board and FSR Sensor.

Automatic Fear 1.0
Intermediate
  • 279
  • 5

Full instructions

A device capable of frightening my sister and with compatibility with other members of the family

Arduino Addons : Battery Level Indicator
Intermediate
  • 1,738
  • 21

A RealTime Battery Indicator For Your Project Without Extra Components Or Using Any Analog I/Os

End-Effector and Control Logic for Robot
Intermediate
  • 3,026
  • 23

For my thesis, I have developed the control system and end-effector for a robot, easily implementable and economic.

Theremino Adapter for CNC.
Intermediate
  • 281
  • 7

Full instructions

Attention: This adapter is used to replace the parallel port with the USB, and not to operate Mach3 CNC or Linux.

ProjectsCommunitiesContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Respect project
Feedback