Archive for the ‘Robotics’ Category

Wireless Robotics Platform with XBee Remote Control

Difficulty Level = 7 [What’s this?]

I built a remote-controlled robotics platform using a 4WD mobile platform, an Arduino (Seeeduino Mega), an Adafruit motor shield, and two XBee radios for communication. There are also some super-bright white LEDs on the front for headlights. The point of the project was to show how an XBee radio can be used to send joystick sensor data without using a microcontroller on the remote.

The vehicle is very easy to control using a joystick and a couple of buttons to control the lights. First I’ll describe how the remote control unit works, then I’ll show how the vehicle was built.

The Remote

Here’s a picture of the remote control unit that I built on a breadboard. A Parallax joystick is used to control the vehicle, one button turns the headlights on/off, and another button puts the headlights in “scanner” mode, you know, like Kitt or like a cylon. The radio requires a 3.3V supply, but the analog pins cannot take more than 1.2V, so I used some precision resistors to form a voltage divider so that the analog input voltage was stepped down to less than 1.2V. Also note that the joystick is rotated 90 degrees so that it worked on a breadboard with this orientation.

To make this work, one radio needs to be running the “coordinator” firmware, and the other running the “router” firmware. In this project, the coordinator is on the vehicle and the router is on the remote control, but it should not really matter. It’s important that each radio be running the API mode firmware, not the AT/transparent firmware.

I used the X-CTU tool from Digi to write the appropriate firmware to the radios and configure them. If you have not done this before, this is not a good project to start with. It is best to start with 2 radios that you already have working together using the API firmware.

The XBee on the remote control unit is configured to send analog/digital sample packets every 100ms. Pins AD1 (pin 19) and AD2 (pin 18) are configured as analog inputs and are connected to the potentiometers in the joystick. Pins DIO3 (pin 17) and DIO4 (pin 11) are configured as digital inputs for the two buttons on the remote that control the lights on the vehicle. Here is a list of the configuration parameters that were set on the remote radio:

  • AD1/DIO1 = 2 (configured as analog input)
  • AD2/DIO2 = 2 (configured as analog input)
  • AD3/DIO3 = 3 (configured as digital input)
  • DIO4 = 3 (configured as digital input)
  • IR = 0x64 (sample rate set to 100ms)
  • PR = 0x1FFF (all pullup resistors enabled — this is the default)

This is a schematic of the remote control unit:

The Vehicle

The wiring for the vehicle is fairly simple. Inside the 4WD platform are 5 AA batteries for powering the motors, and a 9V battery for the Arduino. I’m using a Seeeduino Mega because that’s what I had handy but any Arduino will work. The Adafruit motor shield is connected to the 4 DC motors inside the chassis. I used the 3.3V power supply on hte Arduino to power the XBee radio. The TX/RX lines of the radio are connected to the RX/TX pins on the Arduino. There’s a ribbon cable connecting 4 output pins to the LED headlights, and a ground wire running to the headlight assembly. Here is the bottom of the headlight assembly. These are 100 ohm resistors to keep the current draw below 20mA per LED.

The Software

This code depends on the Adafruit library for using the motor shield, so download that and install it as an Arduino library. The Arduino sketch for this vehicle can be downloaded from here. Read the code for an explanation of how it works. The basic idea is to decode the incoming XBee API packets and map the joystick position information to the motor speeds. If the joystick is forward, all four wheels move forward. If the joystick is turned slightly to one corner, then the vehicle will move along an arc. If the joystick is hard left or right, then the wheels on the left side and right side will turn in opposite directions, causing the vehicle to rotate in place. By studying the code carefully, you should be able to understand how all of it works. Enjoy!

Published by Michael, on February 18th, 2012 at 7:03 am. Filed under: Arduino,Level 7,Robotics,XBee. | 36 Comments |

A Halloween Costume with Source Code

Difficulty Level = 5 [What’s this?]

Like many parents, we make hand-made costumes for our kids instead of buying cheaply-made (and expensive) costumes based on licensed characters. This year, my youngest son wanted to be a robot. My wife did a great job making the costume, but I just had to add some cool electronics to take it to the next level.

The electronics are nothing fancy — a simple Atmel ATtiny13 microcontroller that interfaces with two 74HC595 shift registers to light up LEDs randomly. The technical details are below, but in the process of building this, I was really struck by how electronics and computing are being embedded into everything. This week I was making a TODO list and one of the items was “finish source code for robot costume”.

OMG, now the costumes we make have source code.

