This Instructable provides a step-by-step explanation of how to develop an app that will allow the user to monitor a travel trailer from their phone or other device using motion, sound, light, temperature/humidity, and gas sensors. This system uses wireless Arduino-based sensors, Arduino Uno and Intel Galileo single-board computers and an open source home automation platform called OpenHab. While this Instructable is targeted for the Ann Richards School Airstream trailer, the product can be used in other tiny living areas.
Step 1: Purchasing Materials
$9.95 - Digital PIR Motion Sensor
$6.90 - Analog Light Sensor aka Cds photoresistor
$9.99 - Analog Gas Sensor
$8.69 - Analog Sound Sensor
Blue LED, for motion and light sensors
Red LED, for sound sensor
Resistors with 1 kohm value (2)
Resistors with 220 ohm value (3)
Various long and short wires (black for ground, red for power)
$24.95 - Arduino Uno Board (1) **one needed here, one needed for ethernet gateway**
$9.95 - Protoshield (2)
$16.60 - 915 MHz Wireless Module aka RFM69 wireless transceiver
$19.99 - FlexiBrute Current Transformer Board 2.0 **currently out of stock**
$24.95 - Arduino Uno Board (1) **one needed here, one needed for wireless gateway**
$18.00 - Wiznet 5100 Ethernet Shield
$5.29 - RJ45 Ethernet Cable (2)
$79.95 - Galileo Board, instead of using Raspberry Pi… NOT needed if you substitute a laptop
$72.99 - Router
Total Cost: $348.49
Notes: the most expensive items are the router, Galileo board, and Arduino boards, which make up more than half of the total cost. The sensors, circuit parts, and most other items are relatively inexpensive. This budget does not include shipping fees. Also, if you can use a router that you already have, or substitute the Galileo board for a laptop that you leave at home, this could decrease the total cost considerably.
Step 2: Coding Sensors
Links to Code
Temperature Sensor Code: http://www.codeshare.io/NL6Xh
Light Sensor Code: http://www.codeshare.io/gCPOF
Motion Sensor Code: http://www.codeshare.io/gCPOF
Sound Sensor Code: http://www.codeshare.io/gCPOF
RFM Gateway Code: http://www.codeshare.io/gCPOF
Takes data on the sensor nodes from the wireless transceiver and translates this data into an I2C data struct. We were unable to run this code because we didn’t have time to order and set up an RFM wireless transceiver.
Ethernet Gateway Code: http://www.codeshare.io/gCPOF
Calls data from the wireless gateway in the form of an I2C data struct and communicates with the Arduino Uno board in the ethernet gateway. The Arduino Uno board is connected to MQTT so the data can be published to the Mosquitto broker. We were unable to run this code because we didn’t have time to order and set up an RFM wireless transceiver.
Step 3: Connecting Sensors to Arduino Uno Board
The temperature sensor has four pins, but only three are actually hooked up to the Arduino Uno board. The leftmost pin is attached to power and the rightmost pin is attached to ground. The left middle pin is connected to the Arduino board digital pin 5. The output pin connects to a 1 kohm resistor which runs to power.
Our temperature sensor came with a 1 kohm resistor. However, our temperature sensor isn’t hooked up to an LED because the temperature and percentage humidity are displayed on the serial monitor (this aspect is coded).
The photoresistor is fairly simple; it connects to ground, power, and a resistor. The output wire can connect to either side of the photoresistor and then analog 0 (A0) on the Arduino board. The resistor also connects to the output wire and then to ground. The other side of the photoresistor is connected to power. An LED is used as an output for the light sensor. The LED is connected to digital pin 9 on the power side (the longer wire on the LED) and to a resistor that runs to ground on the ground side (the shorter wire on the LED).
We used two 1 kohm resistors, one for the LED and the other for the photoresistor. Our LED was blue. To test this circuit we plugged the arduino board into a laptop and ran the code. When the photoresistor is covered the light turns off and it stays on at all other times. Our photoresistor code didn’t allow for output values on the serial monitor, however that could easily be coded in.
The PIR (Passive Infrared) motion sensor has three wires. One goes to ground (the black wire), another to power (the red wire), and the third (the middle wire) runs to digital pin 7. There are two outputs, an LED and the serial monitor value output. The LED is connected on the power side to digital pin 9 and on the ground side to ground.
We used the same LED that was used for the photoresistor for the PIR sensor. When the motion sensor senses movement it outputs a value on the serial monitor and catalogues when the movement occurred. The blue LED lights up. When the motion and light sensors are run together the absence of light causes the LED to turn off and the presence of light and absence of motion causes the LED to be dimly lit. However, when motion is detected all other sensors are overridden and the light turns on regardless of whether it is light or dark.
When building the sound sensor circuit, make sure to plug the correct wires into ground, power, and analog. Different sound sensors will have different pins for ground and power, so make sure to check. If everything is wired correctly, a light should turn on on the sound sensor. Also, be careful when building the circuitry that you don’t short circuit the system. Use the appropriate resistor for whatever sound sensor you have. The sound sensor is hooked up to an LED, which also needs a resistor.
We used a red-red-brown-gold, 220 ohm resistor for both the LED and sound sensor. Our ground was on the right pin, power in the middle, and analog on the left pin. We put the analog pin into spot A1 on the Arduino Uno Board. Our LED ran to digital 4.
Step 4: Setting Up Wireless and Ethernet Gateways
- Install OpenHAB on the host computer. Go to http://www.openhab.org/downloads.html and download the three packages under “openHAB Runtime”: “Runtime core”, “Addons”, and “Demo setup”
- Install Java if not already installed (http://www.java.com).
- Unzip the openhab-runtime-.zip to where it is intended to be running from, such as C:\OpenHAB. Note that there can't be a space in the path, so it can't be in program files in windows.
- Install Mosquitto, an MQTT broker (http://mosquitto.org/download/).
- Download OpenHAB from the App Store (iPhones) or Google Play (Android).
Step 5: Configuring OpenHAB and Mosquitto
The host computer picks up sensor data from the MQTT broker and sends it to the OpenHAB program. Single board computers like the Raspberry Pi and Intel Galileo boards make good host computers and have the advantage of low power consumption, but laptops and personal computers work as well. These instructions are for installing and running OpenHAB and Mosquitto on a Windows computer, which is simpler than using an Intel Galileo board (especially since we didn’t want to break the Intel Galileo board by incorrectly installing programs on it). If you want to install these programs on a single-board computer like Intel Galileo and Raspberry Pi boards, you will need to use the operating system Linux and can follow this Instructable: https://www.instructables.com/id/OpenHAB-on-Raspberry-Pi/?ALLSTEPS.
- In the “configurations” folder of the unzipped “runtime” folder, rename the file openhab_default.cfg to openhab.cfg.
- Open openhab.cfg in Notepad, Wordpad, or another text editor.
- Delete the default text and paste in the configuration for this system, which can be copied from this link: http://www.codeshare.io/buJt1
- From the OpenHAB Addons folder, copy all of the .jar files. Paste them in the “addons” folder of the OpenHAB Runtime folder.
- Locate the configurations folder within the OpenHAB Demo folder and the configurations folder within the OpenHAB Runtime folder. Within the “items”, “persistence”, “rules”, “scripts” and “sitemaps” folders, copy all files from the Demo folder and paste them into the corresponding folders in the Runtime folder.
- Connect the wireless router to the host computer (laptop, Intel Galileo board, etc.) with another ethernet cable (RJ45 cable).
- Start the server by executing the script start.bat (located in the “Runtime” folder).
- On the smartphone go to OpenHAB App and select the Settings button in the top right corner. Enter “/openhab.app” in the Remote OpenHAB URL blank. The smartphone should then connect to the remote URL and show the status of all the sensors (if they’re running).
Step 6: Installing in Trailer (or Tiny Home)
Now that the various components (sensors and Arduino Uno board, wireless gateway, ethernet gateway, and Galileo board) are connected and communicating with each other, it’s time to place your automation system in the trailer.
We found it helpful to create an overhead visual of the space you want to automate, using the free version of Google SketchUp (http://www.sketchup.com/). We were fortunate enough to have access to SketchUp Pro, which includes Google Layout in its software package - but this extra program is only needed to create professional looking labels, arrows, and other fine-tuning, graphic design adjustments.
Here are some tips for creating your SketchUp overhead visual:
- Open SketchUp Free and create a new project using feet/inches.
- Go to VIEW on the top menu bar, and select TOP. From this point forward, you only have to draw 2D shapes.
The above image is simply a suggestion of one advantageous sensor placement.