Have a Question?

Quadcopter Battery Monitor and Laser Controller

Do you plan on flying a quad copter? Well you’ll need a way to monitor your battery level! Otherwise, you will get excited and fly it and then the battery voltage will drop enough such that the current will drop and then your quad copter will crash and there will go hundreds of dollars to waste because you didn’t buy insurance. How about that landing? Would you like to have the power to switch a laser on to determine where you are in reference to the ground? No worries! We will create a device that wirelessly displays your current voltage level, status messages, an LED light that displays the battery percent remaining, and you will even have the power to turn a quad copter mounted laser on or off wirelessly with the control of a switch, all on one device using Arduino and Digi XBee radio technology.  After all, Arduino and XBee are best friends in the electrical engineering world! Why else would an XBee shield exist?


Parts:

  • Two solderless breadboards (MS MKKN2, AF 64, DK 438-1045-ND, SFE PRT-09567)
  • Two Arduino Uno boards (MS MKSP4, SFE DEV-09950, AF 50)
  • Hookup wire or jumper wire kit (MS MKSEEED3, AF 153, DK 923351-ND, SFE PRT-00124)
  • USB A-to-B cable for Arduinos (AF 62, DK 88732-9002, SFE CAB-00512)
  • One rocker switch (DK CH755-ND, SFE COM-11139)
  • One XBee Pro radio (Series 2/ZB firmware) configured as a Zigbee Coordinator API mode (Digi: XBP24BZ7WIT-004, DK 602-1181-ND)
  • One XBee Pro radio (Series 2/ZB firmware) configured as a Zigbee Router API mode (Digi: XBP24BZ7WIT-004, DK 602-1181-ND)
  • XBee USB serial adapter (XBee Explorer or Digi Evaluation board) (AF 247, SFE WRL-08687)
  • Two XBee shields (Seeed Studio SLD01103P, Arduino A000065, SF WRL-10854)
  • Wire strippers (AF 147, DK PAL70057-ND, SFE TOL-08696)
  • Buzzer (DK 102-1621-ND, RS 273-060)
  • One 150K ohm resistor (DK P150KBACT-ND)
  • One 10K ohm resistor (DK P10KBACT-ND, SFE COM-08374)
  • One 300 ohm resistor (DK P300BACT-ND)
  • One 2N3904 transistor (DK 2N3904TFCT-ND, RS276-2016, SFE COM-00521)
  • One 10K ohm potentiometer (panel mount) (DK P3C3103-ND, RS 271-1715, SFE COM-09288)
  • One 16x2 character LCD display (with HD44780 parallel interface) (AF 181, DK 67-1758-ND, SFE LCD-00255)
  • 16-pin single-row male header (DK S1012E-36-ND, SFE PRT-00116)
  • One mini-breadboard (DK 923273-ND, SPE PRT-12046)
  • One 10 Segment LED Bar Graph (DK ELB-1010SURD, SFE COM-09935)
  • Four 9-volt batteries (RS 23-866)
  • Two 9-volt to barrel jack adapters (SFE PRT-09518)
  • A laser pointer that runs on roughly 3 volts (LAZERPOINT SKU-0004251)
  • Two alligator clips (DK 290-1951-ND, SFE PRT-00111)
  • Duct tape (every store in the universe has this)
  • Electrical tape (DK 3M33+A-ND, SPE PRT-10689)
  • Two plastic boards (roughly 8”x6”) (any hardware store will have this in some form)
  • Soldering tools (any hardware store)
  • An excited mind

Using the Arduino IDE

This project uses the Arduino software, known as the IDE, in order to program the Arduino uno microcontroller. You can download it for free from the Arduino website software section at http://www.arduino.cc/en/Main/Software. There are many versions, so be sure to download the correct one. A basic guide to how to use it can be found at http://arduino.cc/en/Guide/HomePage.

Prepare and Configure your Coordinator Radio

  1. Use X-CTU to set the designated coordinator radio in API mode.
  2. Configure the coordinator radio with a PAN ID (between 0x0 and 0xFFFFFFFFFFFFFFFF). Make sure you note this ID so that you can set up your router radio with the same one.
  3. Enter in the High and Low destination addresses of your router radio.
  4. Set pin 0 to mode 4, which is low digital output mode.
  5. Set the sampling rate to 0x64 (100 samples per second).

