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

by technolabcreationindia in Circuits > Arduino

9 Views, 0 Favorites, 0 Comments

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

Screenshot (139).png

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.

Supplies

Screenshot (141).png

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.

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.

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.

Integrating the 4G LTE Modem:

Screenshot (126).png
Screenshot (127).png

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.

Screenshot (128).png
Screenshot (129).png

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

  • This article is sponsored by JLCPCB, a leading manufacturer specializing in PCB prototype and fabrication. With their fully automated production lines housed in their own factories, they guarantee excellent quality and consistency in their products, adhering to certifications such as ISO 9001:2015, ISO 14001:2015, and IPC-6012E.
  • JLCPCB is not only renowned for its high-quality PCBs but also for its extraordinary savings and guaranteed satisfaction. They offer a range of services including PCB assembly with over 350, 000 in-stock parts, 3D printing with various materials like resin, nylon, and metal, and high-precision SMT stencils created with state-of-the-art LPKF machines.
  • Experience fast and stable delivery with JLCPCB, where over 98% of orders are shipped on time, allowing you to iterate your projects more freely with their low-cost and fast-turnaround services. Moreover, their friendly support team is available 24 hours a day through email, live chat, and phone to assist you at any time.
  • Choose JLCPCB as your PCB partner to enjoy quality products, extraordinary savings, and guaranteed satisfaction.

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);
}

Click here to read the detailed Explanation of this code.

Connection Diagram.

Screenshot (138).png

Make all the connection as per the Above Connection diagram.

Lets See in Action.

Screenshot (142).png
Screenshot (139).png

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.

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

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


Thank you so much for reading.