Arnab Kumar Das
Published © CC BY

IOT Smart Dustbin using Arduino Nano and ESP8266

Tracking the amount of garbage inside the bins and thus can be easily geotagged and the dump vehicle can plan its path around the city.

BeginnerShowcase (no instructions)3 hours9,845
IOT Smart Dustbin using Arduino Nano and ESP8266

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
ESP8266 ESP-01
Espressif ESP8266 ESP-01
×1
Step-Up Voltage Regulator - 3.3V
SparkFun Step-Up Voltage Regulator - 3.3V
×1
9V battery (generic)
9V battery (generic)
×1
Plastics and Wood
×1
Ultrasonic Sensor - HC-SR04 (Generic)
Ultrasonic Sensor - HC-SR04 (Generic)
×1
Wire Cable - By the Foot
OpenBuilds Wire Cable - By the Foot
×1

Software apps and online services

Arduino IDE
Arduino IDE

Hand tools and fabrication machines

Bosch Drill
Bosch Screw Driver

Story

Read more

Code

Code snippet #1

Plain text
#include <NewPing.h>

#define TRIGGER_PIN 12 // Arduino pin tied to trigger pin on the ultrasonic sensor.
#define ECHO_PIN 11 // Arduino pin tied to echo pin on the ultrasonic sensor.
#define MAX_DISTANCE 50 // Maximum distance we want to ping for (in centimeters). Maximum sensor distance is rated at 400-500cm.

NewPing sonar(TRIGGER_PIN, ECHO_PIN, MAX_DISTANCE); // NewPing setup of pins and maximum distance.

//*-- IoT Information
#define SSID "CrazyEngineer"
#define PASS "www.ArnabKumarDas.com"
#define IP "184.106.153.149" // ThingSpeak IP Address: 184.106.153.149

// GET /update?key=[THINGSPEAK_KEY]&field1=[data 1]&field2=[data 2]...;
String GET = "GET /update?key=VYJGZSHIYR7SMTX9"; // You have to get your key from the website
int prev = 0;
void setup() {
Serial.begin( _baudrate );

sendDebug("AT");
delay(5000);

if (Serial.find("OK"))
{
debug.println("RECEIVED: OK\nData ready to sent!");
connectWiFi();
}

}

void loop()
{
int dat = sonar.ping_cm();
if (dat < 0 || dat > 37)
dat = prev;
String depth = String((37 - dat)); // turn integer to string
debug.print( "DEPTH = " );
debug.println(depth);
updateTS(depth);
delay(1000);
}
//----- update the Thingspeak string with 3 values
void updateTS( String T)
{
// ESP8266 Client
String cmd = "AT+CIPSTART=\"TCP\",\"";// Setup TCP connection
cmd += IP;
cmd += "\",80";
sendDebug(cmd);
delay(2000);
if ( Serial.find( "Error" ) )
{
debug.print( "RECEIVED: Error\nExit1" );
return;
}

cmd = GET + "&field1=" + T + "\r\n";
Serial.print( "AT+CIPSEND=" );
Serial.println( cmd.length() );
if (Serial.find( ">" ) )
{
debug.print(">");
debug.print(cmd);
Serial.print(cmd);
}
else
{
sendDebug( "AT+CIPCLOSE" );//close TCP connection
}
if ( Serial.find("OK") )
{
debug.println( "RECEIVED: OK" );
}
else
{
debug.println( "RECEIVED: Error\nExit2" );
}
}

void sendDebug(String cmd)
{
debug.print("SEND: ");
debug.println(cmd);
Serial.println(cmd);
}

boolean connectWiFi()
{
Serial.println("AT+CWMODE=1");//WiFi STA mode - if '3' it is both client and AP
delay(2000);
//Connect to Router with AT+CWJAP="SSID","Password";
// Check if connected with AT+CWJAP?
String cmd = "AT+CWJAP=\""; // Join accespoint
cmd += SSID;
cmd += "\",\"";
cmd += PASS;
cmd += "\"";
sendDebug(cmd);
delay(5000);
if (Serial.find("OK"))
{
debug.println("RECEIVED: OK");
return true;
}
else
{
debug.println("RECEIVED: Error");
return false;
}

cmd = "AT+CIPMUX=0";// Set Single connection
sendDebug( cmd );
if ( Serial.find( "Error") )
{
debug.print( "RECEIVED: Error" );
return false;
}
}

Github

https://github.com/arnabdasbwn/ESP8266-Arduino-Smart-Dustbin

Credits

Arnab Kumar Das

Arnab Kumar Das

6 projects • 79 followers
Maker 🔨- Crazy Engineer 🛠️- YouTuber 📹 Projects on Embedded S/W, Electronics, RC Vehicles, CNC, Mechatronics, DIY Projects, Woodworking

Comments