Controlling iRobot Roomba from Z-Wave
Controlling iRobot Roomba from Z-Wave network.This sketch allows to control iRobot Roomba with Clean and Seek Dock commands. It also reports current battery voltage (usefull for old Roomba battery). You can also add direct control of Roomba, read temperature sensor, read wall strike sensor, get can not pass notification and many more.
DC-DC power switching is used to safely power Z-Uno from Roomba as voltage can change from 14 V during claning up to 20 V while charging.
Two resistors are used as voltage divider to convert from 5 V TTL UART levels of Roomba to 3.3 V required for Z-Uno (RX pin only).
- Z-Uno board
- Breadboard (optional)
- 1 resistor 1 kΩ
- 1 resistor 2.2 kΩ
- MP1584EN switching DC-DC converter
#define LED_PIN 13
byte roombaState = 0;
word batteryValue = 0;
ZUNO_SETUP_CHANNELS(
ZUNO_SWITCH_BINARY(getter, setter),
ZUNO_SENSOR_MULTILEVEL(
ZUNO_SENSOR_MULTILEVEL_TYPE_VOLTAGE,
SENSOR_MULTILEVEL_SCALE_VOLT,
SENSOR_MULTILEVEL_SIZE_ONE_BYTE,
1,
getterBattery
)
);
void setup() {
pinMode(LED_PIN, OUTPUT);
Serial1.begin();
}
void loop() {
// Get battery value every 1 minute
byte data[2] = {0, 0}; // array to store data from battery
byte i = 0;
Serial1.write(142); // Send a packet of sensor data bytes
Serial1.write(22); // Get battery value
delay(200);
while (Serial1.available()) {
data[i++] = Serial1.read();
}
// highbyte is shifted left eight bits, lowbyte is added to highbyte
// encoder_count = highbyte << 8 + lowbyte
batteryValue = (data[0] << 8) + data[1];
zunoSendReport(2); // Send Battery every 30 seconds
delay(30000);
}
void setter(byte value) {
if (value) {
digitalWrite (LED_PIN, HIGH);
Serial1.write(128); // Roomba START Communication
Serial1.write(131); // SAFE MODE
Serial1.write(135); // Clean
roombaState = 1;
}
else {
digitalWrite (LED_PIN, LOW);
Serial1.write(128); // Roomba START Communication
Serial1.write(131); // SAFE MODE
Serial1.write(135); // Stop Clean
roombaState = 0;
}
}
byte getter() {
return roombaState;
}
byte getterBattery() {
return batteryValue;
}
Download this sketch
Link to detailed project description (in Russian, use Google to translate)