Request Sensor Data Using 4G LTE Modem & Arduino Uno | DHT22.

Request Sensor Data Using 4G LTE Modem & Arduino Uno | DHT22.

Request Sensor Data Using 4G LTE Modem & Arduino Uno | DHT22.

Introduction.

In an era where monitoring and automation are becoming increasingly significant in both industrial and residential environments, the need for efficient and reliable monitoring systems is paramount. This article delves into the creation of a robust GSM-based temperature and humidity monitoring system using Arduino. This system is designed to read environmental data using a DHT22 sensor, display the readings on an LCD, and enable remote data access via SMS using a GSM module.

System Overview

The system is built around several key components:

  • Arduino Uno: The central controller for managing sensor data readings, display outputs, and GSM communications.
  • DHT22 Temperature and Humidity Sensor: Provides accurate readings of the ambient temperature and humidity.
  • 16×2 LCD Display with I2C Interface: Shows real-time temperature and humidity data for local monitoring.
  • 4G LTE Modem: Enables SMS communication, allowing users to receive sensor data remotely on their mobile phones.

1.Connecting the DHT22 Sensor:

  • The DHT22 sensor is connected to digital pin 2 of the Arduino. This pin reads the digital signal outputted by the sensor, which contains the temperature and humidity data.

2.Setting Up the LCD Display:

  • The LCD is connected via the I2C bus, reducing the number of pins needed for interfacing. The typical I2C address for these displays is 0x27, but it can vary and should be confirmed with an I2C scanner sketch.

3.Integrating the 4G LTE Modem:

  • The 4G LTE Modem is connected through a software serial port using pins 9 (RX) and 10 (TX). This setup allows the Arduino to communicate with the module to send and receive SMS messages.

The backbone of this project is a 4G LTE module, supported by JLCPCB SMT Assembly Services.For those interested in the technical details, I’ve covered the features and specifications of this 4G LTE module in a dedicated Article. This includes its advantages over traditional 2G GSM modules and guidance on connecting it with an Arduino Uno board.Click here to read the full Article.

PCB Design.

After making the Schematic, Convert it into PCB, Arrange and place all the components in desirable places, Once the layout is ready route the wiring and complete the design of PCB.

JLCPCB.

  • In this project, a crucial component is the precision and reliability provided by the 4G LTE Module, a product that came to fruition with the expertise of JLCPCB. As the leading PCB (Printed Circuit Board) manufacturing company, JLCPCB offers state-of-the-art SMT (Surface Mount Technology) assembly services that enable hobbyists and professionals alike to bring their electronic projects to life with ease and affordability.
  • Whether you’re building a simple DIY project or developing complex industrial applications, JLCPCB has the capabilities to meet your needs. They provide a fast turnaround on orders, often shipping within 24 hours, and their pricing is transparent and highly competitive, making high-quality PCBs accessible to everyone.
  • What sets JLCPCB apart is their commitment to quality and customer service. Their website, JLCPCB, offers a user-friendly experience where you can easily upload your PCB design files, view instant quotes, and track the production process in real-time. With JLCPCB’s robust service offerings, you’re not just purchasing a product; you’re investing in a partnership that empowers your innovations.
  • For those who are curious about integrating JLCPCB’s services into your own projects, I encourage you to explore their website and discover the various services they offer that can enhance your electronic designs. This project wouldn’t have been possible without their exceptional PCB assembly service, proving that JLCPCB is not just a supplier, but a critical partner in the world of electronics.

JLCPCB's Multi-Color Silkscreen PCBs.

  • JLCPCB—their Multi-Color Silkscreen PCB service. This cutting-edge service allows the integration of multiple colors onto the surface of printed circuit boards, transforming standard PCBs from purely functional components into visually striking elements of any hardware project.
  • Traditional silkscreen PCBs typically feature monochromatic designs, limiting their use to functional labels for component placements and simple logos. JLCPCB has revolutionized this by introducing their Multi-Color Silkscreen service, which supports vibrant and detailed graphics, enhancing both the aesthetics and functionality of your PCBs. Whether it’s intricate logos, detailed graphical instructions, or simply artistic designs, JLCPCB’s service enables a new level of creative expression.
  • Utilizing premium UV curable inks that are both eco-friendly and resilient against fading and heat, JLCPCB ensures that your designs are not only striking but durable. The process is simple and integrated with JLCPCB’s online platform, where you can upload and manage your designs easily. Their state-of-the-art 6-color UV printer guarantees ultra-high resolution prints, making it possible to achieve exceptional detail on every PCB.
  • Additionally, JLCPCB offers this service at a starting price of just $4.7, adding only a day to the standard production timeline, which makes it a cost-effective and timely solution for enhancing your electronic projects. To help users get started, JLCPCB has also introduced a limited-time offer that includes a special discount for those who join their official user group.
  • For more detailed guidance on designing with Multi-Color Silkscreen, JLCPCB provides comprehensive support through EasyEDA tools, making it easy for anyone from hobbyists to professional designers to bring their colorful PCBs to life.

