IoT based automation with Feedback using Raspberry Pi, WROOM32 and a Android Phone

Hello Friends,
IoT i.e Internet of Things is a term we all get to hear more often these days. Two machines talking to each other is something we could've hardly imagined a decade ago and today IoT forms a base of growing technology in the digital world. It is present in almost our every activity, right from when we wake up and receive reminders about a scheduled Zoom Meeting, or a booked flight or an aunts birthday from Google calendar to when we go to bed with our Digital Wrist Band which probably is accumulating and analyzing your health data and monitoring your health while you are deep asleep. Having a deep understanding of IoT and related concepts, applications and challenges like security and privacy is therefore essential.  
So let's dive into the Project.

We will need
1. A smartphone
2. Raspberry Pi 4 and later versions (or a WiFi adaptor if you have an earlier version of Pi)
3. ESP WROOM32 board
4. 1K potentiometer (for calibration)
5. LDR
6. Relay module


Step 1: Create a Firebase Database
Create a firebase database to store and update the information regarding User Command and the Status of the Lights. Although a lot of other online real-time platforms are available like ThingSpeak, RethinkDB, restdb.io etc... but we choose Firebase as its directly supported by MIT App inventor (our App building platform) and is pretty simple to use. A lot of video tutorials are available to give a walk through the process of creating a real-time database on Firebase.

Step 2: Create a Mobile App using MIT App Inventor
Make an Android App for our project using MIT App Inventor:
We will make an Android App that will listen to the command from the user and update a tag in the firebase database accordingly. The code for this Application can be found here


Download the project file, open MIT App inventor and export the downloaded .aia file from the project. Edit the firebase URL and enter Authentication Key.
Step 3: Interface LDR to ESP WROOM 32 and upload the code using Arduino IDE




Install the libraries following this tuitorial
As we can see, LDR and a 1K potentiometer are connected in a potential divider arrangement,
and Vout is connected to pin no. 34 of ESP Wroom32. LDR will sense the ambient light intensity
with the help of it's inbuilt ADC. We program it using Arduino IDE to sense the ambient light and
 update the status tag in the firebase database. The program for this can be found here.

We can also observe the digital output values on the Serial Monitor of Arduino IDE and decide the
 threshold value according to the light intensity reading when lights are turned OFF and when they
 are turned ON. 
Step 4: Interfacing lamp to Raspberry Pi
One can use only one board instead of two as both have inbuilt WiFi adaptors. Here we choose to use two boards to demonstrate a example where the sensor (LDR connected to WROOM32) and the actuator (Relay module connected to Raspberry Pi) are at two different places. Also,one has to keep in mind that Raspberry Pi doesn't have a inbuilt ADC, so one will have to use a external ADC like MCP3008 (SPI output ADC) to interface LDR to RPi.


The Signal input of the relay is connected to GPIO pin 7 of Raspberry Pi. We now write a python script that reads the tag updated by the user command and performs the ON-OFF action accordingly.
One the script is ready and tested, we will now create a cronjob scheduled at every reboot which will execute our script.
The python script can be found here 


Limitations: Anyone with the App can control the lights. This can be overcome by setting the required access permissions in the firebase database. 
Suggested extensions: External interrupt pin can be used to interface the sensor, in order to save the processor from continuously looking for a change in the status. (This will need the use of a comparator as signal conditioning and converting the sensor data into a digital signal). 


Comments

Popular posts from this blog

Real Time Object Tracking using Simulink and Raspberry Pi

Development and implementation of real time face recognition systems