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.