DIY Smart Home Monitoring Bottle

by ssarthak598 in Circuits > Arduino

2951 Views, 32 Favorites, 0 Comments

DIY Smart Home Monitoring Bottle

IMG_1172.JPG
IMG_1171.JPG

Each year about 100 million accidents happen in homes across the world like fire, theft, earthquakes, smashing sounds, many many more. Because of this lives of common people are affected, their family and property is lost.

The idea is to make a simple device that can be kept on your dining table, near your door, or gas stove that can notify about any issue within seconds like gas leaks, or motion detected, or high air pollution, or strange sounds, etc etc.

What Do You Need?

IMG_1208[1].JPG

Boards & Parts:

1) Arduino or any other microcontroller

2) Grove base shield

3) An empty soda bottle

4) Some jumpers

5) A battery for powering your board

6) A breadboard

Sensors:

1) Grove temperature & humidity sensor

2) Gas sensor

3) Grove air quality sensor

4) Grove dust sensor

5) PIR motion sensor

6) Sound level detection sensor

Tools:

1) Cutter/Dremel

2) Some tape to sticking up things

Web Services:

1) Ubidots.com account

Assemble All the Sensors

Here we'll assemble all the sensors to the board.

Set Up the Web Service (Part 1)

ubidots_home.PNG
signup.PNG
3.PNG
add variable button.PNG

1) Go to Ubidots.com and then sign up

2) Log into you dashboard

3) Click on the sources button

4) Click on add source

5) Select Arduino as source

6) Name it as you want

Now you have successfully make your account!

8) Now click on add variable

9) Chose a line chart

10) Name your variables and add different icons to them

11) Create all of them and then go to your dashboard

Copy your account ID as well as we will need it in the next few steps.

Adding the Gas Leak Sensor (Part 1)

15 8:27 pm.jpg
15 8:27 pm.jpg
15 8:27 pm.jpg
15 8:27 pm.jpg
15 8:31 pm.jpg

Now we'll hack into the gas stove. Search for a location where gas could leak in case of an accident, it could be a pipe connection, near the stove mesh, near a valve, or a gas meter.

We'll fix the fire sensor there to sense some fire and gas leaks!

Attaching the Gas Leak Sensor Module (Part 2)

FEL57F1IHDAZB70.jpeg
IMG_0842.JPG
IMG_0838.JPG
15 8:31 pm.jpg

Now connect your sensor to the board. Do it tightly so that it doesnot comes out.

Test it using your board's ADC.

Adding the Motion Detector (Part 1)

IMG_0854.JPG
15 10:57 pm.jpg

Here i'll show you how to assemble your sensors with the board.

First, take your sensor, you'll see 3 pins in it-

1) GND

2) DATA

3) VCC

Connect your sensor to a breadboard and then connect the GND pin to GND pin of your linkit, VCC to 5V, and DATA pin to A0 pin.

Finally connect everything and lets move on to the next step!

Testing the PIR Module (Part 2)

IMG_0857.JPG
IMG_0856.JPG

Many PIR modules give errors. Test your module by testing it out on an ADC.

Attaching the Sound Sensor Module

IMG_0861.JPG
IMG_0859.JPG
IMG_0869.JPG

Now assemble all the parts together.

First of all, connect the jumper wires to the sound sensor. Connect 3 wires to VCC, GND and AOUT pin of the sensor.

Now connect the sensor to the A0 pin of the board.

Pin connections:

AOUT - A0

VCC - 5V

GND - GND

Attaching the Dust Sensor for PM10 Gas

IMG_0846.JPG
IMG_0833.JPG
IMG_0845.JPG

Now, assemble all the parts together.

First off all, put the grove base shield on your LinkitONE carefully. Check if the pins are placed correctly. If thats done, then connect the sensor.

We'll be using the digital pin 8 of the linkit for communication, so connect the dust sensor to that pin.

Make sure everything is secure, and handle the sensor with care so that it doesnot fall.

Connections:

Red Wire - 5v

Black write - GND

Yellow wire - Data pin 8 /D8

