My Cart

How to Wirelessly Set a Password Using XBee Connectivity Kit

Difficulty Level: Intermediate -

1. Introduction

This tutorial allows the user to set a password key and if it is correct, a LED and a Buzzer will sound printing a message in the LCD.

Ingredients:

    - 1 x XBee Connectivity Kit:
    • 1x Platform
    • 2x XBee
    • 1x XBee Shield
    • 1x XBee gateway
    • 1x LCD
    • 2x LEDs
    • 2x 220Ω resistors
    • 1x Buzzer
    • 1x Potentiometer
    • 1x Breadboard
    • 1x Programming cable
    • Jumper Wires

Preparation Time: 30 minutes

Buy now
NOTE: Depending on the platform chosen to develop the project, the ingredients and the schematics shown in this tutorial can vary.

This project can be developed with Arduino or Intel Galileo. It is also compatible with Raspberry Pi using the Raspberry Pi to Arduino shields connection bridge.

For further information about the XBee Shield, consult the main tutorial.

Step 1: Connection

Connect the XBee shield to Arduino and then connect XBee module or you can connect it directly to Raspberry Pi connection bridge. Connect the LEDs with the resistors,the buzzer and the LCD with the potentiometer 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 the VCC supply (5V in Arduino and 3.3V in Raspberry Pi) and ground.

Connect left terminal of the potentiometer to VCC and the right terminal to GND. Connect the central leg of the potentiometer to the third pin of the LCD display. Follow the wire color diagram to connect all LCD pins.

Connect digital pin 10 and 11 to the longest leg of each LED. Place a resistor in the other leg of the LED and the remaining leg of the resistor to GND.

On the other hand you must connect a gateway with a XBee module to a PC.

Step 2: The Code

Arduino:

Code:
/*  
 *  XBEE Module 
 *  
 *  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. 
 *  a
 *  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 MartĂ­nez
 */
 
#include <LiquidCrystal.h>

#define RED 10
#define GREEN 11
#define BUZZER 9

char password[] = {"seattle"};

char buffer[100];
int i = 0;

LiquidCrystal lcd(12, 8, 6, 5, 4, 3);

void setup() {
  Serial.begin(9600);
  
  pinMode(RED,OUTPUT);
  pinMode(GREEN,OUTPUT);
  pinMode(BUZZER,OUTPUT);
  
  digitalWrite(RED,LOW);
  digitalWrite(GREEN,LOW);
  digitalWrite(BUZZER,LOW);
  
  memset(buffer,0,sizeof(buffer));
  
  lcd.begin(16, 2);
  lcd.print("Waiting Password");
  lcd.setCursor(0, 2);
  lcd.print("________________");  
}

void loop() {

   if (Serial.available()>0){
   while(Serial.available()>0){
    buffer[i] = Serial.read();
    i++;
    delay(5);
   }
   
   checkPassword();
   memset(buffer,0,sizeof(buffer));
   i=0;
}
 
}

byte checkPassword() {

byte z=0;
    while(buffer[z] !=0){
		z++;
	}
	
if (sizeof(password) == z-1){

for (int i=0;i<sizeof(password)-1;i++){
	
	if (buffer[i] == password[i]){
	
	}
	else{
		wrongPass();
		return 0;}
	
}
correctPass();
return 1;
}
else {wrongPass();}
}

void wrongPass(){
lcd.setCursor(0, 2);
lcd.print(" Wrong Password ");
digitalWrite(RED,HIGH);

digitalWrite(BUZZER,HIGH);
delay(1000);
digitalWrite(BUZZER,LOW);

digitalWrite(RED,LOW);

    
delay(1000);
lcd.setCursor(0, 2);
  lcd.print("________________"); 
   
}

void correctPass(){
lcd.setCursor(0, 2);
lcd.print("Correct Password");
digitalWrite(GREEN,HIGH);

digitalWrite(BUZZER,HIGH);
delay(200);
digitalWrite(BUZZER,LOW);
delay(200);
digitalWrite(BUZZER,HIGH);
delay(200);
digitalWrite(BUZZER,LOW);

delay(500);
digitalWrite(GREEN,LOW);


delay(1000); 
lcd.setCursor(0, 2);
  lcd.print("________________"); 
  
}
        

Raspberry Pi:

Code:
/*  
 *  XBEE Module 
 *  
 *  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. 
 *  a
 *  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 MartĂ­nez
 */
 
//Include arduPi library
#include "arduPi.h"

#define RED 10
#define GREEN 11
#define BUZZER 9

byte checkPassword();
void correctPass();
void wrongPass();

char password[] = {"seattle"};


char buffer[100];
int i = 0;


