Arduino Projects

How to use GSM and Bluetooth Together To monitor Any Sensors wirelessly using Arduino

GSM and Bluetooth Together, Project Description:

 

GSM and Bluetooth Together- In this Tutorial, you will learn how to use GSM and Bluetooth together to monitor any Sensors. In this project, the sensors can be monitored wirelessly using the GSM sim900A module and HC-05 Bluetooth module.  In this tutorial, we will cover

  1. Bluetooth settings using AT commands, like setting the pin code, changing the name of the Bluetooth module
  2. dht11 sensor datasheet, pinouts, and soldering
  3. GSM module pinouts and explanation
  4. Complete circuit diagram explanation
  5. Programming
  6. testing

For the complete step-by-step explanation Watch Video Tutorial given at the end of this Article.


Amazon Links:

12v Adaptor:

Arduino Uno

Arduino Nano

Mega 2560:

DHT11 Temperature and Humidity Module:

Bluetooth Module: Hc-05:

Sim900A GSM Module:

DC 5V 2A Adaptor

Other Tools and Components:

Top Arduino Sensors:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!

Why we use GSM and Bluetooth together?

While we are at the site near to the hardware then there is no need to use the GSM for monitoring the Sensor. The best way can be to use the Bluetooth module. We can design our own android cell phone application to monitor different sensors.

GSM and Bluetooth Together Arduino Circuit Diagram:

Bluetooth

Download:

Android cell phone application:gms and bluetooth together

GSM and Bluetooth Arduino Programming:

Both the modules, GSM SIM900A and HC-05 Bluetooth communicates with the Arduino using the Serial communication. As you know, in Arduino we have only one Serial Port, which can be used only for one device at a time unless you use some kind of a multiplexer. But instead of using complex hardware components, we can define other Serial ports using the SoftwareSerial library.

This way we can connect one device with the Arduino’s default Serial port, and the other device with our own defined Serial port. This is the reason I defined a serial port with the name nodemcu on pins 2 and 3.

// Arduino programming

#include <SoftwareSerial.h>
SoftwareSerial nodemcu(2,3);

long int data; 
int firstVal, secondVal,thirdVal;

int tempin = A1; // temperature sensor. middle pin
int vrdata; // store temperature

String myString; // complete message from arduino, which consistors of snesors data
char rdata; // received charactors
String cdata; // complete data


int heater = 13; // for automatic control
int ac = 12; // for automatic control

int dheater = 10; // disconnect heater
int dac = 11; //disconnect ac

String mydata; 

void setup()
{
Serial.begin(9600); 
nodemcu.begin(9600);
pinMode(tempin, INPUT);

 pinMode(heater, OUTPUT); 
 pinMode(ac, INPUT);

 digitalWrite(heater, LOW); 
 digitalWrite(ac, LOW); 

 pinMode(dheater, OUTPUT); 
 pinMode(dac, OUTPUT); 

digitalWrite(dheater, LOW); 
digitalWrite(dac, LOW); 

}

void loop()
{
  
if(nodemcu.available() == 0 )
{
 
temperature();  
mydata = mydata + vrdata + ","; 
nodemcu.println(vrdata); 
mydata = "";  
}

if ( nodemcu.available() > 0 ) 
{

      rdata = nodemcu.read(); 
    myString = myString+ rdata; 
    //Serial.print(rdata);
    if( rdata == '\n')
    {
Serial.println(myString);
// new code
String l = getValue(myString, ',', 0);
String m = getValue(myString, ',', 1);
String n = getValue(myString, ',', 2); 


firstVal = l.toInt(); // Slider value
secondVal = m.toInt(); // device1 
thirdVal = n.toInt(); // device 2

  myString = "";

Serial.println("Slider Value:"); 
Serial.println(firstVal);

if ( vrdata < firstVal ) // if temperature is less than the pre defined temperature, set through app
{
  digitalWrite(heater, HIGH); 
  digitalWrite(ac, LOW); 
}

if ( vrdata > (firstVal+5) )
{
  digitalWrite(heater, LOW); 
  digitalWrite(ac, HIGH); 
}

if ( secondVal == 10 )
{
  digitalWrite(dheater, LOW); 
}

if ( secondVal == 11 )
{
  digitalWrite(dheater, HIGH); 
}

if ( thirdVal == 12 )
{
  digitalWrite(dac, LOW); 
}

if ( thirdVal == 13 )
{
  digitalWrite(dac, HIGH); 
}
 Serial.println("Device1:"); 
Serial.println(secondVal);

Serial.println("device 2:"); 
Serial.println(thirdVal);

    }
  
}

}