Adding a Temperature Sensor

IMG_0868.JPG
IMG_0839.JPG

Here i'll show you how to assemble your sensors with the board.

First, take your sensor, you'll see 3 pins in it-

1) GND

2) DATA

3) VCC

Connect your sensor to a breadboard and then connect the GND pin to GND pin of your linkit, VCC to 5V, and DATA pin to A0 pin.

Finally connect everything and lets move on to the next step!

Adding a Humidity Sensor

FUKI9J1IHEQEWOO.jpeg
F3MYDYTIHEQEWSV.jpeg

Similarly add a humidity sensor. Test that out using an ADC.

Building the Base

IMG_0686.JPG
IMG_0688.JPG
IMG_0687.JPG

we'll use the soda bottle to make the base. It'll make the work easy as 3D printing is really costly.

Adding All Components Inside Our Bottle

IMG_0680.JPG
IMG_0681.JPG
IMG_0683.JPG
IMG_0682.JPG
IMG_0818.JPG

Now hook up everything! Put your assembled circuit into the cut bottle carefullly. Be careful to put the air quality sensor outside the bottle for air. Once you are done neatly with this step, proceed to the next steps.

Taping Up All the Components in the Bottle

IMG_0684.JPG
IMG_0679.JPG

Now we'll tape up the bottle so that its tight up.

Setup Your WiFi Router for Static IP and Web Server

IMG_0901.JPG
Capture.PNG
Capture7.PNG
Capture6.PNG
Capture4.PNG

We'll need to setup a static IP for our board, for that we'll make virtual servers on our router.

Now open your gateway page. It'll give you the connection settings. Here you can forward your local IP to public IP.

Now navigate to the advanced setup option and click on "NAT". Then go to "Virtual Server Option"

Noe enter the public and local IP in the setup virtual server page. Here you can edit any of the ports you forwarded earlier.

Mine local IP is 192.168.1.3 and i'm forwarding it to 122.160.202.xx

Enter all the details correctly and save them!

Attach Your WiFi and GSM Antenna

IMG_1034[1].JPG
IMG_0826.JPG
IMG_0825.JPG
IMG_1035[1].JPG
IMG_1031[1].JPG

Now carefully attach your board's wiwi and sms antenna. We'll use them in next step.

Connecting Sensors to the Web Service

see variables.PNG
type of source.PNG
selecte line chart.PNG
make veriable.PNG
create variable.PNG
setup board.PNG

Now we'll make variables for our board. It'll transmit data to the cloud in our web service.

Writing the Code

Burn this code into your board

CODE-
#include "Barometer.h"
#include
#define WIFI_AP "iPhone"
#define WIFI_PASSWORD "helloworld1"
#define WIFI_AUTH LWIFI_WPA // choose from LWIFI_OPEN, LWIFI_WPA, or LWIFI_WEP.
// Ubidots information
#define URL "things.ubidots.com"
#define TOKEN "WF1hbsrYltg5vwGDowAejTykHigEi5" // replace with your Ubidots token generated in your profile tab
#define VARIABLEID "55d5f6047625422bxxxb0441"
#define VARIABLEID1 "55d5f5e37625xxxce1e0358f" //temprature
#define VARIABLEID2 "55d4c74xxx25424830973c35" //dust
#define VARIABLEID3 "55d5xxx7762542363264e715" //crow


