My Cart

How to Monitor your Bin with a Buzzer Using Waspmote Starter Kit

Difficulty Level: Intermediate -

1. Introduction

This tutorial allows the user to know if the bin of your work is full and informs you with the buzzer making a beep. Waspmote uses RTC to take the hour and filter working hours and excluding evening and weekends. It also sends all the read data via XBee to a PC with a XBee gateway.

Ingredients:

  • 1 x Waspmote Starter Kit:
    • 1x Waspmote 802.15.4 uFL
    • 1x Waspmote Gateway 802.15.4 uFL
    • 1x 2300 mAh LiPo Battery
    • 1x miniUSB Cable
  • 1 x Starter Kit:
    • 1x LDR
    • 1x 220Ω resistors
    • 1x Buzzer
    • 1x Breadboard
    • 1x Programming cable
    • Jumper Wires

Preparation Time: 30 minutes

Buy now

For further information about Waspmote, consult the main tutorial.

Step 1: Connection

Connect the LDR with the resistor and the temperature sensor in the breadboard as you can see in the next diagram.

Connect two wires, red and black, to the two long rows on the side of the breadboard to provide access to 3.3V in and ground.

Connect digital pin 1 to the positive terminal of the buzzer and the other leg to GND.

Connect one leg of the light sensor to 3.3V and the other to Analog 1 and also to a 220 Ohm resistor. The other leg of the resistor has to be connected to GND. This structure is called "voltage divider".

Finally connect the XBee in the correct socket as you can see in the diagram and plug the XBee gateway in your PC.

Step 2: The Code

Waspmote:

Code:
/*  
 *  Waspmote Starter Kit
 *  
 *  Copyright (C) Libelium Comunicaciones Distribuidas S.L. 
 *  http://www.libelium.com 
 *  
 *  This program is free software: you can redistribute it and/or modify 
 *  it under the terms of the GNU General Public License as published by 
 *  the Free Software Foundation, either version 3 of the License, or 
 *  (at your option) any later version. 
 *  
 *  This program is distributed in the hope that it will be useful, 
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License 
 *  along with this program.  If not, see http://www.gnu.org/licenses/. 
 *  
 *  Version:           1.0
 *  Design:            David GascĂłn 
 *  Implementation:    Marcos Martinez & Victor Boria
 */
 
#include <WaspXBee802.h>

////////////////////////////////////////////////
// XBee Parameters
////////////////////////////////////////////////

// Destination MAC address
char* MAC_ADDRESS="0013A200400A3451";

packetXBee* packet; 
char pac[200];

////////////////////////////////////////////////
// Light parameters
////////////////////////////////////////////////
int light = 0;

//You can adjust this value according to your office light level
#define lightThreshold 50

void setup() {
	
  ////////////////////////////////////////////////
  // 0. Initialization
  ////////////////////////////////////////////////
  
  // 0.1 USB port for debugging
  USB.ON();
  USB.println(F("Welcome to Bin Checker"));
  delay(100);
  
  // 0.2 Sending init XBee message
  snprintf(pac,sizeof(pac),"Welcome to Bin Checker\n");
  sendXbee(pac);
  
  // 0.3 Turn ON xbee802
  xbee802.ON();

  // 0.4 Turn ON RTC
  RTC.ON(); 
  // Setting time [yy:mm:dd:dow:hh:mm:ss]
  // dow = day of the week
  // Sunday = 01, Monday = 02, Tuesday = 03 ...
  RTC.setTime("15:05:04:02:09:00:00");
  
  ////////////////////////////////////////////////
  // 1. Digital pins configuration
  ////////////////////////////////////////////////
  
  pinMode(ANALOG1,INPUT);  //LDR
  pinMode(DIGITAL1,OUTPUT);  //BUZZER
  
}


void loop() {

  ////////////////////////////////////////////////
  // 2. Checking LDR level
  ////////////////////////////////////////////////
  
  // 2.1 USB debugging
  USB.println(RTC.getTime());
  
  // 2.1 Checking bin level
  checkBin();
  delay(1000);

}

////////////////////////////////////////////////
// Check bin level function
////////////////////////////////////////////////

void checkBin(){

  // Turn ON 3V3 voltage
  PWR.setSensorPower(SENS_3V3,SENS_ON);
  delay(500);

  // Filter working hours excluding evenings and weekends
  if (RTC.hour > 8 && RTC.hour < 19 && RTC.day !=7 && RTC.day !=1){    

	// Take light measure  
    light = analogRead(ANALOG1);
    
    // USB debugging
    USB.print("light value: ");
    USB.println(light);
    
	// Sending data via XBee  
    snprintf(pac,sizeof(pac),"light value: %i\n",light);
    sendXbee(pac);
    
    // Light measure comparation
    if (light < lightThreshold){

      // USB debugging
      USB.println("Please empty your bin");
      
      // Sending data via XBee  
      snprintf(pac,sizeof(pac),"Please empty your bin\n");
      sendXbee(pac);

      //Buzzer only will sound once an hour
      if (RTC.minute == 00 && RTC.second == 00){
        digitalWrite(DIGITAL1,HIGH);
        delay(500);
        digitalWrite(DIGITAL1,LOW);
        delay(500);
        digitalWrite(DIGITAL1,HIGH);
        delay(500);
        digitalWrite(DIGITAL1,LOW);
      }

    }
    else{
		
      // USB debugging 
      USB.println("Your bin level is OK!");
      
      // Sending data via XBee   
      snprintf(pac,sizeof(pac),"Your bin level is OK!\n");
      sendXbee(pac);
    }

  }

  else{
	  
    // USB debugging	  
    USB.println("Out of the office");

    // Sending data via XBee    
    snprintf(pac,sizeof(pac),"Out of the office\n");
    sendXbee(pac);
  }

  // Turn OFF 3V3 voltage
  PWR.setSensorPower(SENS_3V3,SENS_OFF);	


}

////////////////////////////////////////////////
// Send XBee function
////////////////////////////////////////////////

void sendXbee(char* str){

  // Memory allocation
  packet=(packetXBee*) calloc(1,sizeof(packetXBee)); 
  
  // Choose transmission mode: UNICAST or BROADCAST
  packet->mode=BROADCAST; 
  
  // set destination XBee parameters to packet
  xbee802.setDestinationParams( packet, MAC_ADDRESS, str, MAC_TYPE);
  
  // send XBee packet
  xbee802.sendXBee(packet);
  
  // free variables
  free(packet);
  packet=NULL;
  
}