IoT-project-applied-to-home-automation
IoT project to measure temperature and humidity in a room and to control a lamp state
- Active · last change 3-18-2025
- ★ 3 on GitHub
README
IoT project applied to home automation This is a simple project dedicated to the sensing and controlling some physical variables in a room. The variables to be measured are temperature, humidity and light intensity. The state of a lamp is controlled remotely through the Internet.
The devices chosen in this project are: - IoT board: Wemos D1 R2
This is a board based on the chip ESP8266 [1], which has a 32-bits CPU, 17 GPIO, 1 analog to digital converter with 10 bits of resolution, UART, SPI and I2C serial ports, and is capable of connecting to a WiFi acces point using the IEEE 802.11 b/g/n protocol.
- Temperature and humidity sensor DHT22 [2]
This is a cheap sensor able to measure temperatures between -40°C a 80°C with a precision <±0.5°C and a resolution of 0.1°C. The relative humidity can be measured between 0% and 100%, with a precision of 2% RH and a resolution of 0.1%RH. Data is delivered as a digital signal in an output pin.
- Light intensity sensor based on an LDR [3]
This is a simple module which measures the light intensity using an LDR. It has an onboard potenciometer to adjust the threshold level from 0 to 1, this state is displayed on a digital output pin.
- Relay with 3 contacts: common, normally open and normally close.
The following figure shows the layout of the devices used in this project connected.

The communication between the IoT board and other clients is made through the MQTT broker test.mosquitto.org [4]. This is a broker deployed in the cloud which manages the communication between clients in a net using the MQTT application layer protocol [5].
The IoT board was programmed using the Arduino IDE in C. The code allows the board to connect to a WiFi acces point using the ESP8266WiFi.h library [6]. The MQTT protocol was implemented using the PubSubClient.h library [7].
The board sends messages on a topic head reporting the values of the temperature, humidity, and the states of the relay and of the lamp upon request. Additionally, a message reporting the state of the lamp is sent periodically at each 10 sec.
An Android application has been developed for communication with the IoT board. This app has been developed using the RAD Studio 11 Alexandria IDE [8]. The MQTT protocol has been implemented using the TMS MQTT components [9].
This app allows the connection to a broker, and reports all messages received from the IoT board in a window. Temperature and humidity are reported on the screen and the state of the lamp is shown in a picture where the image is the lamp on or the lamp off, according its state. Clicking on this picture allows the user to toggle the state of the lamp.

[1] ESP8266EX datasheet, https://www.espressif.com/sites/default/files/documentation/0a-esp8266ex_datasheet_en.pdf
[2] DHT22 datasheet, https://cdn.sparkfun.com/assets/f/7/d/9/c/DHT22.pdf
[3] Light intensity sensor, https://programarfacil.com/blog/arduino-blog/ldr-arduino/
[4] Mosquitto, test.mosquitto.org. MQTT broker, http://test.mosquitto.org/
[5] MQTT: The standard for IoT messaging, http://mqtt.org/
[6] ESP8266WiFi.h library, https://github.com/esp8266/Arduino/tree/master/libraries/ESP8266WiFi
[7] O'Leary, N.: Pubsubclient: Arduino client for MQTT, https://github.com/knolleary/pubsubclient
[8] RAD Studio IDE, https://www.embarcadero.com/products/rad-studio
[9] TMS MQTT, Components TMS MQTT for RAD Studio, https://www.tmssoftware.com/site/tmsmqtt.asp

