Be Aware- Kids Nearby!

by chenhillel1 in Workshop > Home Improvement

358 Views, 0 Favorites, 0 Comments

Be Aware- Kids Nearby!

34.jpg

It happened to almost every person, child touched or destroyed something valuable.

Our device will help detect when someone is approaching the product, it will send an alert to the owner's mobile phone and also alert with an alarm beep until the person will move away from the product.

Supplies

Hardware

1 X ESP8266 board

1 X HC- SR04

1x LDR

1 X Arduino Speaker

2 X 330 ohm resistor

1X LED

15 X Arduino jumper cables

1 X micro USB cable

1 X Breadboard (to connect everything together)

Software

Arduino program

Blynk (download to your mobile phone)

Adafruit.io user

Config ESP8266

1.jpg
WhatsApp Image 2020-03-06 at 11.49.58.jpeg

first, if you haven't done it already, download the Arduino program.

now we want to connect the ESP8266, this is a low-cost WIFI microchip.

connect the micro usb to the component and put it on your breadboard for your convenience.

You can use the image above when you do it yourself.

now to config this component to your Arduino program, you can use this excellent guide:

https://randomnerdtutorials.com/how-to-install-esp8266-board-arduino-ide/

Includes

2.JPG

in the top of your Arduino project, you want to include few libraries.

the first one will help you to connect to the ESP8266.

the last one will help you to connect to the Blynk app usin WIFI.

all others will help you to transfer data to Adafruit.io.

ESP8266

4.JPG

To make the ESP8266 work and to be connected to the Blynk app you want to define in your code the details of the WIFI you are connected to.

in the WLAN_SSID you need to fill the name of your WIFI.

in the WLAN_PASS you need to fill your WIFI password.

Connect to Blynk App

6.jpg
7.jpg

if you don't have the Blynk app, you need to download it now.

after you downloaded the app and created a user, you want to open a new project.

you can use the photo above as an example.

after the project was created, you will get an email with an Auth Token. we will use it in the next step.

Config Blynk in Your Code

8.JPG

now we want to define the following lines.

the ESP_SSID is the name of the WIFI user.

the ESP_PASS is the password of the WIFI.

in "auth[]" you need to fill the auth token you received by email.

Code

to setup the Blynk app use this line:

Blynk.begin(auth, ssid, pass);

in the beginning of the loop you should put the next line:

Blynk.run();

you can watch the full code in the end of this guide :)

Connect the SC-SR04

9.png

connect the SC-SR04 to the breadboard according to this picture.

this component will help you to check if someone is coming next to your valuable object.

Code

14.JPG

define the pins according to the connections you made.

#define echoPin D5 // Echo Pin
#define trigPin D6 // Trigger Pin

(D5 and D6 in our example)

define the following-

long duration, distance_data; // Duration used to calculate distance

don't forget to setup-

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

the code above is belong to the loop,

it calculates the distance from any object to our product.

.

Connect the LDR

15.jpg

connect the LDR using the photo above.

the connection to the Arduino is same for the ESP8266.

Code

16.JPG

define the following-

const int ledPin = 5;
const int ldrPin = A0;

don't forget to setup-

pinMode(ledPin, OUTPUT);
pinMode(ldrPin, INPUT);

the code above is the calculation in every loop.

Blynk Notifications

17.jpg
18.jpg

in the project you opened,

tap on the screen and choose notifications.

now you can see it on your board.

Code

19.JPG

now we want to make the connection.

create the connection function. you need to call it at the end of the setup.

you also need to check the connection is open at the beginning of the loop:

// ping adafruit io a few times to make sure we remain connected
if (! mqtt.ping(3)) {

// reconnect to adafruit io

if (! mqtt.connected()) {

connect();

}

}

Connect the Speaker

20.png

now we want to connect the speaker, you can use the picture above.

the purpose of the speaker is to make sound if someone is coming close to the object.

Code

define the speaker-

int Speaker = 13; // GPIO13

you also need to setup-

pinMode(Speaker, OUTPUT);
digitalWrite(Speaker, HIGH);

Notification and Noise

22.JPG

this part is at the end of the loop,

we will check the relevant values and send a notification and sound when someone is getting close to your object.

you can use our music (in the code) or define anything you want to.

Hardware

23.jpg

now your hardware should look similar to the picture above.

Adafruit.io

24.JPG

we want to see the log of the distance in the adafruit.io.

first, you need to create a user.

after you create a user, you need to save your Key value- we will use it in the next level. you can see in the picture above how to find the key product.

Define Adafruit.io

25.JPG

define your account using this lines-

#define AIO_SERVER "io.adafruit.com"

#define AIO_SERVERPORT 1883

#define AIO_USERNAME "****"

#define AIO_KEY "aio_LOsr380zMS0xHlfCWdECFzjhDRul"

AIO_USERNAME is the user name of your account.

AIO_KEY is the key from the last step.

the code above (you can find it at the end of this guide) is the feeds you want to create, in our example the feed is "distance".

Create Distance Chart

26.JPG
27.JPG

create a new block,

choose the kind of block you want to see (it can be a log, chart and many other options).

28.JPG
29.JPG

choose the value you want to track and then put the relevant details.

Publish Data

30.JPG

publish data using this lines:

// Publish data
if (! distance.publish((int)distance_data)) {

Serial.println("Failed to publish temperature");

} else {

Serial.println("Distance published!");

}

//Delay 50ms before next reading.

delay(5000); }

Run!

31.JPG
WhatsApp Image 2020-03-06 at 10.39.21.jpeg

run your arduino code :)

when someone is getting close to the object:

1. you will get a notification in your phone.

2. you can see the history of distances in adafruit.io

3. you will hear an alarm that won't stop until the person will go away.

4. you can add a led that will turn on (optional)

Code

you can use this full code :)

Downloads

Illustration

https://drive.google.com/open?id=1gMBL5vJBsMn7VVsiwUFVhBp9QX2RCwwY