phpoc_man
Published © LGPL

Monitoring the Fill Height of Paper Shredder

When paper shredder is filled by paper trash, Arduino notifies someone via Gmail that the trash bin is full and it should be taken out.

BeginnerShowcase (no instructions)3 hours2,833
Monitoring the Fill Height of Paper Shredder

Things used in this project

Story

Read more

Schematics

Assembly

Assembly
1. Stack PHPoC Shield on Arduino
2. Connect LAN cable or USB wifi Dongle to the shield for Ethernet
3. Pin wiring between Arduino and Sensor.

Pin wiring between Arduino and Sensor

All system

Code

Source Code

Arduino
You only need to replace your Gmail account's information

To get Gmail library, visit here https://create.arduino.cc/projecthub/phpoc_man/gmail-arduino-uno-ipv6-01ecc0?ref=user&ref_id=160147&offset=3
#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;
	}
}

Credits

phpoc_man

phpoc_man

62 projects • 405 followers

Comments