Thursday, July 24, 2014

Robot - Wireless Communication: Receiver

In this post, I'll go over how to make the robot respond to commands sent by the transmitter. You'll need the parts outlined in a previous post. These parts include a motor driver, 433 MHz receiver, and some Arduino-compatible device. The robot chassis has limited space, so I used an Arduino nano clone.

The Receiver

The Arduino needs to respond to wireless commands by sending commands to the motor driver, which will ultimately drive the robot. Hook the 433 MHz receiver up to the Arduino as follows:

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

Power

At first, we had the Arduino and the motor driver running on 5 AA batteries. However, the Arduino exhibited odd behavior, like not responding to wireless commands after one had already been sent. With the motors running at half speed, they draw ~0.5 A, which was likely causing the Arduino to malfunction due to power loss. To fix this, a 9 V battery is used to power the Arduino and wireless receiver independent of the motors.

To run the Arduino off of a 9 V battery, connect:

9 V + --> Arduino VIN
9 V - --> Arduino GND


To recap, the motors are powered by 5 AA batteries, independent of any logic functions. The 433 MHz receiver, Arduino, and motor driver logic (VCC pin) are all powered from the 9 V battery.

Show Code

How It Works

The loop() function is similar to my previous weatherstation posts. VirtualWire handles any incoming transmissions, storing them in a string, buf. Only the first character is of interest, and if it's one of the commands (i.e., STOP, FORWARD, BACKWARD, CLOCKWISE, CCLOCKWISE), the command is passed to the set() function.

set() specifies the direction and speed of one motor. It simply pulls the appropriate direction pins (e.g., AIN1 and AIN2) to HIGH or LOW depending on the desired direction. Then, it sets the speed by sending a PWM signal to the appropriate pin. Finally, go() is called, which sets STBY to HIGH, causing the robot to move.

Turning involves setting one motor to move forward and the other to move backward.

Conclusion

While the robot will respond to wireless commands, the control is rudimentary. The speed is manually defined in the robot's code, and sending commands through the Serial Monitor is clunky at best. The next step will be to use joysticks to control the robot, allowing precise control of both speed and direction.

Here's a short video of the robot in action. This was before I had my Arduino nano. As you can see in the above picture, the chassis is much less crowded now. I think one motor is not properly aligned, but that will be fixed soon.