Wednesday, July 23, 2014

Robot - Wireless Communication: Transmitter

Now that the robot can respond to commands programmatically, the next step is to get the robot to listen for and respond to wireless commands. RF communication will be accomplished using the same library (VirtualWire) and components as my previous post, entitled Arduino Weatherstation – RF Communication

I'll split this part into two posts. The first will go over how to make the transmitter. The second will detail how to get the robot to respond to the transmitter's commands.

The Transmitter

Two components are needed, a 433 MHz transmitter and an Arduino. Connect the components as follows:

DATA --> Arduino pin 12
VCC --> Arduino 5V
GND --> Arduino GND


The transmitter operates as follows: First, the user opens the Serial monitor in the Arduino IDE and enters one of five commands:
  • 0 - Stop
  • 1 - Move forward
  • 2 - Move backward
  • 3 - Turn clockwise
  • 4 - Turn counterclockwise
Second, this command will be transmitted to the robot, which will respond to the command.

Show Code

How It Works

Open the Arduino Serial Monitor. Make sure that the drop-down menu next to the baud rate is set to "Newline." Enter a command, 0-4. The serialEvent event will fire, initiating the serialEvent() function. This function reads whatever was typed into the Serial Monitor into a String, one character at a time. When the line break character is reached, the contents of the String are transmitted. Refer to the transmitter.pde example that comes with VirtualWire for how to setup and transmit data. This sketch is simply a modification of that example. Note that VirtualWire requires a C-string, so toCharArray must be called on the Serial data to transmit.

The TXBURST variable will repeat the transmission however many number of times the user desires. This might be useful for for long-distance communication, where checksum validation might fail on the robot.