String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}


void temperature()
{
   // read temperature.
  int rawvoltage= analogRead(tempin);
float millivolts= (rawvoltage/1024.0) * 5000;
float celsius= millivolts/10;
vrdata = celsius; 
//Serial.print(celsius);
delay(500); 


}

Watch Video Tutorial:

Engr Fahad

My name is Shahzada Fahad and I am an Electrical Engineer. I have been doing Job in UAE as a site engineer in an Electrical Construction Company. Currently, I am running my own YouTube channel "Electronic Clinic", and managing this Website. My Hobbies are * Watching Movies * Music * Martial Arts * Photography * Travelling * Make Sketches and so on...

11 Comments

  1. Hi Sir.
    Thank you for great quality content, total hooked on you tutorials. I would like ask you a question, maybe you have it already in you examples but you have a lot of content to go through. Now as for an example, if you have your mobile number set in your GSM text on the Arduino code to send a notification to your number of choice.
    Now say i don’t want to connect to the Arduino through the serial port every time i want to change the number for the GSM notification. How would i build a App to be able to change GSM mobile number or any other parameters like delay times on the Arduino code, to give it a user App interface. Would i be able to use a bluetooth module to build that type of user interface. Well that is one of the challengers that i have being facing. Anyway i hope you have a solution to this, or if you have one already. Anyway Sir thank you again.

    Kindest Regards

    Errol Sternberg

    1. this is very simple, you can use the Bluetooth module to wirelessly update the cell phone number. let’s say you send a number wirelessly to the Arduino, the received number then you can save in the EEPROM. So even if you restart the Arduino the number will stay there. you can also do it for multiple numbers.

      1. Thank you for your reply. Ok i will need to do a bit of research on this, if i cannot come rite, I might have to ask you for your help and pay the necessary fee if that is fine with you. Will try it first, that’s the only way to learn. Thanks again.

        1. let me tell you what I am making, My client has the requirement of entering any 10 cell phone numbers which can be permanently stored in the Arduino EEPROM. he can delete any number, he can update any number. display all the stored numbers, can erase all the numbers. This is done wirelessly using Bluetooth. He is launching a Security system based on the GSM. he can use the same program and can update cell phone numbers wirelessly without any change in the code.
          it’s really a long code.

          1. That is exactly what my project is suppose operate like or what i want it to do as you have just described. So if it is a working system and lets say sold as a working unit the customer can change the mobile number for the GSM as well as the delay time or on off delay time at his convenience.
            The thing is i’m still new to programing and have not yet explored the EEPROM side of programing so this would take me a while. So i think in stead of me spending weeks i would rather pay you the fee instead. Lol i just hope i can afford you.

            Ok just a bit of a description of my project, as you have already done in your tutorial there is a PIR and a LDR sensor or any other sensor, once triggered Your code GSM code does it thing to three numbers, ofter that it activates a solenoid, sound alarm then a stepper motor, then it deactivates after delay times. And then just waits for the next activation. i would like it to do more but will take a look at you project were you have multiple relays.

  2. Dear Engrr Fahad.
    I understand a lot of things. your way of describing the projects is very simple, and easy to understand.
    I do not know how to program any thing, but believe me I am at your site since 3 hours.
    and I am feeling myself a programmer.
    thanks a lot for giving this price less knowledge.
    Arif Toheed

  3. where is your bluetooth connection???
    the code on this articel not same like a video on youtube.
    why nodemcu you turn in on your articel.

Leave a Reply

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

Back to top button