smart dustbin using hcsr04

Dependencies:   HCSR04 TextLCD mbed-rtos mbed

Files at this revision

API Documentation at this revision

Comitter:
kumarlalit
Date:
Wed Apr 19 08:15:32 2017 +0000
Commit message:
smart dustbin using sim900a;

Changed in this revision

HCSR04.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-rtos.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 4273965739dc HCSR04.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR04.lib	Wed Apr 19 08:15:32 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/prabhuvd/code/HCSR04/#71da0dbf4400
diff -r 000000000000 -r 4273965739dc TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Wed Apr 19 08:15:32 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/simon/code/TextLCD/#308d188a2d3a
diff -r 000000000000 -r 4273965739dc main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Apr 19 08:15:32 2017 +0000
@@ -0,0 +1,194 @@
+#include "hcsr04.h"
+#include "TextLCD.h"
+#include "rtos.h"
+#include <string>
+
+DigitalOut myled(LED1);
+DigitalOut myled1(LED2);
+DigitalOut myled2(LED3);
+Serial pc(USBTX, USBRX);
+//TextLCD lcd(p21,p22,p23,p24,p25,p26);
+HCSR04  usensor(p15,p16);
+HCSR04  usensor1(p21,p22);
+HCSR04  usensor2(p23,p24);
+
+Serial SIM900(p13, p14);   //tx, rx SIM 900
+string result;
+char x;
+Thread thread;
+unsigned int dist;
+unsigned int dist1;
+unsigned int dist2;
+
+void clearString()
+ {
+  result.clear();
+  }
+ 
+void callback_rx() {
+ 
+    while (SIM900.readable()) {
+      x = SIM900.getc();
+      result += x;
+    pc.putc(x); // print the answer from SIM900
+ 
+       }
+}
+
+void sendSMS1()
+{
+ 
+clearString();
+  SIM900.printf("AT+CMGF=1\r\n"); //at command for send sms
+    wait_ms(1000);
+clearString();
+wait_ms(1000);
+SIM900.printf("AT+CMGS=");
+SIM900.putc('"');
+SIM900.printf("+919405204727");
+SIM900.putc('"');
+SIM900.printf("\r");
+SIM900.printf("\n");
+wait_ms(1000);
+SIM900.printf("Bin 1 is full");
+wait_ms(1000);
+SIM900.putc(0x1A);
+wait_ms(5000);
+}
+ 
+ void sendSMS2()
+{
+ 
+clearString();
+  SIM900.printf("AT+CMGF=1\r\n"); //at command for send sms
+    wait_ms(1000);
+clearString();
+wait_ms(1000);
+SIM900.printf("AT+CMGS=");
+SIM900.putc('"');
+SIM900.printf("+919405204727");
+SIM900.putc('"');
+SIM900.printf("\r");
+SIM900.printf("\n");
+wait_ms(1000);
+SIM900.printf("Bin 2 is full");
+wait_ms(1000);
+SIM900.putc(0x1A);
+wait_ms(5000);
+}
+ 
+ void sendSMS3()
+{
+ 
+clearString();
+  SIM900.printf("AT+CMGF=1\r\n"); //at command for send sms
+    wait_ms(1000);
+clearString();
+wait_ms(1000);
+SIM900.printf("AT+CMGS=");
+SIM900.putc('"');
+SIM900.printf("+919405204727");
+SIM900.putc('"');
+SIM900.printf("\r");
+SIM900.printf("\n");
+wait_ms(1000);
+SIM900.printf("Bin 3 is full");
+wait_ms(1000);
+SIM900.putc(0x1A);
+wait_ms(5000);
+}
+
+
+void led1_thread() {
+    while (true) {
+        wait_ms(10);
+sendSMS1();  // SEND SMS
+ wait_ms(10);
+ 
+        
+        Thread::wait(1000);
+    }
+}
+
+void led2_thread() {
+    while (true) {
+        wait_ms(10);
+sendSMS2();  // SEND SMS
+ wait_ms(100);
+ 
+        
+        Thread::wait(1000);
+    }
+}
+void led3_thread() {
+    while (true) {
+        wait_ms(10);
+sendSMS3();  // SEND SMS
+ wait_ms(100);
+ 
+        Thread::wait(1000);
+    }
+}
+
+
+int main()
+{
+ SIM900.attach(&callback_rx);
+SIM900.baud(9600); //
+wait_ms(100);
+ 
+    while(1) 
+      {
+        usensor.start();
+        usensor1.start();
+        usensor2.start();
+        wait_ms(500); 
+        dist=usensor.get_dist_cm();
+        dist1=usensor1.get_dist_cm();
+        dist2=usensor2.get_dist_cm();
+  //      lcd.locate(0,0);
+    //    lcd.printf("distance"); 
+        if(dist<20)
+        {
+        myled=1;
+        thread.start(led1_thread);
+      //  lcd.locate(0,0);
+       // lcd.printf("dist=cm:%ld\r\n",dist );
+        }
+        else
+        {
+        myled=0;
+       // lcd.printf("abnormal");
+        }
+        
+    if(dist1<20)
+        {
+        myled1=1;
+        thread.start(led2_thread);
+        //lcd.locate(0,0);
+        //lcd.printf("dist=cm:%ld\r\n",dist );
+        }
+        else
+        {
+        myled1=0;
+        
+        }
+        
+        if(dist2<20)
+        {
+        myled2=1;
+        thread.start(led3_thread);
+        //lcd.locate(0,0);
+        //lcd.printf("dist=cm:%ld\r\n",dist );
+        }
+        else
+        {
+        myled2=0;
+        //lcd.printf("abnormal");
+        }
+      }
+      
+
+
+
+}
\ No newline at end of file
diff -r 000000000000 -r 4273965739dc mbed-rtos.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-rtos.lib	Wed Apr 19 08:15:32 2017 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed-rtos/#58563e6cba1e
diff -r 000000000000 -r 4273965739dc mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Apr 19 08:15:32 2017 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/093f2bd7b9eb
\ No newline at end of file