Prepare and Configure your Router Radio

  1. Use X-CTU to set the designated router radio in API mode.
  2. Configure the router radio with the PAN ID you set the coordinator radio with.
  3. Set JV to 1 to ensure that your router attempts to rejoin the coordinator on startup.
  4. Enter in the High and Low destination addresses of your coordinator radio.
  5. Set pin 0 to mode 2, which is analog mode.
  6. Set the sampling rate to 0x64 (100 samples per second).

Construct the on-board arduino-xbee system

Quad1 
Figure 1 

Quad2 
Figure 2
  1. Attach the Arduino and breadboard side by side onto a plastic board. Rolling up duct tape and attaching it in between the plastic and components is just fine.
  2. Take your Router XBee Pro radio and insert it into the Arduino with the XBee shield.
  3. Hook up the Arduino ground to the breadboard ground.
  4. Hook up the Arduino 3.3 volt supply to the power supply on the breadboard.
  5. Connect the power and ground on one side of the breadboard to the other side using jumper wire or the metal leads cut off from resistors.
  6. Using a quad battery connector (connects to thin end of battery), solder a black wire and a red wire (each about a foot in length) to the corresponding pins on the connector.
  7. Hook up the black wire to ground on the breadboard.
  8. Hook up the red wire to a spot near the middle of the breadboard. You will create a voltage divider from this.
  9. From the red wire, hook up a 150K ohm resistor to another spot on the board.
  10. From the other end of the 150K ohm resistor, hook up a 10K ohm resistor. Then, connect it to ground on the breadboard.
  11. Hook up a wire from the connection between the two resistors to pin 20 on the XBee radio.
  12. Take the laser pointer and unhook the battery half of it, so that only the laser light segment is left. Identify where the positive and negative components are hooked up.
  13. Cut a red wire and a black wire into segments about a food and a half long.
  14. Solder an alligator clip to one end of the red wire and one end of the black wire.
  15. Clip the wires to the corresponding positive and negative terminals of the laser pointer. Wrapping electrical tape around the alligator clips will prevent short circuiting!
  16. Using electrical tape, attach the laser pointer (facing down) to an interior corner of your choosing on the quad copter. Remember – there is no such thing as too much tape.
  17. Hook the laser’s red wire to the positive on the breadboard (will supply 3.3 volts).
  18. Place the 2N3904 transistor on the breadboard (preferably towards one end). Connect the middle terminal to digital pin 9 on the Arduino.
  19. When facing the transistor on the flat side, hook the left pin to the breadboard ground.
  20. Hook the right pin to the laser’s negative wire.
  21. Now that the on board Arduino-XBee system construction is complete, attach the plastic board holding it to the top of the quad copter with electrical tape.
  22. Cut off two metal pins from a resistor. Take two 9 volt batteries and solder the positive terminals together and the negative terminals together. This will put the two batteries in parallel (doubling the current capacity). Tape them together with electrical tape to strengthen the attachment between the two.
  23. Using electrical tape, attach the batteries towards the front of the quad copter under where the Arduino is placed.
  24. Using the 9 volt to barrel jack adapter (only needs to be connected to one battery), hook up the batteries to the Arduino. Your on-board system is ready to rock and roll!

Program the onboard laser system

*When uploading the program to the Arduino board, make sure you switch the TX (connected to pin 1 on Arduino) on the XBee off. This can be done on the XBee shield.*

There are two programs that run the quad device system. One runs the main handheld device (to be constructed next), and this program runs when the laser turns on or off on the onboard system. Upload the following program to your Arduino board on the onboard system:

#include <WString.h>
#define VERSION "1.02"int LASER = 9;
int button = 0;void setup() {

pinMode(LASER, OUTPUT);
Serial.begin(9600);

}

void loop() {

if (Serial.available() >= 22) {
if (Serial.read() == 0x7E) {

//read variables that we're not using out of buffer

for (int i = 0; i<19; i++) {

byte discard = Serial.read();

}

button = Serial.read();

}
}

button = button & B00000001; //looks at bit for digital pin 0

if (button) {

digitalWrite(LASER, HIGH);

}

else {

digitalWrite(LASER, LOW);

}

delay(10);

}