This is a great example of how technology is becoming increasingly ubiquitous. Ten years ago, this would have been far beyond my reach. But in 2010 I can build this easily. The microcontroller cost $1.04, the shift register chips are $0.25 each, the resistors are a penny each, and the LEDs probably average $0.20 each. Definitely less than $5 for everything.

Technical Details

Here’s the schematic:

Schematic for robot costume circuit

Here is a closeup of the circuit board. There is a piece of clear acrylic protecting it. I ran out of 16 pin IC sockets, so the shift registers are in 20 pin sockets.

Circuit on front of costume. ATtiny13 microcontroller and two 74HC595 shift registers.

And finally, the simple source code that runs on the chip. I use CrossPack for AVR development. I use avrdude and a Bus Pirate to upload the code onto the ATtiny13 chip.

 * ATtiny13 driving two 74HC595 shift registers
 * Randomly turns on/off output pins of the shift
 * register ICs.
 * A random number of outputs are set high, then
 * a random time delay occurs.  Then the cycle
 *  repeats.

#include <stdlib.h>
#include <avr/io.h>
#include <util/delay.h>

#define DATA PB0
#define CLOCK PB1
#define LATCH PB2

int main(void) {
  int d;
  char n;
  char i;

  // set DATA, LATCH and CLOCK pins to OUTPUT
  DDRB |= (1 << DATA);
  DDRB |= (1 << LATCH);
  DDRB |= (1 << CLOCK);
  PORTB = 0;

  for(;;) {
    // choose number of LEDs to light up.
    // n will be between 4 and 16
    n = 4 + (random() % 13);

    for(i=0;i<16;i++) {
      // for each LED, probability of it being lit
      // is n/16
      if ((random() % 16) <= n) {
	PORTB |= (1 << DATA);  // set DATA pin high
      } else {
	PORTB &= ~(1 << DATA); // set DATA pin low

      // toggle shift register clock pin
      PORTB |= (1 << CLOCK);
      PORTB &= ~(1 << CLOCK);

    // once we've shifted out all 16 values, toggle
    // the latch pin.
    PORTB |= (1 << LATCH);
    PORTB &= ~(1 << LATCH);

    // delay random amount of time between
    // 100ms and 500ms
    d = 100 + (random() % 400);
    for(i=0;i<d;i++) {
      // _delay_ms function must be called with a
      // constant value, not a variable!

  return 0; // not reached

Published by Michael, on October 28th, 2010 at 8:55 pm. Filed under: AVR,Level 5,Robotics. | No Comments |

Wireless Robotics Platform: Cheap R/C Vehicle + Arduino + XBee + Processing

Difficulty Level = 8 [What’s this?]

UPDATE: Check out the new robotics platform project!

I built a wireless robotics platform from a cheap R/C car, an Arduino with XBee shield, small microswitch sensors, and a Processing program running on a remote computer to control the vehicle. The vehicle is completely controlled by the code running on the remote computer which allows very rapid prototyping of the code to tell the vehicle what to do and how to react to the sensor events received from the vehicle. I’m hoping this is a good way to teach my 9-year old son about programming.

Wireless computer-controlled robotics platform built on cheap RC vehicle, Arduino microcontroller, and XBee radios

Before I get into details, here’s an overview of the features:

  • All logic controlling the vehicle is performed in a Processing program running on remote computer. The Arduino program listens for commands from the remote computer.
  • Bi-directional wireless communication over XBee radios with (theoretical) 1-mile range. I’ve accomplished 1/4 mile range with these radios.
  • Sensor events are transmitted from the vehicle to the controlling computer. This vehicle has 3 microswitches – two on front bumper and one at the rear.
  • Original circuitry of vehicle replaced with dual H-Bridge circuit to control drive motor and turn motor. Drive motor is controlled with variable speed.
  • Power: Vehicle motors powered by 4 AA batteries. Arduino with XBee shield powered by 9V battery mounted at front of vehicle.
  • Simple communications protocol: 2 byte commands from controller to vehicle, one byte sensor readings from vehicle to controller.

The Hardware

There’s nothing special about the configuration of the XBee radios. They are running the AT firmware (“transparent mode”) which allows them to simply exchange serial data. The Libelium XBee shield on top of the Arduino makes it easy to read/write serial data from Arduino code.

Arduino and XBee shield on top of the vehicle

Inside the vehicle is a simple circuit board with an SN754410 quadruple half-H driver to drive the motors. The drive motor and turn motor are connected. I had to rip out the original circuit board (but I saved it!).

Read more…

Published by Michael, on March 4th, 2010 at 9:47 pm. Filed under: Arduino,Level 8,Processing,Robotics,XBee. | 43 Comments |