void setup() {
  Serial.begin(9600);
  
  pinMode(RED,OUTPUT);
  pinMode(GREEN,OUTPUT);
  pinMode(BUZZER,OUTPUT);
  
  digitalWrite(RED,LOW);
  digitalWrite(GREEN,LOW);
  digitalWrite(BUZZER,LOW);
  
  memset(buffer,0,sizeof(buffer));
  
}

void loop() {

   if (Serial.available()>0){
   while(Serial.available()>0){
    buffer[i] = Serial.read();
    i++;
    delay(5);
   }
   
   checkPassword();
   memset(buffer,0,sizeof(buffer));
   i=0;
}
 
}

byte checkPassword() {

byte z=0;
    while(buffer[z] !=0){
		z++;
	}
	
if (sizeof(password) == z-1){

for (int i=0;i<sizeof(password)-1;i++){
	
	if (buffer[i] == password[i]){
	
	}
	else{
		wrongPass();
		return 0;}
	
}
correctPass();
return 1;
}
else {wrongPass();}
}

void wrongPass(){
printf("Wrong password\n");
digitalWrite(RED,HIGH);

digitalWrite(BUZZER,HIGH);
delay(1000);
digitalWrite(BUZZER,LOW);

digitalWrite(RED,LOW);
}

void correctPass(){
printf("Correct password\n");	
digitalWrite(GREEN,HIGH);

digitalWrite(BUZZER,HIGH);
delay(200);
digitalWrite(BUZZER,LOW);
delay(200);
digitalWrite(BUZZER,HIGH);
delay(200);
digitalWrite(BUZZER,LOW);

delay(500);
digitalWrite(GREEN,LOW);
}

int main (){
    setup();
    while(1){
        loop();
    }
    return (0);
}


        

Intel Galileo:

Code:
/*  
 *  XBEE Module 
 *  
 *  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. 
 *  a
 *  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:    Jorge Casanova, Luis MartĂ­n
 */	

#include <LiquidCrystal.h>

#define RED 10
#define GREEN 11
#define BUZZER 9

char password[] = {"seattle"};

char buffer[100];
int i = 0;

LiquidCrystal lcd(12, 8, 6, 5, 4, 3);

void setup() {
  
  lcd.begin(16, 2);
  lcd.print("Waiting Password");
  lcd.setCursor(0, 2);
  lcd.print("________________");
  
  Serial.begin(9600);
  Serial1.begin(9600);
  
  pinMode(RED,OUTPUT);
  pinMode(GREEN,OUTPUT);
  pinMode(BUZZER,OUTPUT);
  
  digitalWrite(RED,LOW);
  digitalWrite(GREEN,LOW);
  digitalWrite(BUZZER,LOW);
  
  memset(buffer,0,sizeof(buffer));
  
}

void loop() {

   if (Serial1.available()>0){
   while(Serial1.available()>0){
    buffer[i] = Serial1.read();
    Serial.print(buffer[i]);
    i++;
    delay(5);
   }
   
   checkPassword();
   memset(buffer,0,sizeof(buffer));
   i=0;
}
 
}

byte checkPassword() {

byte z=0;
    while(buffer[z] !=0){
		z++;
	}
	
if (sizeof(password) == z-1){

for (int i=0;i<sizeof(password)-1;i++){
	
	if (buffer[i] == password[i]){
	
	}
	else{
		wrongPass();
		return 0;}
	
}
correctPass();
return 1;
}
else {wrongPass();}
}

void wrongPass(){
lcd.setCursor(0, 2);
lcd.print(" Wrong Password ");
digitalWrite(RED,HIGH);

digitalWrite(BUZZER,HIGH);
delay(1000);
digitalWrite(BUZZER,LOW);

digitalWrite(RED,LOW);

    
delay(1000);
lcd.setCursor(0, 2);
  lcd.print("________________"); 
   
}

void correctPass(){
lcd.setCursor(0, 2);
lcd.print("Correct Password");
digitalWrite(GREEN,HIGH);

digitalWrite(BUZZER,HIGH);
delay(200);
digitalWrite(BUZZER,LOW);
delay(200);
digitalWrite(BUZZER,HIGH);
delay(200);
digitalWrite(BUZZER,LOW);

delay(500);
digitalWrite(GREEN,LOW);


delay(1000); 
lcd.setCursor(0, 2);
  lcd.print("________________"); 
  
}			
		

Links and Documentation

Related Tutorials

Datasheets and Manuals



If you are interested in Internet of Things (IoT) or M2M projects check our open source sensor platform Waspmote which counts with more than 100 sensors available to use 'off the shelf', a complete API with hundreds of ready to use codes and a low consumption mode of just 0.7µA to ensure years of battery life.

Know more at:

Get the Starter Kits at: