Tuesday, October 25, 2011

Xbee Proximity Trigger/Alarm Project. Overboard Alarm

This prototype lets me test the range of the Xbee under various conditions and provides the bones for many other uses of Xbee as a proximity trigger or alarm, as part of a smart system.
For this, smart lifejacket. The input sensors would most suitably be moisture sensors which turn the Xbee proximity scan on, on the remote unit. Actuators you would most likely use would be buzzers, LED's or other parts of a wider smart system.

Both units are running the same sketch as one another. This new sketch incorporates both send and receive sketches. Curiously, the Arduino Duemilanove with the 9V battery has a slightly less stable reception range than the 3.7V Seeeduino Stalker kit.
The range of this system is about 20meters strong signal and 50meters of disrupted signal. Less when line of sight is obscured.

The Seeeduino Stalker Waterproof Solar Kit is an excellent choice if you are looking to start using Xbee. No breakout boards or shields necessary and its already set up with a 3.7V lipo, mini solar panel and solar regulator.


To upload the sketch to Seeeduino Stalker you will need to use a UartBee and a mini USB cable, via the RX/TX pins (make sure you take off the Xbee while transferring the code onto the board);

RX/TX Coding Pins on Stalker;
  • USB5V - Draws 5V from computer, via USB, while attached
  • RXD - Receive Data
  • TXD - Transfer Data
  • GND - Ground the circuit
  • DTR - Data Transfer


The sketch below switches an LED on in pin 13 on when the Xbee's are in range and the sensor reading is above 200, but is otherwise the same as the code further up the page;

int sensorPin = A0;
int sensorValue = 0;

void setup(){
Serial.begin(9600);
pinMode(13,OUTPUT);
}

void loop(){
if (sensorValue > 200){
if(Serial.available() > 0){
digitalWrite(13,HIGH);
Serial.flush();
delay(100);
Serial.write('d');
Serial.flush();
delay(100);
}
}

else {
digitalWrite(13,LOW);
}
}


I revised the code when it was pointed out to me that in the permutation above everything turns on when the receivers are in range of each other. For this smart lifejacket example it would be more useful to swap that around. Also, I have added a speaker to the system as per my original concept;

/*this sketch is by seamus mccarthy 2011 using bits from examples and
online support communities.
It is meant to help people new to xbee to get started using it in your
own smart systems projects*/

int sensorPin = A0; //Sensor pin (moisture, light, pot etc)
int sensorValue = 0; //Sensor variable

void setup(){
Serial.begin(9600);
pinMode(13,OUTPUT); //LED pin
pinMode(6,OUTPUT); //add a pin for speaker tone
}

void loop(){
if (sensorValue > 200){ //if sensor value is above 200..
if(Serial.available() > 0){ //check if Serial data is available
digitalWrite(13,LOW); //Turn off LED
}

else {
digitalWrite(13,HIGH); //Turn on LED
tone(6, 440, 100); //play A4 note on pin 6 for 100 ms:
tone(6, 1760, 100); //play A6 note on pin 6 for 100 ms:
Serial.flush(); //flush
delay(100); //delay
Serial.write('d'); //send back serial to other unit
Serial.flush(); //flush
delay(100); //delay
}
}
}

You will have to create a new tab in Arduino for the tones. I have just used two here but you should get the idea;

// set pitches
#define NOTE_A4 440
#define NOTE_A6 1760
I have included diagrams and schematics for my system. Im not quite sure about the Xbee wiring because I used an Xbee Pro Shield and the Seeeduino Stalker which are set up nicely to run the Xbee. This is a good option for beginners as it will allow you to get set up fast.

For a tutorial of how to make your own PCB at home visit this link.

Xbee Project Contextual Statement

This blog is a document of my explorations of Xbee as an RF trigger. The purpose of the blog is to document my findings and help new users of Xbee, like me, to get started.
It started as a project to make a useful, marine smart system, for me to use on the boat over summer. Upon reflection I realized that my experiences and observations could be used by others so I decided to blow the project up and publish online for people to see.

