Click image for larger version  Name:	arduino_fullness_cover_img.jpg Views:	122 Size:	60.8 KB ID:	602

When Paper Shredder is fulfilled by paper trash, Arduino notifies someone via Gmail that paper trash is full and it should be taken out.

In this tutorial, I am going to show you how to detect the fullness of Paper Shredder and send a notification via Gmail using Arduino Uno.

I made this tutorial for beginners! It is really easy!!!

Let's get started!

Demonstration




Detecting the Fullness of Paper Shredder

Ultrasonic Sensor - HC-SR04 is used to detect the fullness of Paper Shredder. When the distance between sensor and paper trash is below a threshold, Paper Shredder is considered to be full.


Handling Event

In this project, when an event occurs, a notification is sent via Gmail.

Click image for larger version  Name:	arduino_fullness_gmail.png Views:	82 Size:	33.4 KB ID:	603


Thing used in this projectsClick image for larger version  Name:	arduino_fullness_things.JPG Views:	90 Size:	52.8 KB ID:	604


Assembly

1. Stack PHPoC Shield on Arduino
2. Connect LAN cable or USB wifi Dongle to the shield for Ethernet

Click image for larger version  Name:	arduino_fullness_assembly.JPG Views:	84 Size:	48.9 KB ID:	605

3. Wiring Diagram between Arduino and Sensor.

Click image for larger version  Name:	arduino_fullness_wiring.PNG Views:	117 Size:	69.3 KB ID:	606

Arduino Source Code

Code:
#define PIN_TRIG 5
#define PIN_ECHO 6
#define BIN_HEIGHT 20 // maximum containable height of bin in centimeters

#include "SPI.h"
#include "Phpoc.h"

long ultrasonicGetDistance();
boolean dustbinSendGmail();

PhpocEmail email;
boolean isSent = false;

void setup() {
 Serial.begin(9600);
 while(!Serial)
 ;
 pinMode(PIN_TRIG, OUTPUT);
 pinMode(PIN_ECHO, INPUT);

 Phpoc.begin(PF_LOG_SPI | PF_LOG_NET | PF_LOG_APP);

}

void loop() {
 long distance = 0;
 // read 10 time and get average value to eliminate noises
 for(int i = 0; i < 100; i++)
 {
  long temp = 0;
  do
  {
   temp = ultrasonicGetDistance();
  }
  while(temp > BIN_HEIGHT);

  distance += temp;
  delay(10);
 }
 distance /= 100;

 Serial.print(distance);
 Serial.println(" cm");

 if(distance <= 5)
 {
  if(!isSent)
  {
   Serial.println("Dustbin is almost full");
   isSent = dustbinSendGmail();
  }
 }
 else if(isSent && distance > 8) // avoid send alot of email when the distance is oscillated around 5cm
  isSent = false;

 delay(500);
}

long ultrasonicGetDistance(){
 long duration, distance;
 digitalWrite(PIN_TRIG, LOW);
 delayMicroseconds(2);
 digitalWrite(PIN_TRIG, HIGH);
 delayMicroseconds(10);
 digitalWrite(PIN_TRIG, LOW);
 duration = pulseIn(PIN_ECHO, HIGH);
 distance = (duration/2) / 29.1;
 return distance;
}

boolean dustbinSendGmail(){
 // setup outgoing relay server - gmail.com
 email.setOutgoingServer("smtp.gmail.com", 587);
 email.setOutgoingLogin("your_login_id", "your_login_password");

 // setup From/To/Subject
 email.setFrom("from_email_address", "from_user_name");
 email.setTo("to_email_address", "to_user_name");

 email.setSubject("Your dustbin is almost full");

 // write email message
 email.beginMessage();
 email.println("Location: Planet Earth.");
 email.println("");
 email.println("Your dustbin is almost full.");
 email.println("");
 email.println("Prepare to through it out.");

 email.endMessage();

 // send email
 if(email.send() > 0)
 {
  Serial.println("Email send ok");
  return true;
 }
 else
 {
  Serial.println("Email send failed");
  return false;
 }
}