Introduction: Baby Monitor With Arduino and SmartLiving Maker Platform

Baby monitor is nice example of connected devices using Arduino, Grove Shield Base and SmartLiving Maker platfrom (https://maker.smartliving.io) for IoT makers.

What Baby Monitor can do?

  • See the room temperature and noise level at any time on your mobile device
  • Receive alerts (push notifications) on your mobile device when room temperature or noise level is critical
  • Your wife/husband/grand parents receiving alerts on their mobile phones
  • Enable/Disable Baby Monitor when needed

Step 1: Requirements

  • Arduino board
  • Grove Base Shield
  • Grove Sound Sensor
  • Grove Temperature Sensor
  • Smartliving account (FREE)
  • Arduino usb2serial
  • Network cable

Step 2: Setup Arduino Board

To setup your Arduino board do the following:

  • Plug Arduino usb2serial and connect to your computer
  • Plug Grove Temperature Sensor and Grove Sound Sensor into analog ports
  • Connect to the network with internet connectivity

Step 3: Setup Smartliving Account and Baby Monitor Device

Go to maker.smartliving.io and setup account and baby monitor arduino device.

  1. Login on maker.smartliving.io
  2. Click on ground named Playground (or create new ground)
  3. Click on Devices in menu
  4. Click on plus sign to create new device
  5. Select Arduino and name your device as you wish (eg 'Baby Monitor')

Step 4: Download and Adapt Arduino Script

Download the sketch attached to this step and adapt it:

First, copy and paste deviceId, clientId and clientKey from Baby Monitor device page on SmartLiving Maker. These are necessary to authenticate on SmartLiving Maker platform.

char deviceId[] = ""; // Your device id comes here
char clientId[] = ""; // Your client id comes here
char clientKey[] = ""; // Your client key comes here;

Then, adapt mac address of your arduino board inside setup() method.

byte mac[] = {  0x90, 0xA2, 0xDA, 0x0D, 0xE1, 0x3E };

Finally, change the values of TEMP_SENSOR and SOUND_SENSOR variables to the pin numbers where you plugged it in to Grove Shield.

int TEMP_SENSOR = 0;  <br>int SOUND_SENSOR = 1;

Short explanation of the script

Script uses ATT_IOT.h, which wraps the HTTP API and MQTT communication with SmartLiving platform.

setup()

Setup method is used to initialize device on SmartLiving platform.

if(Device.Connect(ðClient, httpServer))                                              
  { 
    Device.AddAsset(TEMP_SENSOR, "Temperature", "Temperature Sensor", false, "number");   
    Device.AddAsset(SOUND_SENSOR, "Noise", "Noise sensor", false, "number");              
    Device.AddAsset(DISABLE_ACTUATOR, "Disabled", "Monitor Disabled", true, "boolean");   
    Device.Subscribe(pubSub);

    Device.Send(F("false"),DISABLE_ACTUATOR); 
}

Device.AddAsset is calling SmartLiving Maker API function to setup asset on the platform.

Device.Subsribe is used to subscribe on MQTT broker of SmartLiving platform. We will receive messages from the platform (web, mobile app) to disable/enable monitor.

loop()

Reading Temperature

a = analogRead(TEMP_SENSOR);
resistance=(float)(1023-a)*10000/a;
temperature=1/(log(resistance/10000)/B+1/298.15)-273.15;

Reading Sound

soundValue = analogRead(SOUND_SENSOR);

Sending temperature and sound values to the SmartLiving platform

if(!monitorDisabled){
  if(lastSentTemperature != temperature){
    Device.Send(String(temperature), TEMP_SENSOR);
    lastSentTemperature = temperature;
    Serial.println(F("temperature changed"));
  }
  if(lastSentSoundValue != soundValue){
    Device.Send(String(soundValue), SOUND_SENSOR);
    lastSentSoundValue = soundValue;
    Serial.println(F("sound changed"));
  }
}
 Device.Process(); 
 delay(1000);
}

Device.Send will publish a value to the appropriate MQTT topic.

Step 5: Upload Script to Arduino

After you upload srcipt to Arduino, setup will create three assets:

  • Monitor Disabled (Actuator)
  • Temperature (Sensor)
  • Noise (Sensor)

SmartLiving Make plartform allows you to select visual control that will be associated with each asset. To configure control for each of these assets do the following:

  1. Open asset page (Playground -> Baby Monitor -> choose Asset)
  2. Open configuration drawer
  3. From dropdown 'Select control' choose control you want to use

I've chosen Toggle control for Monitor Disabled, Circle Progress for Temperature Sensor and Line Progress for Noise Sensor.

Step 6: Setup Rules on SmartLiving Maker

SmartLiving Maker platform allows us to setup simple rules that will execute each time the value of sensor changes. We will use this feature to setup two rules:

  1. To Notify us when Temperature drops below certain level
  2. To Notify us when Noise is above certain level

Here is how to do it on SmartLiving Maker platform:

  1. Click on user menu in top right corner
  2. Click on 'Your Rules' menu item
  3. Click on plus sign to create new rule and choose 'Use Rules Wizard'
  4. For the trigger select 'Device State Change'
  5. Select 'Baby Arduino' on next step
  6. Select 'Temperature' sensor
  7. Select 'Compare to some value'
  8. Select 'Less then' comparation operator
  9. Enter minimum temperature and click Next to finish trigger configuration and go to action configuration
  10. Select 'Notify Me' action
  11. Enter message you want to receive when this rule is executed (eg The temperature in baby room is below minimum!)

You can repeat similar steps for rule that will notify you when Noise is above certain level. Note that noise level is sound strength of the environment, therefore you should calibrate the rule to the sound of your baby crying.

Step 7: Install SmartLiving Mobile Application

SmartLiving Mobile is the extension app of SmartLiving Maker website.

It is available on Play Store and App Store. Install SmartLiving Mobile and install on your phone and login with your SmartLiving Maker credentials.

Now, you should be able to receive alerts when room temperature is below minimum level or when noise is above the limit you set in the rule.

Step 8: Enable Your Wife/husband/grand Parents to Receive Notifications Too

Cool thing about Smartliving Maker is that you can easily add other people to your ground (eg Playground) which will allow them to use some of your resource such as rules or sensor values.

It is required that the person you want to share alerts also register on SmartLiving Maker and install SmartLiving mobile application. Once that is done, do the following:

  1. Go to SmartLiving Maker home page https://maker.smartliving.io/
  2. Select 'Playground'
  3. Select 'Members' in top menu
  4. Click on plus sign to add new member
  5. Enter email address of the person you want to share alerts

Now, new person is member of the ground. Next step is that person to subscribe on alert he wants to receive. This is how to do that:

  1. Login to Smartliving Maker with other person credentials
  2. Click on 'Playground' (it will show in this account as well because in previous steps we added this user as member)
  3. Click on 'Devices' in top menu
  4. Click on 'Baby Monitor'
  5. Click on pen icon below the title. It will open popup with all the rules associated with this device
  6. Click on the 'me' button to subscribe on rules

And, that's it.

Now you and your family can receive alerts on their phones when room temperature is below minimum or noise is above normal.