I have tried to be as accurate, clear and concise as possible, giving examples and explanations for users to try.
I have made comparisons between different methods for using Xbee as an RF trigger and share my observations for others to use.

The name 'How to Use Xbee to Make a Proximity Alarm' and simple url, howtousexbee.blogspot.com, is purely to make the publication more searchable and accessible to more people.

I acknowledge that there are other methods of wireless communication that I have not examined. I seek only to add to the community of data online for inventors, hobby electricians and smart systems enthusiasts.

As well as being useful to hobbyists, inventors etc, I hope this blog can be used as a starting point for educators to help students learn about wireless electronics in smart systems.

Please write any alterations, comments, comparisons or useful links in the comment box below the related post. This will provide perspective and help create an ongoing dialogue for others to use.

Thanks

Saturday, October 22, 2011

Xbee as an RF Trigger - Main Findings and Observations

During my Xbee project I have made jumps in my own knowledge of simple radio communication and how to use the Xbee, series 1, as part of a system. I hope that this blog can be used to help beginner Smart Systems makers and hobby electricians to become better equipped to use Xbee or make choices as to the applicability of this tech for their own projects.

I dont count myself as an amazing user/maker of smart systems but enjoy tinkering away, making sensors sense, actuators actuate, or lights and buzzers whir into life.
In most examples on this blog you will still have to trouble shoot a bit when trying to use in your own systems. This is to be expected and must be met with patience. I hope this blog has helped.

The following is a list of my main findings. They are intended only as a guide and represent my opinion, based on what I have observed while using Xbee in this project.

Main findings and observations;
  • Xbee, series 1 is very dependent on line of sight for steady signal.
  • You can expect 20-25m strong signal range when sender and receiver units are in line of sight.
  • 60m+ can be expected with clear line of sight
  • Variable, 10-20m range likely when used inside. May be very useful for a RF trigger intended for single room proximity.
  • Components costs add up very quickly so you should seek advice so that you get the right components for your application.
  • Xbee runs happily on a 3V power supply
  • A 3.3 or 3.7V lipo is a good option for repeated use and rechargablity.
  • There are plenty of other options you could choose to use, such as wifi (e.g. wiFly), web feed, RFID.
  • Xbee is a good starting point for beginners who want to use wireless communication or control in their smart systems.

Should I use the Seeeduino Stalker, FIO or an Arduino Duemilanove with a Shield for Xbee?

The clear winner here is the Seeeduino Stalker, which is set up to house Xbee and has a built in solar regulator. This board is simple to use like Arduino Duemilanove and comes with all of the benefits of the Duemilanove except the USB programming capability.


Stalker Pros and Cons;
  • Built in Solar Regulator
  • Set up for 3.7V lipo
  • Good range 20-60+meters
  • Steady signal reception
  • RX/TX pins set up for Uart programming cable
  • Great entry level unit
  • Fairly slim
  • Comes with SD data logger
  • Is available with a waterproof solar kit for $60 inc p&p. Includes Stalker board, solar panel, 3.7V lipo, Uart, mini USB connector, SD card and waterproof housing.
  • ATmega328V microcontroller
  • Slightly more complicated to program than Duemilanove
  • Xbees are another $25 each and are sold separately.



Arduino Dumilanove with Xbee Pro Shield Pros and Cons;
  • Easily use multiple types of power source
  • Direct USB programming
  • Good range 20-55+meters
  • ATmega328V microcontroller
  • Is about $100 dollars for the shield and Duemilanove
  • Shield obscurs some pins on Duemilanove unnecessarily
  • Comparatively heavy and bulky to other options
  • Xbees are another $25 each and are sold separately

I had a look at another option as well. The FIO is mall and set up for Xbee. I didn't have much success with this but feel it makes a useful comparison to the others.

