Sitemap / Advertise

Introduction

Via SMS messages; control a fan and observe the temperature, humidity, and gas status of your room.


Tags

Share

SIM808 Remote Cooling Fan w/ Weather and Gas Station

Advertisement:


read_later

Read Later



read_later

Read Later

Introduction

Via SMS messages; control a fan and observe the temperature, humidity, and gas status of your room.

Tags

Share





Advertisement

Advertisement




    Components :
  • [1]Arduino Uno
  • [1]SIM808 GPS/GPRS/GSM Shield
  • [1]3-wire Serial LCD Module
  • [1]DHT11 Temperature and Humidity Sensor
  • [1]MQ-135 Gas Sensor
  • [1]2-Way Relay
  • [1]20V External Battery
  • [1]SIM Card
  • [1]Jumper Wires

Description

I had a problem with my room temperature lately due to enervating heat during summer, especially when I went outside and returned after a few hours. Unfortunately, my cooling fan placed in my room was able to, scarcely, be on or off via a control switch while plugged in. And, I did not want to acquiesce that only feature. So, I contemplated this project to be able to control my cooling fan and get information about the temperature and humidity of my room while I am away, via SMS messages. To get the temperature and humidity values, I used a DHT11 Temperature and Humidity Sensor. And, I used a 2-Way relay module to turn on or off the cooling fan.

Also, gas leakage, instigated by pipe expansion, is a dangerous problem while temperature is rising. Therefore, I added an MQ-135 Gas Sensor to the device, which detects NH3, NOx, Alcohol, Benzene, Smoke, CO2, to check the hazardous gas status in my room. And, most importantly, to be able to send commands to control the cooling fan via SMS messages and get the weather and gas information as feedback, I used a SIM808 GPS/GPRS/GSM Shield sponsored by DFRobot.

Sponsored products by DFRobot:

- SIM808 GPS/GPRS/GSM Shield For Arduino | Inspect

project-image
Figure - 47.1

Step 1: Programming Arduino Uno

Download the required libraries:

For SIM808 GPS/GPRS/GSM Shield | Download

For 3-wire Serial LCD Module | Download

For DHT11 Temperature and Humidity Sensor | Download

Do not forget that the SIM808 receives SMS messages as char arrays instead of strings. So, you have to use the strcmp function to make comparisons to detect the requested command.

And, the 3-Wire Serial LCD module prints only char arrays. After creating a data string, use the String_to_Char function to convert strings to char arrays.

- Include required libraries.

- Define the sim808 object.

- Define required settings to read SMS messages.

- Define a phone number to be able to receive feedback messages from the device.

- Define the DHT11 object.

- Define pin numbers for modules.

- Define the data holders.

- Initiate the DHT11 Temperature and Humidity Sensor.

- Initiate the SPI LCD Screen with the given pins (2, 7, 10).

- Initialize sim808 module.

- Continue if the SIM808 Module is working accurately.

- In the get_Sensor_Variables() function:

- Get data from the DHT11 Sensor.

- Get data from the MQ-135 Gas Sensor.

- Detect the gas status depending on the value generated by the MQ-135 - OK or DANGER.

- Convert messages from strings to char arrays to be able to send them via the SIM808.

- In the read_SMS_Messages() function:

- Wait serial data from the SIM808.

- Detect the current state of SMS.

- Print the received SMS message.

- Activate the requested command depending on the SMS message.

- In the activate_Commands function:

- Using the strcmp function, detect the requested command by the user to execute features related to that command.

project-image
Figure - 47.2


project-image
Figure - 47.3


project-image
Figure - 47.4


project-image
Figure - 47.5


project-image
Figure - 47.6


project-image
Figure - 47.7

Connections and Adjustments


// Connections
// Arduino Uno:           
//                               SIM808 GPS/GPRS/GSM Shield For Arduino
// D0 --------------------------- RX
// D1 --------------------------- TX
// D12 -------------------------- POWER
//                               3-wire Serial LCD Module
// D2 --------------------------- SCK
// D7 --------------------------- CS
// D10 -------------------------- SID
// 5V --------------------------- VCC
// GND -------------------------- GND
//                               DHT1l Temperature and Humidity Sensor
// D3 --------------------------- S
//                               MQ-135 Gas Sensor
// A0 --------------------------- A0
//                               2-Way Relay Module
// D4 --------------------------- IN1

project-image
Figure - 47.8

Note: D0, D1, D12 pins are occupied by the SIM808 GPS/GPRS/GSM Shield.

Connect an external battery (7-23V) for the SIM808 module to work properly.

Attach the GPS antenna and the GSM antenna to the SIM808 shield.

Insert a SIM card into the SIM slot on the SIM808 shield.

Before uploading the code, set the function switch on the shield to None (1).

Upload the code.

Then, set the function switch to Arduino (3).

Press the Boot button on the shield until seeing the Net indicator LED flashing every 1 second and wait for the SIM card to register the network - the Net indicator LED will slowly flash every 3 seconds.

