GeoNomad
Created February 17, 2020 © GPL3+

Quadriplegic Infant Motion Sensing

Monitor infant motion to determine when he is asleep, awake or agitated. Trigger speech feedback to encourage intentional motion.

IntermediateWork in progress2 hours30

Things used in this project

Hardware components

ESP8266 ESP-12E
Espressif ESP8266 ESP-12E
×1
Proximity Sensor- Pyroelectric Infrared Sensor Module
KEMET Electronics Corporation Proximity Sensor- Pyroelectric Infrared Sensor Module
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

3D Printer (generic)
3D Printer (generic)

Story

Read more

Custom parts and enclosures

3D Lens for Kemet

Fits over SS-430 modules

Schematics

Connection Diagram

Code

Kemet_Logger.ino

Arduino
ESP-12E code to log Kemet Sensor Module data
/* https://benlo.com/esp8266/KemetSensor.html Logging program */ 

#include <ESP8266WiFi.h> 

const char* ssid = "YOURWIFI";      // your AP SSID
const char* password = "YOURPASSWORD"; 
const char* host = "yourhost.com";      // host with logging software
int sensor = 0; 
int sensorCount = 0;
unsigned long now = millis();
unsigned long lastCounter = 0;


ICACHE_RAM_ATTR void detectsMovement()   // interrupt routine for sensor output
  {
  sensorCount++;  
  digitalWrite(2, LOW);
  }

void setup() 
  { 
  pinMode(2, OUTPUT);   // LED tracks sensor
  pinMode(D2, INPUT);   // Kemet sensor output
  pinMode(16, OUTPUT);  // Wifi status LED

  // Set motionSensor pin as interrupt, assign interrupt function and set RISING mode
  attachInterrupt(digitalPinToInterrupt( D2 ), detectsMovement, RISING);  

  digitalWrite( 2 , HIGH);
  digitalWrite( 16, HIGH);

  WifiConnect();
  } 

bool WifiConnect()
  {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
    {
    delay(500);
    digitalWrite(16, !digitalRead(16) ); // blink status while connecting to AP
    }
  digitalWrite( 16, HIGH);  // turn off Wifi status LED
  return true;
  }

void loop() 
  { 
  digitalWrite( 2, !digitalRead(D2) );  // LED tracks sensor
  unsigned long now = millis();

  if ( now - lastCounter > 10000 )  // log sensor count every 10 seconds
    {
    lastCounter = now;
    if ( sensorCount )
      {
      LogValue( sensorCount );
      }
    }
  }

bool LogValue( int value )
  {
  sensorCount = 0;  // restart counting from zero
  
  if ( !value ) value = -1;  // avoids null value
  digitalWrite(16, LOW );
  if ( WiFi.status() != WL_CONNECTED ) WifiConnect();   // reconnect if WiFi dropped
  
  WiFiClient client;
  if (!client.connect(host, 80)) 
    {
    Serial.println("connection failed");
    return false;
    }
 
  client.print("GET /ESP8266/Log.php?sensor=Kemet001&count=");  // URL for logging software
  client.print(value);  // cannot be int 0 or creates 404 error due to malformed URL
  client.println(" HTTP/1.1");
  client.println("Host: benlo.com");
  client.println("Connection: close");
  client.println();
  
  unsigned long timeout = millis();
  while (client.available() == 0) 
    {
    if (millis() - timeout > 5000)
      { 
      Serial.println(">>> Client Timeout !");
      client.stop(); 
      digitalWrite(16, HIGH );
      return false; 
      } 
    } 
  while (client.available())
    { 
    String line = client.readStringUntil('\r'); // read reply from server
//    Serial.print(line);
    }
  client.stop(); 
  digitalWrite(16, HIGH );  // turn off WiFi status LED
  return true;
  }

Credits

GeoNomad

GeoNomad

1 project • 0 followers
A wandering inventor.

Comments