This is an old revision of the document!


Smart room monitoring and control system

Author: Claudiu-Catalin Pumnea - SRIC

Short Description of the project

The “Smart room monitoring and control system” is an innovative project that focuses on collecting environment parameters and leveraging them to control the lights and outlets of a kitchen. The system utilizes a range of sensors including a water level detection sensor, a temperature and humidity sensor, and a gas sensor. Additionally, a control module equipped with two relays is employed for managing the lights and outlets.

To provide users with real-time data and control functionality, a web application has been developed. The web app features intuitive graphs displaying the humidity and temperature readings, allowing users to visualize the environmental conditions in the kitchen. Furthermore, the app provides the capability to control the status of the relays, enabling users to remotely manage the lights and outlets for enhanced convenience and energy efficiency.


Hardware

To develop this project, the following components were utilized:

  • Water Level Detection Sensor: This sensor enables the system to detect and monitor the water level within the kitchen, providing valuable information in the event of flooding or water leakage.
  • Temperature and Humidity Sensor (DHT11): The DHT11 sensor measures the temperature and humidity levels in the kitchen, allowing for precise environmental monitoring and control.
  • Gas Sensor (MQ2): This sensor measures the level of gas in the kitchen, providing crucial information for safety and preventing potential hazards.
  • Module with Relays: A module equipped with two relays is employed to manage the kitchen's electrical devices. The relays enable control over the lights and outlets, enhancing convenience and energy management.
  • EspWROOM32: Microcontroller that integrates Wi-Fi (802.11 b/g) and Bluetooth (dual mode version 4.2) capabilities. It serves as the core of the project, enabling data collection from sensors and transmitting the it to a database through requests. Additionally, the ESP32 is responsible for controlling various components of the system, such as managing lights and outlets in the kitchen.

Software

Technologies used in the project:

  • HTML5: It the latest version of the Hypertext Markup Language and is used for structuring and presenting the content of web pages.
  • CSS (Cascading Style Sheets): CSS is a style sheet language used to describe the visual presentation of HTML documents. It is used to enhance the appearance and layout of web pages.
  • TypeScript & TypeORM: TypeScript is a superset of JavaScript that adds static typing and additional features to the language. It enhances code maintainability and provides improved tooling support. TypeORM is an Object-Relational Mapping (ORM) library that simplifies database interactions in TypeScript/JavaScript projects.
  • Nest.js: Nest.js is a framework for building server-side applications using TypeScript. It leverages the capabilities of Node.js and provides a modular, scalable, and opinionated structure for building back-end applications.
  • PostgreSQL: PostgreSQL is an open-source relational database management system (RDBMS) known for its reliability and robustness. It is used for storing and managing structured data in the project.

These technologies form the foundation of the project, combining front-end (HTML, CSS, JavaScript), back-end (Node.js, Nest.js), and database (PostgreSQL) components to create a comprehensive web application with enhanced functionality and a reliable data storage system.

Code description

Used Libraries

#include <DHT.h>
#include <string.h>
#include <HTTPClient.h>
#include <WiFi.h>
#include <ArduinoJson.h>

Constants and global variables

#define LIGHT_RELAY_PIN 18
#define CURRENT_OUTLET_RELAY_PIN 4

//Water level sensor
#define WATER_LEVEL_SENSOR_PIN 34

//Gas sensor
#define GAS_SENSOR_MQ2_PIN 35

//Temperature sensor
#define DHTPIN 19
#define DHTTYPE DHT11
DHT dht(DHTPIN, DHTTYPE); //Initialize dht

//Room and apartment constants
const char* roomType = "Kitchen";
const int apartmentNumber = 49;

//Initialize Docs
DynamicJsonDocument getInitializeDoc(2048);
DynamicJsonDocument getRelayStatusDoc(2048);

////Wifi credentials
const char* ssid = "yourWifiNameHere";
const char* password = "yourWifiPasswordHere";


//Initialize wifiClient and httpClient
WiFiClient client;
HTTPClient http;

//Flags if relays exists

bool currentOutletRelayExists = true;
bool lightRelayExists = true;

//Counter for sending the post message
int counter = 0;

//Declare gas_value and wate_level_value
float gas_value ;
float water_Level_value ;

Setup

void setup() {

Serial.begin(9600);
setupWiFi();
initializePins();
initialize_board();

}

SetupWiFi function

void setupWiFi() {
  WiFi.begin(ssid, password);
  Serial.print("\n Connecting to Wifi");
  
  pinMode(2, OUTPUT);
  while ( WiFi.status() != WL_CONNECTED) {
    Serial.print(".");
    digitalWrite(2, HIGH);
    delay(250);
    digitalWrite(2, LOW);
    delay(250);
  }

  digitalWrite(2, HIGH);
  Serial.println("\n Connected to the WiFi network");
  Serial.print("\n IP address: ");
  Serial.print(WiFi.localIP());
  
}

initializePins function

void initializePins() {

  pinMode(LIGHT_RELAY_PIN, OUTPUT);
  pinMode(CURRENT_OUTLET_RELAY_PIN, OUTPUT);
  pinMode(GAS_SENSOR_MQ2_PIN, INPUT);
  pinMode(LIGHT_CURRENT_SENSOR_PIN, INPUT);
  pinMode(OUTLET_CURRENT_SENSOR_PIN, INPUT);

  //Setting the initial state of the relays
  digitalWrite(LIGHT_RELAY_PIN, HIGH);
  digitalWrite(CURRENT_OUTLET_RELAY_PIN, HIGH);
  dht.begin();

}
iothings/proiecte/2022sric/smart-room-monitoring-and-control-system.1685665701.txt.gz · Last modified: 2023/06/02 03:28 by claudiu.pumnea
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0