The idea of this project is to monitor the garbage level of your home or society's waste bin remotely using IoT technologies. So, this avoids the overflow of the bin by timely informing to your local waste collection authorities.
Here to demonstrate the project I made the prototype using Netduino 3 WiFi development board and the ultrasonic sensor for hardware build and connected device to ClickSend Cloud SMS service via the Internet. So, this enables to send SMS alert to any mobile phone number without the need for a dedicated SIM card anywhere in the world.
Setting up a Development EnvironmentVisit the Link-> http://developer.wildernesslabs.co/Netduino/About/Downloads/
to download various software under Development Environment and follow the sequence mentioned on the link during installation.
For Windows user
- Visual Studio 2015.
- .NET Micro Framework (.NETMF) v4.3.2 - QFE2 SDK
- .NETMF Plugin for: Visual Studio 2015
- Netduino SDK
You will have to signup first on Wilderness Labs developer site to download .NETMF Plugin and Netduino SDK. For Mac follow steps as given on site.
From here we can proceed to write our first sample test code for testing. Follow steps as shown in the video below to create your first application. You can copy code of Blinky file from the code section below to program.cs
You can also follow steps mentioned on link which is another way of creating application : http://developer.wildernesslabs.co/Netduino/Getting_Started/
Only things you need to remember is setting .NET Micro Framework 4.3 as target framework and reference must contain -> Microsoft.Spot.Hardware, SecretLabs.NETMF.Hardware and SecretLabs.NETMF.Hardware.Netduino
Otherwise you will get an error as shown below, red underlines.
This happens when you go by creating a console application. Because by default it won't add reference needed for Netduino. So, you have to add manually. If you follow by creating Netduino Application, then by default it takes those files in references.
I have shown both because we need to follow this procedure for further section explained next. Especially how to add references for various needs.
Configure WiFi Setting of Netduino 3 WifiTo begin with configuration you need NetduinoDeploy and STM32 driver if not already installed by visiting same download link under Firmware Updater and Configuration Tool.
Below is the screenshot of the device manager in a different mode of Netduino board
To put Netduino in DFU mode you need to press switch available on board then plug USB power cable keeping button pressed and after this release.
Once done then start NetduinoDeploy.WPF.exe and first update the firmware of Netduino to latest one. Then proceed with adding WiFi setting according to your router.
Adding WiFi Network setting, for my router, it is WPA2 and 128bit key encryption. Check for your router vendor's site to get that information. Below is screenshot gives you idea->
Note: If you stuck with any problem while performing firmware update or WiFi settings because I faced some difficulties and finally resolved with the help on the forum. So you can post any difficulties on the forum or comment below -> https://community.wildernesslabs.co/t/how-to-connect-the-netduino3-to-the-wifi/634/36
Interfacing Ultrasonic SensorHere I am using HC-SR04 ultrasonic sensor to detect the fill level inside Bin. Make connection as shown.
After this create test application and copy code of UltrasonicSensorTest from code section. Code is simple self explanatory with comments if still facing issue comment below.
Visit https://www.clicksend.com/in/ and signup to create your account on ClickSend Cloud SMS gateway service. For trial service provides you with some initial balance.
Once done, then login to view Dashboard where you will get credential needed to use service. Click on API Credential to copy your Username and API key. Shown in the below images
This service supports different protocols(Rest, HTTP, SMTP, SMPP, and FTP). Detail documentation is available on link https://developers.clicksend.com/docs/
For this project, I am using HTTP/ HTTPS protocol whose documentation is available on link https://clicksendhttpapiv2.docs.apiary.io/#reference/sms/send-an-sms
On the above link of HTTP protocol documentation, you will find testing method and trial numbers. You can use these numbers without any charges. Below is some test which you can try out. Simply your browser needed to perform these tests.
With testing Number, replace username and key with your
https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=+61411111111&message=hello
Response Received:
With real number,
https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=+917955555555&message=Hello%20Netduino
Response Received:
Here I will show how to make HTTP/HTTPS calls using Netduino and try the same example shown in the above section to call ClickSend API with Netduino instead of a browser.
You can get sample code available on Link- http://developer.wildernesslabs.co/Netduino/Input_Output/Network/
which show how Netduino connects to the network, then gets IPAddress and finally makes the simple HTTP request to google.com
Let's create HTTP Request application
I copied the same code but got errors, as shown below.
Errors pointed in the red box. Also look at the marked reference section because here we have to add references to removed those errors.
Simple just right click on References then click on add reference, next select particular reference and click on OK. We need to Add two references System.Http(related to HttpWebRequest,WebRequest and HttpWebResponse) and System.IO(related to StreamReader)
Now, look at below image all errors removed successfully.
compile issue resolved but faced another issue during runtime after deploying code into the board with the following error(Error: ff000000) shown below. Reason marked with an amber colored box.
So, required changes in code is
bool _IsRunning;
public bool IsRunning
{
get { return _IsRunning; }
set { _IsRunning = value; }
}
I have uploaded the test code (httprequesttest code) with correction so download from code section below and try out. Just make changes to comment and check both conditions of ClickSend API call with the test number and real number.
if (goodToGo)
{
MakeWebRequest("http://google.com");
//MakeWebRequest("https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=+61411111111&message=hello");
//MakeWebRequest("https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=+YOURNUMBERWITHCOUNTRYCODE&message=hello");
}
Response received for both conditions shown below
Let's now proceed to create a final application to test the actual project idea. Create a new SmartBin application and then copy SmartBin final code from code section.
I have added comments to understand the need of various namespace for the application. Also, do not forget to add references System.Http and System.IO
using System; //for nativeeventhandler
using System.IO; //for StreamReader methods
using System.Net; //for httpwebrequest and ipaddress methods
using System.Threading; //for Thread method
using Microsoft.SPOT; //for Debug.Print methods
using Microsoft.SPOT.Hardware; //for OutPort,InterrupPort,etc
using SecretLabs.NETMF.Hardware.Netduino; //for netduino hardware methods e.g Pins
using Microsoft.SPOT.Net.NetworkInformation;//for networkinterface and related methods
To final code, I have change MakeWebRequest() method of class App from protected to public
public void MakeWebRequest(string url)
so that it is accessible from the Main method of Program class, as shown below
app.MakeWebRequest("https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=+61411111111&message=Please%20Empty%20WasteBin");
The working logic of code shown below:
HC_SR04 mUS = new HC_SR04(Pins.GPIO_PIN_D4, Pins.GPIO_PIN_D5);
long initialLevel;
initialLevel = mUS.Ping();
byte cnt = 1;
Debug.Print("Empty BinLevel: " + mUS.Ping().ToString() + "mm");
long currentLevel;
float fillPercent;
while (true)
{
fillPercent = initialLevel - currentLevel;
Debug.Print("Fill percentage of Bin is " + fillPercent.ToString() + "%");
if (fillPercent > 80)
{
if (cnt == 2)
{
Debug.Print("More than 80% Full");
Thread.Sleep(100);
//replace with your ClickSend API credential and mobile phone number
//app.MakeWebRequest("https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=+61411111111&message=Please%20Empty%20WasteBin");
app.MakeWebRequest("https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=YOUNUMBERWITHCOUNTRYCODE&message=Please%20Empty%20WasteBin");
cnt = 0;
}
}
if (fillPercent > 50)
{
if (cnt == 1)
{
Debug.Print("More than 50% Full");
Thread.Sleep(100);
//replace with your ClickSend API credential and mobile phone number
//app.MakeWebRequest("https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=+61411111111&message=WasteBin%20is%20Half%20Filled");
app.MakeWebRequest("https://api-mapper.clicksend.com/http/v2/send.php?method=http&username=YOURUSERNAME&key=YOURAPIKEY&to=YOUNUMBERWITHCOUNTRYCODE&message=WasteBin%20is%20Half%20Filled");
cnt = 2;
}
}
if (fillPercent < 10)
{
Debug.Print("Emptied!");
cnt = 1;
}
Thread.Sleep(5000);
}
When the device is power on it connects to the network and then it first measures initial empty bin level. After which it will keep on measuring the current calculated distance which goes on reducing with an increase in waste level. Using those data fill level is calculated in percentage.
Once the fill percentage cross margin of 50% then the first alert is sent via SMS and final alert sent when level is more than 80%. The process will be repeated once the bin is Emptied.
PackagingSome packaging highlights which you could try out.
Other Possible Applications of Project:
- To measure Container Oil Level
- To measure Water Level Of Tank
- To Measure Chemical Level
Thanks!
Comments