Starting Class to Become a Great IoT Engineer Batch 1
The increase in population in a country is one of the development capitals. A large population can influence the development of settlements. On the other hand, settlements that are not well regulated can lead to disasters, such as fires. Fire disasters that occur can result in material and immaterial losses. Therefore, the goal of this project is none other than to produce a good fire detection system. This project has been implemented and took approximately 2 weeks. The results show that the system can function properly. The system interface uses the MIT App Inventor application.
| Part | Description |
|---|---|
| Development Board | Wemos D1 R2 |
| Code Editor | Arduino IDE 1.8.19 (Stable Legacy Version) |
| Application Support | MIT App Inventor |
| Driver | CH340 USB Driver |
| IoT Platform | Antares |
| Communications Protocol | • Inter Integrated Circuit (I2C) • Hypertext Transfer Protocol (HTTP) • Message Queuing Telemetry Transport (MQTT) |
| IoT Architecture | 4 Layer |
| Database | Firebase |
| Programming Language | C/C++ |
| Arduino Library | • ESP8266WiFi (default) • Wire (default) • AntaresESP8266MQTT by Antares (Version: 0.9.2) • MQ2_LPG by cakraawijaya (Version: 1.0.1) • LiquidCrystal_I2C by Frank de Brabander (Version: 1.1.2) • Firebase_Arduino_Client_Library_for_ESP8266_and_ESP32 by Mobizt (Version: 4.3.8) |
| Actuators | Piezo buzzer (x1) |
| Sensor | • KY-26: Fire Sensor (x1) • MQ-2: Gas Sensor (x1) |
| Display | LCD I2C (x1) |
| Other Components | • Micro USB cable - USB type A (x1) • Jumper cable (1 set) • Breadboard (x1) • Casing box (x1) |
-
Arduino IDE
https://bit.ly/ArduinoIDE_Installer
-
CH340 USB Driver
https://bit.ly/CH340_USBdriver
| Schematic Diagram | Pictorial Diagram | Block Diagram |
|---|---|---|
![]() |
![]() |
![]() |
| Infrastructure | Prototype | Systems Diagram |
|---|---|---|
![]() |
![]() |
![]() |
| Wiring |
|---|
![]() |
The difference in pinouts on the Wemos D1 R1 and R2 boards is clearly shown in the image below:
| Wemos D1 R1 | Wemos D1 R2 |
|---|---|
![]() |
![]() |
/*
=====================================================
I2C Scanner for Arduino / ESP32 / ESP8266
by: Devan Cakra Mudra Wijaya, S.Kom.
=====================================================
Functions:
- Detects all connected I2C devices
- Displays device addresses in HEX format
- Displays the total number of detected devices
=====================================================
SDA and SCL Pins for Arduino / ESP32 / ESP8266
=====================================================
Arduino I2C Connection (default):
- Arduino Uno / Nano (ATmega328P)
SDA -> A4
SCL -> A5
- Arduino Mega 2560
SDA -> D20
SCL -> D21
- Other Arduino boards
SDA -> SDA pin
SCL -> SCL pin
(Refer to the datasheet or board pinout)
ESP32 I2C Connection (default):
SDA -> GPIO 21
SCL -> GPIO 22
ESP8266 I2C Connection (default):
SDA -> GPIO 4 (D2)
SCL -> GPIO 5 (D1)
*/
// Include the Wire library for I2C communication
#include <Wire.h>
// Constant that defines the delay between scans (5000 ms = 5 seconds)
const uint32_t SCAN_INTERVAL = 5000;
// Function to initialize I2C communication
// SDA and SCL pin configuration will be adjusted automatically based on the board being used
void initI2C() {
// If the board being used is ESP32:
#if defined(ESP32)
// Enable I2C communication
// SDA = GPIO21
// SCL = GPIO22
Wire.begin(21, 22);
// If the board being used is ESP8266:
#elif defined(ESP8266)
// Enable I2C communication
// SDA = D2 (GPIO4)
// SCL = D1 (GPIO5)
Wire.begin(D2, D1);
// If the board is neither ESP32 nor ESP8266
// Examples: Arduino Uno, Nano, Mega, Leonardo, etc.
#else
// Enable I2C communication using the board's built-in hardware pins
Wire.begin();
#endif
}
// The setup() function runs once when the board is powered on or reset
// It is used to initialize hardware, serial communication, sensors, modules, and the program's initial configuration
void setup() {
// Start Serial communication at 115200 baud rate
Serial.begin(115200);
// Check whether the board uses native USB
// Examples: Arduino Leonardo, Arduino Micro, some ESP32-S2/S3 boards
#if defined(USBCON) || defined(ARDUINO_USB_CDC_ON_BOOT)
// If yes:
// The program will wait until the Serial Monitor is connected before continuing execution
while (!Serial);
#endif
// Wait for 2 seconds before starting the program
delay(2000);
// Display program header
Serial.println("====================================");
Serial.println(" I2C DEVICE SCANNER ");
Serial.println("by: Devan Cakra Mudra Wijaya, S.Kom.");
Serial.println("====================================");
// Print an empty line
Serial.println();
// Initialize I2C communication
initI2C();
}
// The loop() function runs continuously after setup() has finished
// The main program logic is typically placed inside this function
void loop() {
// Variable to store the error code returned from I2C communication
uint8_t error;
// Variable to store the I2C address currently being checked
uint8_t address;
// Counter variable for the number of detected devices
uint8_t deviceCount = 0;
// Display information indicating that the scan process has started
Serial.println("------------------------------------");
Serial.println("Scanning I2C bus...");
Serial.println("------------------------------------");
// Loop through addresses from 1 to 126
// Valid I2C addresses range from 0x01 to 0x7E
for (address = 1; address < 127; address++) {
// Start communication with the address currently being tested
Wire.beginTransmission(address);
// End the transmission and store the result
// 0 = success
// 1 = data too long
// 2 = NACK received when address was sent
// 3 = NACK received when data was sent
// 4 = other error
error = Wire.endTransmission();
// If no error occurs:
if (error == 0) {
// Display information that a device was found
Serial.print("[FOUND] Device at address 0x");
// If the address is less than 16:
// Add a leading zero to keep HEX formatting aligned
if (address < 16) {
Serial.print("0");
}
// Display the address in HEX format
Serial.println(address, HEX);
// Increment the detected device count
deviceCount++;
}
// If an unknown error occurs:
else if (error == 4) {
// Display an error message
Serial.print("[ERROR] Unknown error at address 0x");
// If the address is less than 16:
// Add a leading zero to keep HEX formatting aligned
if (address < 16) {
Serial.print("0");
}
// Display the problematic address in HEX format
Serial.println(address, HEX);
}
// If the error is neither 0 nor 4:
// Ignore it, as this usually means no device exists at that address
}
// Print an empty line
Serial.println();
// If no devices were found:
if (deviceCount == 0) {
// Display a message indicating that no devices were found
Serial.println("No I2C devices found.");
}
else { // If at least one device was found:
// Display the total number of detected devices
Serial.print("Total devices found: ");
// Display the value of deviceCount
Serial.println(deviceCount);
}
// Display information about the next scan
Serial.print("Next scan in ");
// Convert milliseconds to seconds
Serial.print(SCAN_INTERVAL / 1000);
// Display the unit in seconds
Serial.println(" seconds.");
// Empty line
Serial.println("\n");
// Wait 5 seconds before performing the next scan
delay(SCAN_INTERVAL);
} |
MQ-2 sensor calibration tutorial for LPG Gas: Click Here
-
Open the
Arduino IDEfirst, then open the project by clickingFile->Open:FP_Indobot_DevanCakraMW.ino
-
Fill in the
Additional Board Manager URLsin Arduino IDEClick
File->Preferences-> enter theBoards Manager Urlby copying the following link :http://arduino.esp8266.com/stable/package_esp8266com_index.json
-
Board Setupin Arduino IDEHow to setup the
WEMOS D1 R2board• Click
Tools->Board->Boards Manager-> Installesp8266.• Then selecting a board by clicking:
Tools->Board->ESP8266 Board->LOLIN(WEMOS) D1 R2 & mini.
-
Change the Board Speedin Arduino IDEClick
Tools->Upload Speed->115200
-
Install Libraryin Arduino IDEDownload all the library zip files. Then paste it in the:
C:\Users\Computer_Username\Documents\Arduino\libraries
-
Port Setupin Arduino IDEClick
Port-> Choose according to your device port(you can see in device manager)
-
Change the
WiFi Name,WiFi Password, and so on according to what you are currently using. -
Before uploading the program please click:
Verify. -
If there is no error in the program code, then please click:
Upload. -
If there is still a problem when uploading the program, then try checking the
driver/port/otherssection.
-
Getting started with Antares :
• Please Sign Up first.
• Then please Sign In to access the service.
-
Activate Access Key :
• Go to
Accountmenu.• Click
Get Access Keyto generate an access key. This process only needs to be done once.• If you have activated an access key before, skip this step.
-
Create applications :
• Go to
Applicationsmenu.• Click
+ Create an Application.• In the
Add Applicationmenu, please specify the following :Application Name->Name of the App you will create.Application ID->ID of the App you will create.Labels-> determine according to project needs.
-
Create a device :
• Make sure you are on the
Home / Applications / The app you createdmenu.• Click
+ Add Device.• You should specify the name of this device based on the variables in the project.
-
Firmware configuration :
• Make sure you are on the
Accountmenu.• Copy
Access Keymentioned.• Paste in the firmware code, for example like this :
#define ACCESSKEY "1444e88d02acb758:b996115b1c2f6f0f"
• Then, the
Project nameandDevice namemust match what was created earlier. For example :#define projectName "Final_Project_Indobot_Academy_2023" #define deviceName "Smart_Fire_Smoke_Detector"
-
Open the official website
Firebase:https://console.firebase.google.com/
-
Create a project with a free name.
-
Click
gear symbolnext toProject Overview-> Then selectProject settingsto get theFirebaseToken. -
Click
Realtime Databaseto get theFirebaseURL.
-
Open the official website
MIT App Inventor:https://appinventor.mit.edu/
-
Click
Create Apps!, then log in using google account. -
Click
Project-> then import the files in theSmart-Fire-Smoke-Detector-Berbasis-IoT-Mobile\Src\MIT App Inventor Project\directory :Smart_Fire_Smoke_Detector.aia
-
Click
FirebaseDB1then set the following 3 points:•
FirebaseToken-> fill withTokenobtained from theProject settingssection.•
FirebaseURL-> fill withURLobtained from theRealtime Databasesection.•
ProjectBucket-> fill withDB Container. In this case it isDetect.
-
Then click
Connect-> next selectAI Companion. -
Open your smartphone, then in the
Google Play Storesearch for theMIT AI2 Companionapplication, then install it. -
Open the
MIT AI2 Companionapp. -
Select
Scan QR Codemethod. -
Point your smartphone at the
QR Codearea on theMIT App Inventorsite.
-
Download and extract this repository.
-
Make sure you have the necessary electronic components.
-
Make sure your components are designed according to the diagram.
-
Configure your device according to the settings above.
-
Please enjoy [Done].
| MIT App Inventor | Device | Firebase | Antares |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
| Simulation of Monitoring with Mobile Apps | |
|---|---|
![]() |
![]() |
If this work is useful to you, then support this work as a form of appreciation to the author by clicking the ⭐Star button at the top of the repository.
This application is my own work and is not the result of plagiarism from other people's research or work, except those related to third party services which include: libraries, frameworks, and so on.
MIT License - Copyright © 2022 - Devan C. M. Wijaya, S.Kom
Permission is hereby granted without charge to any person obtaining a copy of this software and the software-related documentation files to deal in them without restriction, including without limitation the right to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons receiving the Software to be furnished therewith on the following terms:
The above copyright notice and this permission notice must accompany all copies or substantial portions of the Software.
IN ANY EVENT, THE AUTHOR OR COPYRIGHT HOLDER HEREIN RETAINS FULL OWNERSHIP RIGHTS. THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, THEREFORE IF ANY DAMAGE, LOSS, OR OTHERWISE ARISES FROM THE USE OR OTHER DEALINGS IN THE SOFTWARE, THE AUTHOR OR COPYRIGHT HOLDER SHALL NOT BE LIABLE, AS THE USE OF THE SOFTWARE IS NOT COMPELLED AT ALL, SO THE RISK IS YOUR OWN.