Code.

#include <DHT.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>

// GSM Module connection
SoftwareSerial gsmSerial(9, 10); // RX, TX pins

// DHT Sensor setup
#define DHTPIN 2          // Pin connected to the DHT22 sensor
#define DHTTYPE DHT22     // Specify DHT22 type
DHT dht(DHTPIN, DHTTYPE);

// Initialize the LCD - adjust the I2C address if needed
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup() {
  Serial.begin(9600);          // Start Serial communication
  gsmSerial.begin(115200);       // Start GSM module communication
  dht.begin();                 // Initialize DHT sensor
  lcd.begin();                 // Initialize LCD
  lcd.backlight();             // Turn on LCD backlight

  // Display welcome message
  lcd.clear();
  lcd.setCursor(0, 0); // First line
  lcd.print("Sensor Data Mon."); 
  lcd.setCursor(0, 1); // Second line
  lcd.print("by technolab"); 
 delay(3000); // Keep the message for 3 seconds

  // After the welcome message, proceed with initialization
  lcd.clear();
  lcd.print("Initializing...");
  delay(2000); // Delay for GSM module to initialize

  // Setup GSM module for SMS
  sendATCommand("AT+CMGF=1", "OK", 2000); // Text mode
  sendATCommand("AT+CNMI=1,2,0,0,0", "OK", 2000); // New SMS indication

  lcd.clear();
  lcd.print("Getting Ready");
}

void loop() {
  static unsigned long lastUpdate = 0;
  unsigned long currentTime = millis();

  // Continuously display temperature and humidity every 10 seconds
  if (currentTime - lastUpdate > 10000) {
    lastUpdate = currentTime;
    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature();
    lcd.clear();
    lcd.setCursor(0, 0); // First line
    lcd.print("Updating....");
    delay(500);
         

    lcd.clear();
    lcd.print("Temp: ");
    lcd.print(temperature);
    lcd.print(" C");
    lcd.setCursor(0, 1); // Move to second line
    lcd.print("Hum: ");
    lcd.print(humidity);
    lcd.print(" %");
  }

  // Check for incoming SMS
  if (gsmSerial.available()) {
    if (gsmSerial.find("+CMT:")) {
      String smsCommand = gsmSerial.readString();
        lcd.clear();
         lcd.setCursor(0, 0); // First line
         lcd.print("SMS Received");
         delay(500);
      smsCommand.toUpperCase(); // Convert command to uppercase

      if (smsCommand.indexOf("STATE") != -1) {
        float humidity = dht.readHumidity();
        float temperature = dht.readTemperature();
        String message = "Temp: " + String(temperature) + "C, Hum: " + String(humidity) + "%";

        sendSMS(message); // Respond with temperature and humidity via SMS
      }
    }
  }
}

void sendATCommand(String command, const char* expectedResponse, unsigned long timeout) {
  gsmSerial.println(command); // Send the AT command
  long int time = millis();
  while ((time + timeout) > millis()) {
    while (gsmSerial.available()) {
      if (gsmSerial.find(const_cast<char*>(expectedResponse))) {
        Serial.println(command + ": SUCCESS");
         return;
      }
    }
  }
  Serial.println(command + "FAILED");
  lcd.clear();
         lcd.setCursor(0, 0); // First line
         lcd.print(command + "FAILED"); 
         delay(1000);
  
}

void sendSMS(String message) {
  lcd.clear();
         lcd.setCursor(0, 0); // First line
         lcd.print("Sending......");
  String phoneNo = "+918543053029"; // Replace with the sender's phone number
  sendATCommand("AT+CMGS=\"" + phoneNo + "\"", ">", 2000); // Prepare to send SMS
  gsmSerial.println(message); // Send the message content
  delay(500);
  gsmSerial.write(26); // ASCII code for CTRL+Z to send the SMS
  Serial.println("SMS Sent: " + message);
  lcd.clear();
         lcd.setCursor(0, 0); // First line
         lcd.print("Data Send");
         delay(500);
}
Include Libraries and Define Connections
#include <DHT.h>
#include <SoftwareSerial.h>
#include <LiquidCrystal_I2C.h>

  • <DHT.h>: Includes the library for the DHT sensor to read temperature and humidity.
  • <SoftwareSerial.h>: Includes the library for software serial communication, allowing for serial communication on other digital pins of the Arduino.
  • <LiquidCrystal_I2C.h>: Includes the library for controlling LCD displays that are connected via the I2C bus.