Construct the hand-held device

Quad3
Figure 3

Quad4 
Figure 4
  1. The first step is to place all of the components together on the plastic board. Use Figure 3 to attach the batteries hooked in parallel (refer to steps 22-24 in the previous construction), the buzzer, Arduino uno board, big breadboard, and small breadboard onto the plastic board. We are now ready to begin construction. Rolling up duct tape and attaching it between the plastic and the components works just fine.
  2. Insert your Coordinator XBee Pro Radio onto the XBee shield, and then insert the shield onto the Arduino board.
  3. Hook up the Arduino ground to the breadboard ground.
  4. Hook up the Arduino 5 volt supply to the power supply on the breadboard.
  5. Connect the power and ground on one side of the breadboard to the other side using jumper wire or the metal leads cut off from resistors.
  6. Trim the male headers down to 16 pins and then solder the row of male headers into the LCD screen.
  7. Insert the LCD onto the edge of the breadboard.
  8. Connect the LCD’s pin 1 to the ground rail on the breadboard.
  9. Connect the LCD’s pin 2 to the power rail on the breadboard.
  10. Attach the potentiometer to the breadboard next to the LCD screen. There are three pins: two terminals (the ends) and a wiper pin (the middle). Connect one terminal of the potentiometer to power and the other to ground. Connect the wiper (the center pin) to the LCD’s pin 3.
  11. Connect LCD’s pin 4 to the ground rail on the breadboard.
  12. Connect LCD pins 5, 6, 11, 12, 13, and 14 to Arduino digital pins 13, 12, 11, 10, 9, and 8 respectively.
  13. Connect LCD’s pin 15 to the power rail on the breadboard.
  14. Connect the LCD’s pin 16 to the ground rail on the breadboard.
  15. On the far right of the large breadboard above the LCD screen, insert the rocker switch with one pin connected to the power rail.
  16. Attach a 300 ohm resistor to the pin not connected to the power rail.
  17. Proceed to connect the other end of the resistor to the ground rail.
  18. Connect a wire from the same side of the resistor to XBee pin 20.
  19. Attach the 10 LED Bar Graph to the center of the small breadboard.
  20. Use metal pins from resistors and connect the left side (ground side) of the bar graph pins together to create a common ground. There are many ways of doing this, so use Figure 2 as a reference.
  21. Use metal pins from resistors and connect every two bars together (bars 1 and 2 should have common power, 3 and 4 should have common power, etc.) Again, reference Figure 2.
  22. Connect a wire from either pin 1 (the bottom) or 2 to the Arduino digital pin 2.
  23. Connect a wire from either pin 3 or 4 to the Arduino digital pin 3.
  24. Connect a wire from either pin 5 or 6 to the Arduino digital pin 4.
  25. Connect a wire from either pin 7 or 8 to the Arduino digital pin 5.
  26. Connect a wire from either pin 9 or 10 (the top) to the Arduino digital pin 6.
  27. Connect a wire from the free Arduino ground pin closest to the breadboard to any ground pin on the LED (pin 10 recommended for easiest access).
  28. Connect the buzzer ground to Arduino ground pin on the digital pin side of the board.
  29. Connect the buzzer power to the Arduino digital pin 7.
  30. Using the 9 volt to barrel jack adaptor (only needs to be connected to one battery), hook the batteries up to the Arduino. Your hand-held device is complete!

Program the handheld device

*when uploading the program to the Arduino board, make sure you switch the TX (connected to pin 1 on Arduino) on the XBee off. This can be done on the XBee shield.*

There are two programs that run the quad device system. One runs the main handheld device (to be constructed next), and the other programs when the laser turns on or off on the onboard system. Upload the following program to the Arduino controlling the handheld system:

#include <WString.h>
#include <LiquidCrystal.h>// connect to an LCD using the following pins for rs, enable, d4, d5, d6, d7

LiquidCrystal lcd(13, 12, 11, 10, 9, 8);

// defines the character width of the LCD display

#define WIDTH 16
#define VERSION "1.02"

