Keep Me Clean




A sensor That detects when a diaper needs changing.

Things used in this project

Hardware components

Arduino MKR1000
Arduino MKR1000
× 1

Story

Schematics

Code

client

Arduino

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

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

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

void setup() {
  sentcounter = ;
  //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 = ;
    
      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 = ;
    }
    
  }
  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();
  }
}
READ  BMP380 – Ultra-miniature pressure sensor

Source : Keep Me Clean




Leave a Comment

*
= 3 + 0

(Spamcheck Enabled)

Read previous post:
DIY Arduino mini laser engraver from a DVD player
DIY Arduino mini laser engraver from a DVD player

The YouTube channel DIY Builder has published and created a DIY Arduino laser engraver which is powered by an Arduino Nano development...

Close
Scroll to top