FIO Board Pros and Cons
  • Is only $25 for the FIO board
  • Light and small
  • 3V regulator
  • Set up for battery and Xbee
  • ATmega328V microcontroller
  • Can be difficult to program. RX/TX pins are confusing for beginners
  • Not as accessible for noob's as Dumilanove or Stalker
  • Not as many inputs/outputs available
  • Xbee's are another $25 each
  • I think i fried my one as it started smoking when i attached an external power source and nothing seems to working on it anymore.

Best across the board unit for entry level users of Xbee and people who want to get started quickly, is the Seeeduino Stalker. Hope this has been useful.

Servo Turns When RF Trigger is Tripped

This example shows how you could integrate an actuator with the original sender/receiver system.

To achieve this you will have to wire up a servo to ground, power and a control pin. Such as;
This fritzing diagram is from an old project of mine where we were controlling a servo from a switch via a web feed.

To integrate the Xbee with this system, using the proximity RF trigger instead of switch and web feed seemed an appropriate application for the Xbee trigger system. This could be useful in a number of situations such as an automatic garage door, which opens when you drive your car in range.

You will need to wire any extra components you are trying to integrate, into the breakout pins on the Xbee shield, in the same relative position as if you were plugging it straight into the pins on your Arduino.

To trigger the state of the servo with Xbee, the sender should remain as usual;

void setup(){
Serial.begin(9600);
}

void loop(){
Serial.write('d');
delay(100);
}


The receiver/actuator sketch will look something like this;

The possibilities for integration with your own systems are vast so I thought I'd go one step further, showing you how to add a sensor to the pictured sketch above. This will give the example system a new layer of complexity, adding new variables to test against and use in system function;

#include

Servo myservo;

int pos = 0;
int potpin = 0;
int val;

void setup(){
myservo.attach(9);
Serial.begin(9600);
pinMode(13,OUTPUT);
}

void loop(){
val = analogRead(potpin);
//val = map(val, 0, 1023, 0, 179);

if(Serial.available() > 0 && val > 500){
digitalWrite(13,HIGH);

for(pos = 0; pos < 180; pos += 1) { myservo.write(pos); delay(15); } for(pos = 180; pos>=1; pos-=1)
{
myservo.write(pos);
delay(15);
}
delay(500);
Serial.flush();
}
else {
digitalWrite(13,LOW);
//delay(1000);
}
}

Sensor Threshold Controlling Serial Data Sender

Suppose you only want the your remote unit in your smart system doing whatever it does when the sun is out. This could be for any reason, such as to only use power when the solar panel is charging the battery in the remote unit.

In this example I will quickly show you how you could achieve such a feat using a phototransistor and the sender/receiver system I mentioned in my second post.

Here goes;

int sensorPin = A0;
int sensorValue = 0;

void setup(){
Serial.begin(9600);
}

void loop(){
sensorValue = analogRead(sensorPin);

if (sensorValue > 200){
Serial.write('d');
delay(100);
}

}

You can see how easy it is to add layers of smarts to your system.

How to Use Xbee as an RF Trigger in Your Own Smart System

There are plenty of ways you can use this as part of a wider smart system. Add transponders and actuators to either side of the send/receive units.

The following are a few simple examples of how you
could use the Xbee as an RF trigger. Links are provided to each examples own blog post;
  • ....sensor which turns on the serial data feed in the sender sketch. Click Here

  • ....servo which performs a movement each time the trigger is tripped. Click Here

  • ....a sensor performs a scan when RF trigger is tripped. Click Here
I have published each example in a new post so that for ease of use. I hope this helps you get started quickly or help you decide for yourself whether Xbee is the right tool for what you are intending to build yourself.

Please comment on any posts you found particularly useful and provide links to your own Xbee, RF or Arduino work.

Accuracy Test 3 - Seeeduino Stalker and Solar Regulator Kit



Accuracy Test 2 - Xbee RF Trigger with Mobile Receiver - Outdoor Trials

