Page 309 - Hacking Roomba
P. 309
290 Part III — More Complex Interfacing
Listing 13-3 Continued
void updateSensors() {
Serial.print(142, BYTE);
Serial.print(1, BYTE); // sensor packet 1, 10 bytes
delay(100); // wait for sensors
char i = 0;
while( Serial.available() ) {
int c = serialRead();
if( c==-1 ) { // error
for( int i=0; i<5; i ++ ) { // blink 5 times on error
digitalWrite(ledPin, HIGH); delay(50);
digitalWrite(ledPin, LOW); delay(50);
}
}
sensorbytes[i++] = c;
}
}
Making a Mobile Mood Light
Roomba is not very visible at night when operating. Sometimes people operate their Roomba
in darkened rooms and don’t want to accidentally step on it. Maybe you just want a mobile
source of mood lighting. With the vacuum motors turned off and moving at a moderate
speed, Roomba isn’t very noisy and so having it slowly drive around, creating splashes of
colored light on the ceiling and walls, is pretty relaxing. Between the random motions of
Roomba and the rotating color cycling from the code below, a darkened room becomes a
pretty groovy place.
The schematic in Figure 13-24 shows a modification to the previous circuit to add three high-
output, high-efficiency RGB LEDs to the Roomba Arduino board. These LEDs are so bright
they are painful to look at directly and can fill up a room with light. By having an RGB trio
hooked up to the PWM outputs of Arduino, you can mix and match the RGB components to
make any color you choose.
The blue and green LEDs have a different voltage drop than the red ones and so will need
different resistor values. If you don’t feel like calculating optimal values, use the ones in the
schematic. The schematic’s resistor values are purposefully larger than normal to keep the
LEDs’ brightness down. From the Ohm’s Law discussion in Chapter 3, you’ll recall the resistor
controls the current to an LED and that, for a given voltage, a larger resistance gives a lower
current. Since an LED’s brightness is directly proportional to the current it’s given, if you find
you’d like the LEDs brighter, lower the resistor values. Be sure to know what the maximum
current is from your particular LED’s specification sheet and don’t exceed it.