Automate and monitor the physical systems in your home

Building the System

In this example, we built a system one block at a time, where the blocks correspond to blocks in the block diagrams: we would build a block, test it, save it, and move on to the next block. By the time we had built all the blocks, we had about 60 files for the three Pis and four Arduinos.

Each time we built a block, we'd edit and save our work from the Console page. The Console page keeps a record of every script run and every wire drawn. Each time we ran a script or created a wire, the corresponding script command displayed in the console. So, for example, after creating the devices and wires of this article, the Console looked like Figure 11. Although some of the lines are too long to fit within the Console window, you can see that an Arduino, a programmable device, a state machine device, and a wire were created. After each command is a [true,] line, which is the result from the previously executed command. All the results show [true,], because they executed successfully; bad commands would return [false,].

Figure 11: Scripts and their output in the Console.

If you copy all the lines from the Console and delete the result output from the ends of the lines, you end up with a script that recreates your work. In this way, we were able to save our work. Sometimes, when scripts looked too busy, we added additional blank lines, spaces, and comments (any text following a # is a comment). These elements made the scripts easier to read and didn't affect execution because the script interpreter ignores blank lines, extra spaces, and comments.

Once we had finished creating block-level scripts, we created top-level scripts. Top-level scripts assemble all the blocks together: For three Pis, that's three top-level scripts. Using the block diagrams as guides, we ran all the block-level scripts for each Pi, added the wires to connect the blocks, then tested the wiring. When we were satisfied, we copied the Console into the appropriate top-level script, made the final edits, and saved the lot.


Each enclosure went on a wall panel (Figure 12): The Pi1 and Pi2 enclosure went into the utility room with many of the pre-existing systems, and the Pi3 enclosure went to the other end of the house near the furnace and water heater. After plugging in the Pis and giving each an Ethernet connection, the Pis were running, the Arduinos were running, and all three Virtual Wiring systems were running. Next, we wired in the various relays and sensors – about 50 signal wires. By design, all of the signals were low voltage and low current, so we used standard twisted pair wiring (Ethernet cables).

Figure 12: Mounted Pi1 and Pi2 enclosure.

All the sense wires electrically looked the same: two wires that were either shorted together or open. For each sense pair, then, we connected one wire to an Arduino pin and an external pull-up resistor (Arduinos have built in pull-ups, but they were too weak to be reliable for this application) and grounded the other wire. When the wires were open, the Arduino saw an "on" voltage. When the wires were shorted, the Arduino saw an "off" voltage. To add the external pull-ups, we soldered resistors to Arduino Proto Shields and sandwiched a Shield between each Arduino and Aussie Shield. The Aussie Shields made wiring pretty simple, because they have a push-button terminal for each Arduino signal; therefore, signal wires could be added or removed just by pushing a button.

The relay signals also came in pairs. One of the pair was grounded, and the other was connected to an Arduino output pin. Most of the relays were solid state, and these fit neatly into standard electrical boxes (Figure 13). Note: If you are not an electrician, you must have an electrician install your high-voltage relays; high voltages are dangerous.

Figure 13: Solid state relays, box, and outlet.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Digital – Analog – Mechanical

    As innovative companies consistently push the envelope of progress, antiquated hardware nearly two years old falls by the wayside. We take an old iPad, an Arduino Mega, and various other materials to create an in-dash climate control app.

  • Automated plant watering with Arduino

    House plants are fairly self-sufficient, but they do need certain care from people to survive. With a few Arduino sensors and a little programming, you can take the guesswork out of watering your plants.

  • Connecting a weather station to your Arduino

    After losing one weather station to tropical winds, the author reboots and designs a PCB that connects to an Arduino and monitors weather instruments.

  • A new way of no-solder prototyping

    The Grove system's standardized connector and multitude of devices allow quick and easy project prototyping with your favorite small-board computers.

  • Making your projects more reliable

    A watchdog timer is a great way of improving reliability for little cost in small, inexpensive computers such as the Raspberry Pi and Arduino.