This tutorial aims to replicate the Baby Room Automation project found on Hackster.
For this project we will use an Android device, that will run the AI2 application, and a UDOO Board, installed in the baby room. The UDOO Board runs Linux and has a camera, a microphone, the sensors and relays to control the lights.
- stream the video from the baby room to a remote AI2 app
- stream the audio from the baby room to a remote AI2 app
- turn on/off lights in the baby room
- get data from the sensors, like DHT11 temperature sensor
Turn lights on/off
To control a light you need two buttons (on / off) and any relay, like this one. Connect a lamp to the “normally open” and “in” plugs. On the Arduino side of the relay connect the enable pin to a free GPIO on the UDOO Board. You can the use the digitalWrite method on the UdooArduino component:
Read temperature, motion and audio sensors
We want to get some data from the sensors connected to the UDOO Board:
- motion sensor: we want to know if the baby moves
- audio sensor: we want to know if the baby cries
- temperature sensor: we want to know if the room is too hot
Inside the Timer event of a Clock we read the three sensors. If the digitalRead of the movement sensor returns 1, it means that a movement is detected and the Android device running the AI2 app vibrates.
If the analogRead of the audio sensor returns a number greater than i.e. 50, some noise is detected in the room, and we assume it is the cry of the baby.
We also call ReadSensor on the DHT11 sensor, and we check for the temperature value on the DataReady callback. While digitalRead and analogRead are synchronous, ReadSensor is not, so there is a separate callback for this reason.
The video streaming is achieved installing MJPG-Streamer on the UDOO Board. It exposes a webserver with a MJPEG images, creating a fake (low frame rate) video:
ubuntu@udoobuntu: ~/mjpg-streamer/mjpg-streamer-experimental $ ./mjpg_streamer -o "output_http.so -w ./www" -i "input_uvc.so -d /dev/video0 -r 640x480 -y -fps 2"
Then in App Inventor create a WebViewer component and set the URL to
data:text/html;charset=utf-8,<img src="http://192.168.0.117:8080/?action=stream" />
having care to replace 192.168.0.117 with the IP address of the UDOO Board.
Connect a microphone to the UDOO Board, the install icecast (you can easily find some tutorials on Google). Icecast creates a webradio, records the audio, encodes it in mp3/ogg and streams it over the network.
To play the audio on your board, add a Player component to the AI2 app and set the source to a string containing the radio URL.