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.

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

Pulse Train HAT for Raspberry Pi Mecanum Bot Example
Intermediate
  • 1,178
  • 18

Full instructions

With this example, we show how to use the PTHAT and wireless Xbox controller to control a Mecanum Bot.

Voice Controled Click Lamps
Intermediate
  • 33
  • 2

Work in progress

We have a couple of floor lamps from Ikea. They have two lights in each, and a switch for each light. Let's control them remotely.

MicroPython to Python via SigFox and Azure IoT Hub
Intermediate
  • 218
  • 4

Protip

This is to show how to get messages from a SiPy to your computer via SigFox and Azure IoT Hub.

Smart Garden
Intermediate
  • 1,915
  • 17

Smart Garden is a plant environmental monitoring system.

Both Physical & Cloud Cayenne Lights Switch
Intermediate
  • 108
  • 2

The cloud switches are well known, but what happens when the local internet fails and the switch cannot connect to the internet?

IoT Thermometer Using Python
Intermediate
  • 700
  • 8

Full instructions

How to develop a simple, but powerful, IoT thermometer using a Zerynth-powered single-board MCU and the Zerynth App.

ProjectsCommunitiesTopicsContestsLiveAppsBetaFree StoreBlogAdd projectSign up / Login
Feedback