The first Accuracy Test 1 revealed the expected signal interference by walls and doors. Not surprisingly the accuracy and strength of the signal becomes immediately unstable when you step outside of a room. I repeated the test This is not necessarily a problem but I decided to tweak the delay a bit in the receiver sketch* to smooth things out a bit before continuing on to outdoor trials;
Having discerned in Test 1 that line of sight is key to stable Xbee signal, one of the main things I hoped to learn in this test was whether the voltage of the power source played any significant part in strength and range. Also, I wanted to test range in an unobstructed environment. The following results were collected on my lawn with the Arduino/Xbee Shield/Xbee system powered by various mobile power supplies;

This test will be done using two Arduino Duemilanove units as in test 1. The sender unit will be plugged, via USB cable, into the computer and the other will be powered by a range of modular power sources.

The mobile receiver unit in the photo is using a 9V battery and has a servo attached to pin 9, which is triggered when the Xbee's come in range of one another. Read more about servo receiver.

The three mobile power sources I tested with are;
  • 3.7V single cell lipo
  • 6V battery pack made up of 4x1.5V AAA size batteries
  • Typical 9V battery
I was surprised to find very little difference in range between power sources but a much greater range and degree of accuracy, when unobstructed, than in Test 1. I assume that the steady, computer power source Im using to run the sender data sketch;
Following this trial I intend to try using the Xbee system with both send and receive units being powered modularly. Read more here.




*Editing the delay in the receiver sketch or adding an 'if' statement into the void loop could both be used to alter the rate at which the receiver unit looks for serial data from the sender or to integrate other components to your smart system. E.g;


#include

Servo myservo;

int pos = 0;
int potpin = 0;
int val;

void setup(){
myservo.attach(9);
Serial.begin(9600);
pinMode(13,OUTPUT);
}

void loop(){
val = analogRead(potpin);
//val = map(val, 0, 1023, 0, 179);

if(Serial.available() > 0 && val > 500){
digitalWrite(13,HIGH);

for(pos = 0; pos < 180; pos += 1) { myservo.write(pos); delay(15); } for(pos = 180; pos>=1; pos-=1)
{
myservo.write(pos);
delay(15);
}
delay(500);
Serial.flush();
}
else {
digitalWrite(13,LOW);
//delay(1000);
}
}




Thursday, October 20, 2011

Accuracy Test 1 - Indoor Trial Using USB Computer Power Supply

When I first wired my Xbee units together and uploaded the send/receive sketches I realized signal would be unstable due to a number of factors;
  • range of the Xbee
  • line of site and obstructions
  • type of power source
The first system I have rigged uses two Arduino Duemilanove, two Xbee shields and two xbee series 1's. Both units in this example are plugged in to computers via USB cable. The next trial will feature a mobile power source -probably a 3.7 V lipo. This will make the receiver unit modular and will give me an idea of performance difference between hardwired vs modular power sources for the Xbee.