SoftwareSerial gsmSerial(9, 10); // RX, TX pins

  • gsmSerial(9, 10): Creates a software serial object for communication with the GSM module using pin 9 as RX and pin 10 as TX.

Sensor and Display Setup

#define DHTPIN 2          
#define DHTTYPE DHT22     
DHT dht(DHTPIN, DHTTYPE);
LiquidCrystal_I2C lcd(0x27, 16, 2);

  • DHTPIN and DHTTYPE: Defines pin 2 for the DHT sensor and specifies the type of DHT sensor (DHT22).
  • lcd(0x27, 16, 2): Initializes the LCD object for a 16×2 display with the I2C address 0x27.

setup() Function

void setup() {
  Serial.begin(9600);
  gsmSerial.begin(115200);
  dht.begin();
  lcd.begin();
  lcd.backlight();

  • Initializes serial communication at 9600 baud for debugging, starts the GSM module at 115200 baud, initializes the DHT sensor, and sets up and turns on the LCD backlight.

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Sensor Data Mon."); 
  lcd.setCursor(0, 1);
  lcd.print("by technolab"); 
  delay(3000);

  • Clears the LCD display, sets the cursor, and prints a welcome message. Delays for 3 seconds before proceeding.

  lcd.clear();
  lcd.print("Initializing...");
  delay(2000);

  • Shows an initializing message as the system sets up, particularly the GSM module.

  sendATCommand("AT+CMGF=1", "OK", 2000); // Text mode
  sendATCommand("AT+CNMI=1,2,0,0,0", "OK", 2000); // New SMS indication
  lcd.clear();
  lcd.print("Getting Ready");
}

  • Sends AT commands to the GSM module to set SMS text mode and configure how new SMS messages are indicated. Displays “Getting Ready”.

loop() Function

void loop() {
  static unsigned long lastUpdate = 0;
  unsigned long currentTime = millis();

  • Defines a static variable to keep track of the last update time and checks the current time.

  if (currentTime - lastUpdate > 10000) {
    lastUpdate = currentTime;
    float humidity = dht.readHumidity();
    float temperature = dht.readTemperature();
    lcd.clear();
    lcd.print("Temp: ");
    lcd.print(temperature);
    lcd.print(" C");
    lcd.setCursor(0, 1);
    lcd.print("Hum: ");
    lcd.print(humidity);
    lcd.print(" %");
  }

  • If 10 seconds have passed since the last update, reads new temperature and humidity data, clears the LCD, and displays the new values.

SMS Handling

  if (gsmSerial.available()) {
    if (gsmSerial.find("+CMT:")) {
      String smsCommand = gsmSerial.readString();
      lcd.clear();
      lcd.setCursor(0, 0);
      lcd.print("SMS Received");
      delay(500);
      smsCommand.toUpperCase();

  • Checks if data is available from the GSM module. If an SMS is received (+CMT:), it reads the SMS, clears the LCD, and displays that an SMS was received.

      if (smsCommand.indexOf("STATE") != -1) {
        float humidity = dht.readHumidity();
        float temperature = dht.readTemperature();
        String message = "Temp: " + String(temperature) + "C, Hum: " + String(humidity) + "%";
        sendSMS(message);
      }
    }
  }
}

  • Checks if the received SMS

Connection Diagram.

Make all the connection as per the below connection diagram.

Lets See in Action.

As soon as the system is powered up, it begins to boot. During this startup phase, an LCD screen displays a welcome message: “Sensor Data Monitoring by Technolab.” It takes a few seconds for the system to fully prepare. Once booted, the LCD continuously displays the current temperature and humidity readings. These readings are updated in real-time every 10 seconds, ensuring up-to-date environmental data.

Additionally, the system allows for remote data retrieval via SMS. To request sensor data, simply open your messaging app and send a text with the word “STATE” to the number linked to the 4G LTE module in the system. Upon receiving the request, the system sends an SMS back with the current temperature and humidity values. This process can be repeated at any time to obtain the latest readings.

This project offers a convenient and effective method to monitor environmental conditions in real time, both directly via LCD and remotely through your phone.

Video Tutorial.

That’s it for this Article. I hope you found it informative. 

Thank you so much for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *

Back To Top