Click here to get more information about the SIM808 GSM/GPS/GPRS Shield.

project-image
Figure - 47.9

Connect the 3-wire Serial LCD Module to the Arduino Uno.

To switch to the 3-Wire mode, set the PSB_ON switch to SPI.

Click here to get more information about the 3-wire Serial LCD Module.

project-image
Figure - 47.10


project-image
Figure - 47.11

Connect the DHT11 Temperature and Humidity Sensor, the MQ-135 Gas Sensor, and the 2-Way relay to the Arduino Uno.

Attach a plug to the 2-Way relay to be able to control the cooling fan easily.

project-image
Figure - 47.12

After making connections, I fastened all components to a corkboard. As you may have realized, I used the base of my previous project (ORP Water Quality Detector) to create this project. In this way, I can switch back between projects by merely adding or removing sensors :)

project-image
Figure - 47.13

Features

I mulled over these functions below to be able to observe the temperature, humidity, and gas status of my room while controlling my cooling fan via SMS messages.

1) The device throws an error message (Init Error) until the SIM808 connects to the GSM network.

project-image
Figure - 47.14

2) When the SIM808 connects to the GSM network and works properly, the device shows a confirmation message (Init Success).

project-image
Figure - 47.15

3) The device always returns to the home screen after receiving and interpreting SMS messages to let the user know it is ready.

project-image
Figure - 47.16

4) If the device receives Open Fan as an SMS message, then it activates the cooling fan.

project-image
Figure - 47.17


project-image
Figure - 47.18


project-image
Figure - 47.19

5) If the device receives Close Fan as an SMS message, then it turns off the cooling fan.

project-image
Figure - 47.20


project-image
Figure - 47.21


project-image
Figure - 47.22

6) The device sends a feedback SMS message, including the current temperature detected by the DHT11 module, to the given phone number if it receives Temperature as an SMS message.

project-image
Figure - 47.23


project-image
Figure - 47.24


project-image
Figure - 47.25


project-image
Figure - 47.26

7) The device sends a feedback SMS message, including the current humidity detected by the DHT11 module, to the given phone number if it receives Humidity as an SMS message.

project-image
Figure - 47.27


project-image
Figure - 47.28


project-image
Figure - 47.29


project-image
Figure - 47.30

8) Depending on the gas value detected by the MQ-135 module, the device sends a feedback message including the gas status (OK or DANGER) with the current gas value to the given phone number if it receives Gas as an SMS message.

project-image
Figure - 47.31


project-image
Figure - 47.32


project-image
Figure - 47.33


project-image
Figure - 47.34

Videos and Conclusion

Code

SIM808_Cooling_Fan_with_Weather_and_Gas_Station.ino

Download



         ///////////////////////////////////////////////////////  
        //             SIM808 Remote Cooling Fan             //
       //             w/ Weather and Gas Station            //
      //           -------------------------------         //
     //                     Arduino Uno                   //           
    //                   by Kutluhan Aktar               // 
   //                                                   //
  ///////////////////////////////////////////////////////

// Via SMS messages; control a fan and observe the temperature, humidity, and gas status of your room.
//
// For more information about this project:
// https://www.theamplituhedron.com/projects/SIM808-Remote-Cooling-Fan-with-Weather-and-Gas-Station/
//
// Connections
// Arduino Uno:           
//                               SIM808 GPS/GPRS/GSM Shield For Arduino
// D0 --------------------------- RX
// D1 --------------------------- TX
// D12 -------------------------- POWER
//                               3-wire Serial LCD Module
// D2 --------------------------- SCK
// D7 --------------------------- CS
// D10 -------------------------- SID
// 5V --------------------------- VCC
// GND -------------------------- GND
//                               DHT1l Temperature and Humidity Sensor
// D3 --------------------------- S
//                               MQ-135 Gas Sensor
// A0 --------------------------- A0
//                               2-Way Relay Module
// D4 --------------------------- IN1


// Include required libraries:
#include <DFRobot_sim808.h>
#include "LCD12864RSPI.h"
#include "DHT.h"

// Define the sim808.
DFRobot_SIM808 sim808(&Serial);

// Define settings to read SMS messages.
#define MESSAGE_LENGTH 20
char gprsBuffer[64];
char *s = NULL;

// Define a phone number to be able to receive feedback messages from the device.
#define PHONE_NUMBER "[Enter Phone Number]"  // Change

// Define the DHT11 object.
DHT dht;

// Define pin numbers for modules.
#define mq_135 A0
#define relay 4

// Define the data holders.
const int message_size = 35;
char Temperature[message_size], Humidity[message_size], Gas[message_size];