int analogValue = 0;
int BUZZER = 7;
int TWO = 2;
int FOUR = 3;
int SIX = 4;
int EIGHT = 5;
int TEN = 6;

float voltageValue;

void setup() {

// set up the display and print the version

pinMode(BUZZER, OUTPUT);
pinMode(TWO, OUTPUT);
pinMode(FOUR, OUTPUT);
pinMode(SIX, OUTPUT);
pinMode(EIGHT, OUTPUT);
pinMode(TEN, OUTPUT);

lcd.begin(WIDTH, 2);
lcd.clear();
lcd.print("QUADCOPTER");
lcd.setCursor(0,1);
lcd.print("VOLTAGE TRACKER");

delay(4000);

Serial.begin(9600);

}

void loop() {

// check that the buffer has everything
if (Serial.available() >= 21) {

// search for the start byte
if (Serial.read() == 0x7E) {

//read variables that we're not using out of buffer
for (int i = 0; i<18; i++) {

byte discard = Serial.read();

}

int analogHigh = Serial.read();
int analogLow = Serial.read();

analogValue = analogLow + analogHigh * 256;
voltageValue =  float((1.2 * (analogValue) / 1024) * 12);

}
}

lcd.clear();

if (voltageValue > 12.00) {

digitalWrite(BUZZER, LOW);
digitalWrite(TEN, HIGH);
digitalWrite(EIGHT, HIGH);
digitalWrite(SIX, HIGH);
digitalWrite(FOUR, HIGH);
digitalWrite(TWO, HIGH);
lcd.print(voltageValue);
lcd.print(" Volts");
lcd.setCursor(0,1);
lcd.print("Lookin' healthy!");

}

if (voltageValue > 11.50 && voltageValue <= 12.00) {

digitalWrite(BUZZER, LOW);
digitalWrite(TEN, LOW);
digitalWrite(EIGHT, HIGH);
digitalWrite(SIX, HIGH);
digitalWrite(FOUR, HIGH);
digitalWrite(TWO, HIGH);
lcd.print(voltageValue);
lcd.print(" Volts");
lcd.setCursor(0,1);
lcd.print("Lookin' healthy!");

}

if (voltageValue > 11.00 && voltageValue <= 11.50) {

digitalWrite(BUZZER, LOW);
digitalWrite(TEN, LOW);
digitalWrite(EIGHT, LOW);
digitalWrite(SIX, HIGH);
digitalWrite(FOUR, HIGH);
digitalWrite(TWO, HIGH);
lcd.print(voltageValue);
lcd.print(" Volts");
lcd.setCursor(0,1);
lcd.print("Lookin' healthy!");

}

if (voltageValue > 10.50 && voltageValue <= 11.00) {

digitalWrite(BUZZER, LOW);
digitalWrite(TEN, LOW);
digitalWrite(EIGHT, LOW);
digitalWrite(SIX, LOW);
digitalWrite(FOUR, HIGH);
digitalWrite(TWO, HIGH);;
lcd.print(voltageValue);
lcd.print(" Volts");
lcd.setCursor(0,1);
lcd.print("Lookin' healthy!");

}

if (voltageValue > 10.00 && voltageValue <= 10.50) {

digitalWrite(BUZZER, HIGH);
digitalWrite(TEN, LOW);
digitalWrite(EIGHT, LOW);
digitalWrite(SIX, LOW);
digitalWrite(FOUR, LOW);
digitalWrite(TWO, HIGH);

lcd.print(voltageValue);
lcd.print(" Volts");
lcd.setCursor(0,1);
lcd.print("Fly it down low.");

}

if (voltageValue > 0.00 && voltageValue <= 10.00) {

digitalWrite(BUZZER, HIGH);
digitalWrite(TEN, LOW);
digitalWrite(EIGHT, LOW);
digitalWrite(SIX, LOW);
digitalWrite(FOUR, LOW);
digitalWrite(TWO, LOW);

lcd.print(voltageValue);
lcd.print(" Volts");
lcd.setCursor(0,1);
lcd.print("Bring it down!!!");

}
else {

lcd.print(voltageValue);
lcd.print(" Volts");

}

delay(15);

}

Tags: API XBee