Project tutorial
Keep Me Clean

Keep Me Clean

A sensor That detects when a diaper needs changing.

  • 886 views
  • 1 comment
  • 1 respect

Components and supplies

About this project

A Methane Sensor attached to an Genuino mkr1000 sends notifications to Azure when poop (methane) is detected for a period of time.

Code

clientArduino
#include <SPI.h>
#include <WiFi101.h>

int sensorPin = A1;    // select the input pin for the potentiometer
int sensorValue = 0; 
int sentcounter = 0;
char ssid[] = "myssid"; //  your network SSID (name)
char pass[] = "mykey";    // your network password (use for WPA, or use as key for WEP)
int keyIndex = 0;            // your network key Index number (needed only for WEP)

int status = WL_IDLE_STATUS;
char server[] = "my.server.com";  
WiFiClient client;

void setup() {
  sentcounter = 0;
  //Initialize serial and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  // check for the presence of the shield:
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue:
    while (true);
  }

  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);

    // wait 10 seconds for connection:
    delay(10000);
  }
  Serial.println("Connected to wifi");
  printWifiStatus();
  
}

void loop() {

  
  sensorValue = analogRead(sensorPin);
  if(sensorValue<500){
    sentcounter = 0;
    
      Serial.print("Low: ");
      Serial.print(sensorValue);
      Serial.println();
  }
  else{
    Serial.print("Still up but no post ");
      Serial.print(sensorValue);
      Serial.println();
    sentcounter +=1;
    if (sentcounter == 10)
    {
      Serial.print("Post: ");
      Serial.print(sensorValue);
      Serial.println();
      postData();
      sentcounter = 0;
    }
    
  }
  delay(1000);
  
}


void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
}


void postData() {
  // Combine yourdatacolumn header (yourdata=) with the data recorded from your arduino
  // (yourarduinodata) and package them into the String yourdata which is what will be
  // sent in your POST request
  String yourdata = "poop=poop";

  // If there's a successful connection, send the HTTP POST request
  if (client.connect(server, 80)) {
    Serial.println("connecting...");

    // EDIT: The POST 'URL' to the location of your insert_mysql.php on your web-host
    client.println("POST /path/poop.php HTTP/1.1");

    // EDIT: 'Host' to match your domain
    client.println("Host: my.server.com");
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded;");
    client.print("Content-Length: ");
    client.println(yourdata.length());
    client.println();
    client.println(yourdata); 
  } 
  else {
    // If you couldn't make a connection:
    Serial.println("Connection failed");
    Serial.println("Disconnecting.");
    client.stop();
  }
}

Schematics

Device
12874480 10154016630492438 1013409150 o

Comments

Similar projects you might like

Keep the WiFi On

Project tutorial by Sameer

  • 7,150 views
  • 8 comments
  • 35 respects

Clean Water AI

Project tutorial by Team Clean Water AI

  • 9,721 views
  • 2 comments
  • 54 respects

Baby-Pram Monitoring System

Project tutorial by IP

  • 7,062 views
  • 4 comments
  • 13 respects

Safe City: A Device to Keep You Safe

Project tutorial by Patel Darshil

  • 6,678 views
  • 0 comments
  • 24 respects

The Angry Humidor (Humidor Monitor)

Project showcase by Randall Cole

  • 4,031 views
  • 1 comment
  • 17 respects

I Keep my Cucumber Growing Conditions Moist - Part 2

Project tutorial by Ingo Lohs

  • 2,201 views
  • 0 comments
  • 8 respects
Add projectSign up / Login