Hardware Reference
In-Depth Information
Figure 7-7
The insides of the monkey,
showing the wiring modifica-
tions. Solder the power to the
breadboard to the positive
terminal of the battery. Solder
the ground wire to the ground
terminal. Cut the existing motor
leads, and add new ones that
connect to the breadboard.
A
A
b
C
A. Motor wires replaced here b. Power C. Ground
To test this circuit, make sure that the sensor radio is
working, and turn it on. When the sensor's value is low,
the motor should be turned off; when the sensor reads
a high concentration of VOCs, the motor will turn on and
the monkey will warn you by playing his cymbals. Use the
potentiometer to affect the motor's activation threshold.
Start with the potentiometer set very high, then slowly
turn it down until the motor turns off. At that point, expose
the sensor to some alcohol—the motor should turn on
again. It should go off when the air around the sensor is
clear. If you're unsure whether the motor circuit is working
correctly, connect an LED and 220-ohm resistor in series
from 3V to the collector of the transistor instead of the
motor. The LED should grow brighter when the sensor
reading is higher, and dimmer when the sensor reading is
lower. The LED has no physical inertia like the motor does,
and it consumes less current, so it turns on at a much
lower duty cycle.
shield. You don't need to connect the XBee's receive line
to the Arduino's transmit line because the Arduino's never
going to talk to the XBee—it will just listen. You also won't
need the LED, or the potentiometer from that project.
When the Arduino receives the message from the gas
sensor XBee, it will parse the message, extract the sensor
value, and convert it to a voltage. It will act as a web server,
so anyone who wants to know the sensor level can check
on the Web. In order to make that happen, it's best to break
the task into two parts: first, establish that you can read
and parse the XBee's messages; then, add the web server
component to your code.
Reading the XBee Protocol
So far, you've been able to rely on the XBee radios to do
their work without having to understand their message
protocol. Now it's time to interpret that protocol. The XBee
radios format the readings from their analog-to-digital
converters into a packet before they transmit. The format
of the packet is explained in the Digi XBee 802.15.4 user's
manual. It works like this:
The Arduino circuit
If you're using an Arduino wireless shield, all you need to do
for this project is stack that on top of an Ethernet shield or
Arduino Ethernet board, and add them both to your micro-
controller. If you're building the circuit yourself, it's shown in
Figure 7-8.
• Byte 1: 0x7E, the start byte value.
• Byte 2-3: Packet size, a 2-byte value. This depends on
your other settings.
• Byte 4: API identifier value, a code that says what this
response is.
The Arduino Ethernet and XBee circuit look a lot like the
circuit you used for the duplex radio transmission project in
Chapter 6. All you're doing differently is adding an Ethernet
 
Search WWH ::




Custom Search