Barometer myBarometer;
float temperature;
unsigned long duration;
unsigned long starttime;
unsigned long sampletime_ms = 3000;
unsigned long lowpulseoccupancy = 0;
float ratio = 0;
float concentration = 0;
int counter = 0;
void setup()
{
LTask.begin();
LWiFi.begin();
pinMode(8,INPUT);
Serial.begin(9600);
myBarometer.init();

// keep retrying until connected to AP
Serial.println("Connecting to AP");
while (0 == LWiFi.connect(WIFI_AP, LWiFiLoginInfo(WIFI_AUTH, WIFI_PASSWORD)))
{
delay(1000);
}
}
void loop()
{
temperature = myBarometer.bmp085GetTemperature(myBarometer.bmp085ReadUT()); //Get the temperature, bmp085ReadUT MUST be called first
duration = pulseIn(8, LOW);
lowpulseoccupancy = lowpulseoccupancy+duration;
ratio = lowpulseoccupancy/1000; // Integer percentage 0=>100
concentration = 1.1*pow(ratio,3)-3.8*pow(ratio,2)+520*ratio+0.62;
save_value(String(analogRead(A0)), String(temperature), String(concentration), String(analogRead(A2)));
delay(500);

}
void save_value(String value, String a, String dust, String crow){

Serial.println("Sending value to Ubidots...");
LWiFiClient c;
while (!c.connect(URL, 80))
{
Serial.println("Retrying to connect...");
delay(100);
}
String data = "{\"value\":"+ value + "}";
String thisLength = String(data.length());

// Build HTTP POST request
c.print("POST /api/v1.6/variables/");
c.print(VARIABLEID);
c.print("/values?token=");
c.print(TOKEN);
c.println(" HTTP/1.1");
c.println("Content-Type: application/json");
c.println("Content-Length: " + thisLength);
c.print("Host: ");
c.println(URL);
c.print("\n" + data);
c.print(char(26));

data = "{\"value\":"+ a + "}";
thisLength = String(data.length());

// Build HTTP POST request
c.print("POST /api/v1.6/variables/");
c.print(VARIABLEID1);
c.print("/values?token=");
c.print(TOKEN);
c.println(" HTTP/1.1");
c.println("Content-Type: application/json");
c.println("Content-Length: " + thisLength);
c.print("Host: ");
c.println(URL);
c.print("\n" + data);
c.print(char(26));
//////////////////////////////////////////////////////////
data = "{\"value\":"+ crow + "}";
thisLength = String(data.length());

// Build HTTP POST request
c.print("POST /api/v1.6/variables/");
c.print(VARIABLEID3);
c.print("/values?token=");
c.print(TOKEN);
c.println(" HTTP/1.1");
c.println("Content-Type: application/json");
c.println("Content-Length: " + thisLength);
c.print("Host: ");
c.println(URL);
c.print("\n" + data);
c.print(char(26));
///////////////////////////////////////////////////////////////////
data = "{\"value\":"+ dust + "}";
thisLength = String(data.length());

// Build HTTP POST request
c.print("POST /api/v1.6/variables/");
c.print(VARIABLEID2);
c.print("/values?token=");
c.print(TOKEN);
c.println(" HTTP/1.1");
c.println("Content-Type: application/json");
c.println("Content-Length: " + thisLength);
c.print("Host: ");
c.println(URL);
c.print("\n" + data);
c.print(char(26));
//////////////////////////////////////////////////////

// read server response

while (c){
Serial.print((char)c.read());
}

c.stop();

}

Include the Variable/sensor ID's in Code

2.PNG
1.PNG

we'll copy the variable ID's from the web service and paste it in our code.

Add Sensor Data Visualisations From the Web Service

1.PNG
2.PNG
sources button.PNG
add widget button.PNG

We'll now make some widgets on dashboard. they look nice and you'll be able to show it to your friends.

Add a Power Bank

IMG_1176.JPG
IMG_1177.JPG
IMG_1175.JPG

We'll need to add a power bank so the battery life becomes about 15 days. Mine is a 7200 mah one and gives me about 15-20 days of battery life!

Making the Web Interface (Optional)

3.PNG

Now we'll make a web interface. You can copy the embedd code in this option.

Adding Some SMS Alerts to Web Service

Capture1.PNG
Capture.PNG

Now using events tab, add some events like sending SMS and email to a person.

Finalize Everything

IMG_1033[1].PNG
IMG_1032[1].PNG
IMG_1173.JPG

Now test the SMS service!

Try keeping a burning paper near the device, and watch yourself get SMSs!

Testing It Out!

IMG_1172.JPG
IMG_1174.JPG

Now test it out!

keep your bottle anywhere in your house, and have fun with it!