My first trial was conducted in the computer lab at AUT in anything but controlled conditions;
  • Stable signal for about 6 meters. Aprox 1 room
  • Intermittent, fairly frequent signal for another 14-15 meters
  • My body being in the line of sight between devices made considerable difference to signal
  • Certain walls had greater impact on signal. The granite main pillars seem to block a lot of signal (who've thought).
  • Walking around with the Arduino plugged into computer is fairly unsuitable power source and will be restrictive in most applications.
  • Repeated tests under these conditions revealed very similar results;
Estimated range in indoor areas measured;
  • Computer Lab; 0-6m strong signal, 6m-18/20m fickle signal, 20m signal lost. Signal only constant when sender and reciever units are in the same room.
  • Studio; 0-12m strong signal, 10-12m+ very unstable, 20m signal lost. Signal only constant when sender and reciever units are in the same room. Immediate signal instability when receiver is carried out the door.
  • Home (Lounge); 0-10 meters strong signal through 1 wall layer, through 2 walls or 10m+ signal unstable, signal lost at aprox 22meters. Strong signal range varied greatly as I moved amongst rooms in my house. Glass lounge doors seemed to have little effect on signal strength.
  • Home (Room); 0-10 meters strong signal through 1 wall layer, through 2 walls or 10m+ signal unstable, signal lost at aprox 20meters. Strong signal range varied greatly as I moved amongst rooms in my house.
Line of sight seems to be a clear factor in the accuracy and range of my RF trigger system.

Notably, during this trial, I moved to the into the main studio where another student was working on an Xbee project. Whenever they were broadcasting serial data my receiver unit would switch on. This could be a problem if you were looking to trigger specific systems individually, wirelessly and within the same range. This is one potential downside to using Xbee for this application (RFID or wifi may be more appropriate for you if this is the case).

Make sure no one else is broadcasting serial data within range of your units or the receiver will be confused!!!

Tuesday, October 18, 2011

Serial Trigger using Arduino Duemilanove and Xbee

This blog details the first steps in creating an a proximity alarm/trigger using Xbee and a typical Arduino Duemilanove.
This blog is intended to help beginner/intermediate Smart Systems enthusiasts, like myself, to understand how to create a 'soft tether' system, which they can use as a tether, trigger or alarm in their own projects.
I chose to pursue Xbee radio communication as it is a widely available product with useful potential. There is a fair bit of info online about Xbee but a lot is very rooted in jargon which I found quite inaccessible for a noob such as myself.

For this example we will be programming one unit as a sender and one as a receiver. We are sending serial data via Xbee. The receiver unit will be constantly looking for that serial data and will switch between HIGH and LOW depending on whether any serial data is available.

Things you will need;
  • x2 Arduino Duemilanove (http://www.sparkfun.com/products/10175)
  • x2 Xbee shields (you can also use a breadboard to create your own breakout if you'd prefer)
  • x2 Xbee Series 1 (http://www.sparkfun.com/products/8664)
  • x2 USB to Arduino programming cable (http://www.seeedstudio.com/depot)
  • x1 LED to stick in pin 13 to show HIGH or LOW status of the system.
  • A portable power source for at least one of the Arduino's so that you can test the range of your system. A LiPo is probably the best bet at this stage but should really matter as long as the power supply is of suitable Voltage, 3-5V.

Each of the two units will look approximately like the images below when assembled;
For this very first trial I would attach each of the Arduino's to a computer to program the sketch onto the micro controller and to see that everything is running smoothly in the serial monitor and on the boards themselves.


Serial Sender Code;

void setup(){
Serial.begin(9600);
}


void loop(){
Serial.write('d')
delay(100);
}




    The data we are sending is a 'd' but this is completely inconsequential as the Receiver unit will be looking to see purely if there is any serial data available.
    To add complexity to your system there is the opportunity to add sensors and variables but it is a good idea to get this part of the system running smooth first, then go from there.






    Serial Receiver Code;

    void setup(){
    Serial.begin(9600);
    pinMode(13,OUTPUT);
    }

    void loop(){
    if(Serial.available() > 0){
    digitalWrite(13,HIGH);
    delay(100);
    Serial.flush();
    }
    else {
    digitalWrite(13,LOW);
    }
    }




    The statement in the void loop is saying ' if there is any serial data available then turn on pin 13 or else turn pin 13 off'. Serial.flush is included to refresh the system every loop that serial is available so that the availability of serial data is tested freshly each loop.

    This system will turn the LED in pin 13 on or off depending on whether the two units are in range of one another or if the sender has been switched off.

    At this stage the system is rudimentary RF communication but can be used as a building block for further projects. From here we are able to start adding layers of complexity to the sketch, hardware to the system or new functionalities.

    In the next post I will attach an external power source to my Arduino and attempt to measure the accuracy of the range of the Xbee in various conditions.

    Monday, October 10, 2011