void setup() {
  Serial.begin(9600);

  pinMode(relay, OUTPUT);
  digitalWrite(relay, HIGH);

  // Initiate the DHT11 Temperature and Humidity Sensor.
  dht.setup(3);

  // Initiate the SPI LCD Screen with the given pins (2, 7, 10).
  LCDA.initDriverPin(2,7,10); 
  LCDA.Initialise(); // INIT SCREEN  
  delay(100);

  //******** Initialize sim808 module *************
  while(!sim808.init()) {
     delay(1000);
     Serial.print("Sim808 init error\r\n");
     LCDA.DisplayString(0,0,"Init Error",12);
  }
  delay(2000);
  LCDA.CLEAR();
  // Continue if the SIM808 Module is working accurately.
  Serial.println("Sim808 init success");
  LCDA.DisplayString(0,0,"Init Success",12);
  delay(5000);
  LCDA.CLEAR();
  
}

void loop() {
  
  read_SMS_Messages();

}

void get_Sensor_Variables(){
  // Get data from the DHT11 Sensor.
  delay(dht.getMinimumSamplingPeriod());
  float humidity = dht.getHumidity();
  float temperature = dht.getTemperature();
  // Get data from the MQ-135 Gas Sensor
  int gas = analogRead(mq_135);
  String gas_status;
  if(gas > 305){ gas_status = "DANGER"; }else{ gas_status = "OK"; }
  // Set message texts.
  String _Temperature = "Temperature => " + String(temperature) + "*C";
  String _Humidity = "Humidity => " + String(humidity) + "%";
  String _Gas = "Gas Value => " + String(gas) + " ---- Status => " + gas_status;
  // Convert messages from strings to char arrays tp be able to send them via SIM808.
  String_to_Char(Temperature, message_size, _Temperature);
  String_to_Char(Humidity, message_size, _Humidity);
  String_to_Char(Gas, message_size, _Gas);
  
}

void read_SMS_Messages(){
 //******** Wait serial data *************
 if(sim808.readable()){
   sim808_read_buffer(gprsBuffer,32,DEFAULT_TIMEOUT);
   //Serial.print(gprsBuffer);
   //************** Detect the current state of SMS ************************
   if(NULL != (s = strstr(gprsBuffer,"+CMTI: \"SM\""))) { //SMS: $$+CMTI: "SM",24$$
      LCDA.CLEAR();
      char message[MESSAGE_LENGTH];
      int messageIndex = atoi(s+12);
      sim808.readSMS(messageIndex, message, MESSAGE_LENGTH);
      LCDA.DisplayString(0,0,"Recv. Message:", 14);
      LCDA.DisplayString(2,0,message,strlen(message));
      delay(3000);
      // Activate the requested command via SMS.
      activate_Commands(message);      
   }
   sim808_clean_buffer(gprsBuffer,32);
 }else{
  LCDA.DisplayString(0,0,"Waiting...",10);
  LCDA.DisplayString(1,0,"SMS Messages :)",15);
 }  
}

void activate_Commands(char command[]){
  if(strcmp(command, "Open Fan") == 0){
    LCDA.CLEAR();
    LCDA.DisplayString(0,0,"Fan",3);
    LCDA.DisplayString(1,0,"Activated!",10);
    digitalWrite(relay, LOW);
    delay(3000);
  }
  if(strcmp(command, "Close Fan") == 0){
    LCDA.CLEAR();
    LCDA.DisplayString(0,0,"Fan",3);
    LCDA.DisplayString(1,0,"Closed!",7);
    digitalWrite(relay, HIGH);
    delay(3000);
  }
  if(strcmp(command, "Temperature") == 0){
    // Get variables:
    get_Sensor_Variables();
    // Print
    LCDA.CLEAR();
    LCDA.DisplayString(0,0,"Temperature",11);
    LCDA.DisplayString(1,0,"Transferred!",12);
    // Send the temperature to the defined phone number as a feedback message.
    sim808.sendSMS(PHONE_NUMBER, Temperature);
    delay(3000);
  }
  if(strcmp(command, "Humidity") == 0){
    // Get variables:
    get_Sensor_Variables();
    // Print
    LCDA.CLEAR();
    LCDA.DisplayString(0,0,"Humidity",8);
    LCDA.DisplayString(1,0,"Transferred!",12);
    // Send the temperature to the defined phone number as a feedback message.
    sim808.sendSMS(PHONE_NUMBER, Humidity);
    delay(3000);
  }
  if(strcmp(command, "Gas") == 0){
    // Get variables:
    get_Sensor_Variables();
    // Print
    LCDA.CLEAR();
    LCDA.DisplayString(0,0,"Gas",3);
    LCDA.DisplayString(1,0,"Transferred!",12);
    // Send the temperature to the defined phone number as a feedback message.
    sim808.sendSMS(PHONE_NUMBER, Gas);
    delay(3000);
  }
  // Exit and Clear.
  LCDA.CLEAR();
}

void String_to_Char(char _convert[], int _size, String _String){
  for(int i=0;i<_size;i++){
    _convert[i] = _String[i];
  }
}


Schematics

project-image
Schematic - 47.1


project-image
Schematic - 47.2


project-image
Schematic - 47.3

Downloads

Fritzing File

Download