SIM800L internet Connection Tutorial – AT Command List to make HTTP/GET request

SIM800L HTTP request

In this article we will examine how to make a HTTP/GET Request to web page using AT Command of SIM800L. We will give you the list of AT Command needed and step by step the sequence of the AT Command.

If you are using arduino to make GET request you need a sketch to forward data from your computer’s serial monitor to SIM800L. Use this sketch :

#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  mySerial.begin(9600);
  //pinMode(13, OUTPUT);
}

void loop() {
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

Use pin 10 and 11 for Serial connection between arduino and SIM800L. I use a step down to make the voltage about 4.2V from 12V power supply. So here’s the wiring diagram.


And below is step by step AT command to use

Set Connection to GPRS :

AT+SAPBR=3,1,"Contype","GPRS"

Set the APN, username and password.

AT+CSTT="3gprs","3gprs","3gprs"

(the APN, username and password i’m using is 3GPRS

Enable the GPRS

AT+SAPBR=1,1

Check if we already got IP Adress

AT+SAPBR=2,1

Enabling HTTP mode :

 AT+HTTPINIT

OPTIONAL, If you are using or SLL use :

AT+HTTPSSL=1

Setting HTTP bearer profile :

AT+HTTPPARA="CID",1

Give URL of website we want to access :

AT+HTTPPARA="URL","http://miliohm.com/miliohmSIM800L.php"

Start HTTP GET Session :

AT+HTTPACTION=0

Read the content of webpage :

AT+HTTPREAD

Terminate the session :

AT+HTTPTERM

The Detail of how to do this you can watch on video below :

Lora Shield arduino Tutorial

LORA with arduino tutorial

We will practice how to use LORA shield with arduino UNO. You’ll need two arduinos, and two LORA shield. And don’t forget the USB cable.

A pair of LORA and a pair of arduino

Attach the shield to the arduino and you ready to program the arduino.

You have to upload every sketch for every arduino. There will be a client and a server. The client we use to send data, and the server will receive the data then gives reply.

In this tutorial we will use RadioHead library for LORA. you can download the library here.

Before we start the arduino program, we have to edit the frequency in library according to our LORA. In this case I use the 433Mhz. So I will open the Radiohead library and find file named RH_RF95.cpp. Find and Edit the setFrequency function to 433.0

// An innocuous ISM frequency, same as RF22's
    setFrequency(433.0);

After edit, save the file. and you are ready to open the arduino IDE.

This is the code for the client :

#include <SPI.h>
#include <RH_RF95.h>

// Singleton instance of the radio driver
RH_RF95 rf95;
//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95

// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
//#define Serial SerialUSB

void setup()
{
  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
  //  driver.setTxPower(14, true);
}

void loop()
{
  Serial.println("Sending to rf95_server");
  // Send a message to rf95_server
  uint8_t data[] = "Hello I'm from lora!";
  rf95.send(data, sizeof(data));

  rf95.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf95.waitAvailableTimeout(3000))
  {
    // Should be a reply message for us now
    if (rf95.recv(buf, &len))
    {
      Serial.print("got reply: ");
      Serial.println((char*)buf);
    }
    else
    {
      Serial.println("recv failed");
    }
  }
  else
  {
    Serial.println("No reply, is rf95_server running?");
  }
  delay(400);
}

And this is for the server (another arduino) :

#include <SPI.h>
#include <RH_RF95.h>

// Singleton instance of the radio driver
RH_RF95 rf95;
//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95 

// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
//#define Serial SerialUSB

int led = 9;

void setup() 
{
  // Rocket Scream Mini Ultra Pro with the RFM95W only:
  // Ensure serial flash is not interfering with radio communication on SPI bus
//  pinMode(4, OUTPUT);
//  digitalWrite(4, HIGH);

  pinMode(led, OUTPUT);     
  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");  
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on

  // The default transmitter power is 13dBm, using PA_BOOST.
  // If you are using RFM95/96/97/98 modules which uses the PA_BOOST transmitter pin, then 
  // you can set transmitter powers from 5 to 23 dBm:
//  driver.setTxPower(23, false);
  // If you are using Modtronix inAir4 or inAir9,or any other module which uses the
  // transmitter RFO pins and not the PA_BOOST pins
  // then you can configure the power transmitter power for -1 to 14 dBm and with useRFO true. 
  // Failure to do that will result in extremely low transmit powers.
//  driver.setTxPower(14, true);
}

void loop()
{
  if (rf95.available())
  {
    // Should be a message for us now   
    uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
    uint8_t len = sizeof(buf);
    if (rf95.recv(buf, &len))
    {
      digitalWrite(led, HIGH);
//      RH_RF95::printBuffer("request: ", buf, len);
      Serial.print("got request: ");
      Serial.println((char*)buf);
//      Serial.print("RSSI: ");
//      Serial.println(rf95.lastRssi(), DEC);
      
      // Send a reply
      uint8_t data[] = "And hello back to you";
      rf95.send(data, sizeof(data));
      rf95.waitPacketSent();
      Serial.println("Sent a reply");
       digitalWrite(led, LOW);
    }
    else
    {
      Serial.println("recv failed");
    }
  }
}

And if you want to send integer sensor data you can edit the data and use the code below :

#include <SPI.h>
#include <RH_RF95.h>

// Singleton instance of the radio driver
RH_RF95 rf95;
//RH_RF95 rf95(5, 2); // Rocket Scream Mini Ultra Pro with the RFM95W
//RH_RF95 rf95(8, 3); // Adafruit Feather M0 with RFM95

// Need this on Arduino Zero with SerialUSB port (eg RocketScream Mini Ultra Pro)
//#define Serial SerialUSB

void setup()
{
  Serial.begin(9600);
  while (!Serial) ; // Wait for serial port to be available
  if (!rf95.init())
    Serial.println("init failed");
  // Defaults after init are 434.0MHz, 13dBm, Bw = 125 kHz, Cr = 4/5, Sf = 128chips/symbol, CRC on
  //  driver.setTxPower(14, true);
}

void loop()
{
  Serial.println("Sending to rf95_server");
  // Send a message to rf95_server
  //We change the data we want to send with sensor_value
  int sensor_value = analogRead(A0);
  Serial.println("Sensor Value : "+(String)sensor_value);
  char data[3];
  itoa(sensor_value, data, 10);
  rf95.send(data, sizeof(data));

  rf95.waitPacketSent();
  // Now wait for a reply
  uint8_t buf[RH_RF95_MAX_MESSAGE_LEN];
  uint8_t len = sizeof(buf);

  if (rf95.waitAvailableTimeout(3000))
  {
    // Should be a reply message for us now
    if (rf95.recv(buf, &len))
    {
      Serial.print("got reply: ");
      Serial.println((char*)buf);
    }
    else
    {
      Serial.println("recv failed");
    }
  }
  else
  {
    Serial.println("No reply, is rf95_server running?");
  }
  delay(400);
}

And if you want to watch the complete tutorial, you can watch the video below :

Easy Pulse Plugin Heartbeat Sensor with arduino Tutorial

easy pulse plugin sensor

There are some heartbeat sensor in market with cheap price. I’ve used three of them, that is heart rate from pulsesensor.com, max30100 and easy pulse Plugin heartbeart sensor. In my opinion, the most stable is easy pulse plugin. Maybe because it comes with a shell or cover. That make minimum interference from outside. Different with heart rate sensor form pulsesensor.com sometimes it’s has different output amplitude that make it harder to get stable value. It has many factor that make that unstable.

easy pulse plugin sensor
easy pulse plugin sensor

In this tutorial we will only examine how to use Easy Pulse Plugin Heartbeat Sensor with an arduino. This sensor has an analog output just like sensor from pulsesensor.com. Before we go far how to use this sensor, we will examine how this sensor works. Little basic theory about this sensor.

How Easy Pulse Plugin Sensor Works?

Easy Pulse Plugin is an open-source sensor based on photoplethysmography principle (PPG). It is non-invasive to measure the cadiovascular pulse wave by detect the blood volume changes in blood vessels. This sensor uses a infrared light emitting diode (IR-LED) and a photodetector.

photoplethysmography sensor
photoplethysmography sensor

Look at picture above, there is an IR-LED as transmitter. This LED will transmit an infrared light to the photo sensor. But if we place our finger between them, the photo sensor will receive only the light left after absorbed by finger. And the thing is, the light absorbed by finger is vary according to the blood. The light intensity that up to the photo sensor is related to the changes in blood volume inside the tissue.



Analog output from this sensor will form a wave that related to the beat of the heartbeat. it will rise when there’s a beat.

beat wave
beat wave

Using it with arduino

easy pulse plugin sensor with arduino wiring
easy pulse plugin sensor with arduino wiring

You can choose to use 5V or 3.3V for power of this sensor. To choose simply move the jumper in top left corner (yellow circle in picture above). And you can also choose the output to out at A0 or A1 (move the jumper in green circle).

Connect this sensor to arduino just like picture above.

5v -> 5v (if using 5V module)

GND -> GND

A0 -> A0 (if choose A0 as output).

Or you can just directly connect the sensor to the arduino UNO. Just like the picture below. The module is designed can connect directly. Of course if you don’t need another power pin.

arduino uno with easy pulse plugin
arduino uno with easy pulse plugin

The arduino code

In beat wave picture above is the picture of wave created by the beats from sensor when a finger placed in the sensor. The peak made when a beat is sensed by the sensor. To get the wave like in picture above you can use the sample code from arduino named analogReadSerial  with little modification. The modification should give longer delay. Or you can just copy the code below :

/*
  AnalogReadSerial

  Reads an analog input on pin 0, prints the result to the Serial Monitor.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/AnalogReadSerial
*/

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(10);        // delay in between reads for stability
}

I modify the delay so it will only read the sensorValue every 10ms. Upload code above and open your Serial Plotter. Open it from tools -> Serial Plotter.



If we want to make a heart rate device we can measure by count how many peak from the sensor in one minute. To do this you need to define your threshold first. So you can decide where the beats happen. Look at picture below for example

beat threshold
beat threshold

I will give the threshold for my beats at 450 value of ADC. So every adc reach more than 450 I will count it as a beat.  And because I consider measure beats per minute will take a long time when it’s really count for one minute, I will just count for 20 seconds. And the result will multiply by 3. So it is just like 60 seconds or one minute.


int adc;
boolean counter;
int count;
unsigned long millisBefore;
unsigned long beatTime=20000;
const int threshold=450;

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  counter = true;
  millisBefore = millis();
}

void loop() {
  // put your main code here, to run repeatedly:
  adc = analogRead(A0);
  Serial.println(adc);
  delay(10);

  if ((millis() - millisBefore) < beatTime) {
    if (counter == true) {
      if (adc >= threshold) {
        count++;
        counter = false;
        Serial.print("Beat : ");
        Serial.println(count);
      }
    }
    if (adc < threshold) {
      counter = true;
    }
  } else {
    Serial.print(count*(60000/beatTime));
    Serial.println(" BPM");
    count=0;
    millisBefore = millis();
  }
}

The code above will print number every beat detected and will print the beats per minute every 20 seconds. You can edit how long to get count the beat by edit variable beatTime. 20000 means 20 seconds, because it is in miliseconds. And of course you can edit the threshold too by edit number in threshold variable.

SIM800L With Arduino Tutorial

SIM800L

Introduction to SIM800L

There are so many GSM modules that came to market right now. And SIM800L almost the cheapest. It cost under 10$ and has the same feature as other. So, this module is a great one.

This module works just like another module, it uses AT Command to communicate with arduino and has the same command. You can download the AT command list it uses here.

SIM800L
SIM800L

Just like another GSM module like SIM900A that we’ve wrote the tutorial here. This is of course use serial communication to communicate with arduino. So we need Tx and Rx here.

Arduino and SIM800L Wiring Diagram

arduino and SIM800L wiring diagram

arduino and SIM800L wiring diagramConnect your arduino and SIM800L like above. But this seems like to be wrong. Because in the datasheet it says that VCC must be at 4.4V maximum. But in last version of this module, it works given 5V for it’s VCC.



if it is doesn’t work for you can try to drop the VCC to not more than 4.4V. You can use buck converter, or the simplest way just use a diode. I will prefer use only a diode because it simplicity. So, wiring diagram become like below :

arduino and SIM800L wiring diagram
arduino and SIM800L wiring diagram

The Code

Sending a message:

In this example, we made two function that is SendMessage() and _readSerial(). SendMessage() to send message and _readSerial() to read the answer from SIM800L.

#include <SoftwareSerial.h>
SoftwareSerial sim(10, 11);
int _timeout;
String _buffer;
String number = "+6289668072234";

void setup() {
  delay(7000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(9600);
  _buffer.reserve(50);
  Serial.println("Sistem Started...");
  sim.begin(9600);
  delay(1000);
}

void loop() {
  SendMessage();
  delay(10000);
}

void SendMessage()
{
  //Serial.println ("Sending Message");
  sim.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);
  //Serial.println ("Set SMS Number");
  sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
  delay(1000);
  String SMS = "Hello, how are you?";
  sim.println(SMS);
  delay(100);
  sim.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  _buffer = _readSerial();
}

String _readSerial() {
  _timeout = 0;
  while  (!sim.available() && _timeout < 12000  )
  {
    delay(13);
    _timeout++;
  }
  if (sim.available()) {
    return sim.readString();
  }
}

To make a call you can create another function and call that function from your loop. And this is the function :

void callNumber() {
  sim.print (F("ATD"));
  sim.print (number);
  sim.print (F(";\r\n"));
  _buffer = _readSerial();
  Serial.println(_buffer);
}




I mixed up the code to send and receive sms and make a call. Every task in a function. So it has three function, SendMessage(), ReceiveMessage() and Call(). In this code you just type in serial monitor “s” to send, “r” to receive SMS, and “c” to make a call.

#include <SoftwareSerial.h>
SoftwareSerial sim(10, 11);
int _timeout;
String _buffer;
String number = "+6282222222222"; //-> change with your number

void setup() {
  delay(7000); //delay for 7 seconds to make sure the modules get the signal
  Serial.begin(9600);
  _buffer.reserve(50);
  Serial.println("Sistem Started...");
  sim.begin(9600);
  delay(1000);
  Serial.println("Type s to send an SMS, r to receive an SMS, and c to make a call");
}

void loop() {
  if (Serial.available() > 0)
    switch (Serial.read())
    {
      case 's':
        SendMessage();
        break;
      case 'r':
        RecieveMessage();
        break;
      case 'c':
        callNumber();
        break;
    }
  if (sim.available() > 0)
    Serial.write(sim.read());
}

void SendMessage()
{
  //Serial.println ("Sending Message");
  sim.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);
  //Serial.println ("Set SMS Number");
  sim.println("AT+CMGS=\"" + number + "\"\r"); //Mobile phone number to send message
  delay(1000);
  String SMS = "Hello, how are you?";
  sim.println(SMS);
  delay(100);
  sim.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  _buffer = _readSerial();
}

void RecieveMessage()
{
  Serial.println ("SIM800L Read an SMS");
  delay (1000);
  sim.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  Serial.write ("Unread Message done");
}

String _readSerial() {
  _timeout = 0;
  while  (!sim.available() && _timeout < 12000  )
  {
    delay(13);
    _timeout++;
  }
  if (sim.available()) {
    return sim.readString();
  }
}

void callNumber() {
  sim.print (F("ATD"));
  sim.print (number);
  sim.print (F(";\r\n"));
  _buffer = _readSerial();
  Serial.println(_buffer);
}

 

And that’s all the code. That is easty Isn’t it? And if you need a tutorial on how to send data over GPRS with this module, wait our next tutorial.



Watch also complete video tutorial below :

Non Contact Temperature Sensor MLX90614 With Arduino Tutorial

MLX90614 contactless temperature sensor

One of solution to build sensor system that can measure high temperature without damage the system is using contactless or non-contact temperature sensor. This sensor can sense temperature of an object without touch the object.


Mlx90614 is a infrared based sensor, it measure the temperature based on infrared emitted by an object. It senses electromagnetic waves in the range about 700 nm to 14,000 nm.

Mlx90614 is a great cheap sensor that cost under 10$.

""

Sensor Spesification

These are some good feature of this sensor taken from it’s datasheet.

  • Small size, low cost
  • Factory calibrated in wide temperature range:
    40 to 125 °C for sensor temperature and
    70 to 380 °C for object temperature.
  • High accuracy of 0.5°C over wide temperature
    range (0..+50°C for both Ta and To)
  • Measurement resolution of 0.02°C
  • Available in 3V and 5V versions

Wiring Diagram

wiring diagram mlx90614 and arduino
wiring diagram mlx90614 and arduino

Vin -> 3.3V

GND -> GND

SCL -> SCL or A5

SDA -> SDA or A4



You can choose to connect sensor I²C pin to arduino SCL, SDA or arduino pin A4,A5 they have the same function. Make sure use 3.3V for 3.3V module type. Because it will damage if connected to 5V. I damaged mine twice.

MLX90614 With Arduino Code

Before you start the code, make sure you have the library. Download library from adafruit here.

You can get the sample code to measure temperature using the library sample or copy code below :

/*************************************************** 
  This is a library example for the MLX90614 Temp Sensor

  Designed specifically to work with the MLX90614 sensors in the
  adafruit shop
  ----> https://www.adafruit.com/products/1748
  ----> https://www.adafruit.com/products/1749

  These sensors use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

  Written by Limor Fried/Ladyada for Adafruit Industries.  
  BSD license, all text above must be included in any redistribution
 ****************************************************/

#include <Wire.h>
#include <Adafruit_MLX90614.h>

Adafruit_MLX90614 mlx = Adafruit_MLX90614();

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

  Serial.println("Adafruit MLX90614 test");  

  mlx.begin();  
}

void loop() {
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempC()); 
  Serial.print("*C\tObject = "); Serial.print(mlx.readObjectTempC()); Serial.println("*C");
  Serial.print("Ambient = "); Serial.print(mlx.readAmbientTempF()); 
  Serial.print("*F\tObject = "); Serial.print(mlx.readObjectTempF()); Serial.println("*F");

  Serial.println();
  delay(500);
}

Paste the code above to your arduino IDE and upload. After done uploading, you can test the sensor. It should works now!. You can measure an object temperature by face the sensor toward the object.



Watch the full video tutorial below :

SIM900A module with arduino Tutorial

SIM900A module package

Introduction to SIM900A

SIM900A is a GSM module that function like phone. It can send a message, call a phone number and use GPRS to send data.  Here’s the simple feature taken from it’s datasheet :


  • Quad-Band 850/ 900/ 1800/ 1900 MHz
  • Dual-Band 900/ 1900 MHz
  • GPRS multi-slot class 10/8GPRS mobile station class B
  • Compliant to GSM phase 2/2+Class 4 (2 W @850/ 900 MHz)
  • Class 1 (1 W @ 1800/1900MHz)
  • Control via AT commands (GSM 07.07 ,07.05 and SIMCOM enhanced AT Commands)
  • Low power consumption: 1.5mA(sleep mode)
  • Operation temperature: -40°C to +85 °C

SIM900A block
SIM900A block

SIM900A comes in many module, many factory made product with connection module for easier to use by us. Because it will take many connection if we make circuit manually. In this tutorial, we will use SIM900A module like in picture below :

SIM900A module packageSIM900A module package

Other type should be has same principle on how to use it. Usually just use different power consumption. Like voltage and current. This type can connected to 5V directly, which has provided by arduino. No need external power supply. Other type may need 9V or greater.

AT Command

SIM900A uses AT command to communicate and control the module. This means if you want to control SIM900A with arduino. The arduino should give an AT Command to control it. AT Command in SIM900A uses Serial port to communicate. As usual, serial needs two pins that is Transmitter (Tx) and a Receiver (Rx). AT command is a command that begin with “AT”.

AT Command sample :

AT+CMGF=1  //Sets the GSM Module in Text Mode
AT+CMGS //Send a message



Parts needed for this Tutorial

  1. SIM900A
  2. Arduino UNO
  3. SIM Card
  4. 4 male female jumper cable

SIM900A with arduino
SIM900A with arduino

We just need connect 4 wires to SIM900A module, that is power connection (VCC and GND). And Serial communication (RX-TX). Because we use arduino UNO which is use 5V operating voltage and has 5V logic level (TTL). So we need to connect arduino to 5RX and 5TX like in pinout picture below.

SIM900A pinout
SIM900A pinout

SIM900A and Arduino wiring connection

Wire SIM900A module to arduino UNO like this :

Arduino -> SIM900A

5V -> VCC

GND -> GND

10 -> TX

11 -> RX

 

Arduino and SIM900A wiring
Arduino and SIM900A wiring

Communication Test

If you already connect the module with arduino like in picture above, then this is the time to test communication between module and arduino, to make sure that arduino can give command to SIM900A module. Don’t forget to double check the wiring connection.



In this test, we will use AT Command to communicate with SIM900A module. If we send command “AT” the module should reply “OK”. And if that happen, this means the connection is succesfull. To do this, we need an arduino sketch like below :

 

#include <SoftwareSerial.h>
SoftwareSerial SIM900A(10,11); // RX | TX
// Connect the SIM900A TX to Arduino pin 2 RX. 
// Connect the SIM900A RX to Arduino pin 3 TX. 
char c = ' ';
void setup() 
{
// start th serial communication with the host computer
Serial.begin(9600);
while(!Serial);
Serial.println("Arduino with SIM900A is ready");

// start communication with the SIM900A in 9600
SIM900A.begin(9600); 
Serial.println("SIM900A started at 9600");
delay(1000);
Serial.println("Setup Complete! SIM900A is Ready!");
}

void loop()
{

// Keep reading from SIM800 and send to Arduino Serial Monitor
if (SIM900A.available())
{ c = SIM900A.read();
Serial.write(c);}

// Keep reading from Arduino Serial Monitor and send to SIM900A
if (Serial.available())
{ c = Serial.read();
SIM900A.write(c); 
}

}

Upload the sketch above and open Serial Monitor. Don’t forget to use BOTH NL&CR in arduino Serial monitor option.

Test the connection by type “AT” and then enter. If the arduino reply “OK” means your connection is established and working. If still no answer from arduino then check your connection and wiring again.

Since we already success use an AT command to SIM900A module, now we can try another AT command. These are some basic AT command we can use :

Change mode to sms :

AT+CMGF=1

Read SMS in text mode :

AT+CNMI=2,2,0,0,0

Make a call :

ATD+1123456789; //replace with number and country code you like

Disconnect / hangup call :

ATH

Receive a phone call :

ATA

We will try an complete example how to send and receive message. Use the sketch below :

#include <SoftwareSerial.h>

SoftwareSerial SIM900A(10,11);

void setup()
{
  SIM900A.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600);    // Setting the baud rate of Serial Monitor (Arduino)
  Serial.println ("SIM900A Ready");
  delay(100);
  Serial.println ("Type s to send message or r to receive message");
}


void loop()
{
  if (Serial.available()>0)
   switch(Serial.read())
  {
    case 's':
      SendMessage();
      break;
    case 'r':
      RecieveMessage();
      break;
  }

 if (SIM900A.available()>0)
   Serial.write(SIM900A.read());
}


 void SendMessage()
{
  Serial.println ("Sending Message");
  SIM900A.println("AT+CMGF=1");    //Sets the GSM Module in Text Mode
  delay(1000);
  Serial.println ("Set SMS Number");
  SIM900A.println("AT+CMGS=\"+6281542787536\"\r"); //Mobile phone number to send message
  delay(1000);
  Serial.println ("Set SMS Content");
  SIM900A.println("Good morning, how are you doing?");// Messsage content
  delay(100);
  Serial.println ("Finish");
  SIM900A.println((char)26);// ASCII code of CTRL+Z
  delay(1000);
  Serial.println ("Message has been sent ->SMS Selesai dikirim");
}


 void RecieveMessage()
{
  Serial.println ("SIM900A Membaca SMS");
  delay (1000);
  SIM900A.println("AT+CNMI=2,2,0,0,0"); // AT Command to receive a live SMS
  delay(1000);
  Serial.write ("Unread Message done");
 }

 

You can edit the sketch and add the AT command you want to use.

You can find Complete video tutorial here :

How to use MQ gas sensor using arduino

MQ-6 with arduino

What is gas sensor

In modern industries, gas sensors are so important. Many modern industries use so many kind of hazardous gas that involved in fabrication process. Even in our home we use dangerous gases like LPG, of course only if not work properly like when it is leaked and burned.



Gas sensor is a device that can sense certain gas and give output proportional to concentration that sensed. Gas sensor with give an voltage output that increases with concentration.

MQ Gas Sensor

MQ gas sensor type is the most popular gas sensor for hobbyist, easy to get and of course very cheap. You can get this sensor for several $. MQ gas sensor type has many derived type for every certain gas. Here’s the list taken from arduino.cc website :

MQ-2

Sensitive for Methane, Butane, LPG, smoke.
This sensor is sensitive for flamable and combustible gasses.
The heater uses 5V.

MQ-3
Sensitive for Alcohol, Ethanol, smoke
The heater uses 5V

MQ-4
Sensitive for Methane, CNG Gas
The heater uses 5V.

MQ-5
Sensitive for Natural gas, LPG
The heater uses 5V.

MQ-6
Sensitive for LPG, butane gas
The heater uses 5V.



MQ-7
Sensitive for Carbon Monoxide
The heater uses an alternating voltage of 5V and 1.4V.
A library for the MQ-7

MQ-8
Sensitive for Hydrogen Gas
The heater uses 5V.

MQ-9
Sensitive for Carbon Monoxide, flammable gasses.
The heater uses an alternating voltage of 5V and 1.5V. It depends on the gases how to use that alternating voltage. If only Carbon Monoxide is tested, the heater can be set at 1.5V.

MQ131
Sensitive for Ozone
The heater uses 6V.

MQ135
For Air Quality
Sensitive for Benzene, Alcohol, smoke.
The heater uses 5V.



MQ136
Sensitive for Hydrogen Sulfide gas.
The heater uses 5V.

MQ137
Sensitive for Ammonia.
The heater uses 5V.

MQ138
Sensitive for Benzene, Toluene, Alcohol, Acetone, Propane, Formaldehyde gas, Hydrogen gas.
The heater uses 5V.

MQ214
Sensitive for Methane, Natural gas.
The heater uses 6V.

MQ216
Sensitive for Natural gas, Coal gas.

MQ303A
Sensitive for Alcohol, Ethanol, smoke (just like the MQ-3)
The heater uses 0.9V

MQ306A
Sensitive for LPG, butane gas
The heater uses 0.9V.
It detects the same gasses as the MQ-6, but uses a lower heater voltage.

MQ307A
Sensitive for Carbon Monoxide
The heater uses an alternating voltage of 0.2V and 0.9.
It detects the same gasses as the MQ-7, but uses a lower heater voltage.

MQ309A
Sensitive for Carbon Monoxide, flammable gasses.
The heater uses an alternating voltage of 0.2V and 0.9V. It depends on the gases how to use that alternating voltage.
It detects the same gasses as the MQ-9, but uses a lower heater voltage.



MG811
Sensitive for Carbon Dioxide (CO2).
The heater uses 6V.
The signal from this gas sensor can be connected to the Arduino, but it’s better to amplifly the signal with a OpAmp.

AQ-104
For air quality

AQ-2
Sensitive for Flamable gasses, smoke

AQ-3
Sensitive for Alcohol, Benzine

AQ-7
Sensitive for Carbon Monoxide

Liquid Petrolium Gas (LPG) sensor

For example here, we will use an LPG gas sensor which is MQ-6 with an arduino UNO. MQ-6 has 4 pin, that is VCC, Ground, Digital Out, and Analog Out.

MQ-6 LPG gas sensor
MQ-6 LPG gas sensor

VCC and GND are used to power up the sensor module. Digital Out used to give output High/Low when the gas concentration reach the threshold. So it will only give digital signal. Analog Out will give analog voltage according to gas concentration. More concentration will give more voltage output. Since we will read the gas concentration, we use the analog output.

Here is the wiring diagram :

MQ-6 with arduino
MQ-6 with arduino

Plug the USB connector to your PC and upload the code below :

void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1000);
}

The code above will print the ADC result from your sensor. You can test by give the sensor some LPG gas and sensor value will increase.

You can watch the video tutorial and demo below :

HC-SR04 ultrasonic sensor with arduino tutorial

how HC-SR04 ultrasonic works

Little Theory about HC-SR04 – How Ultrasonic sensor works

HC-SR04 is a distance sensor based on ultrasonic. Distance obtained by calculating how much time required for ultrasonic to travel from transmitter to receiver. In the beginning, ultrasonic wave transmitted from a transmitter sensor and reach an obstacle. When ultrasonic wave reach obstacle, the wave will bounce back to sensor at receiver.

how HC-SR04 ultrasonic works
how HC-SR04 ultrasonic works

If we knew the speed of ultrasonic, then will obtain the distance by measure time required for wave to bounce back. We remember that distance is speed multiply time. Which is :

S = V * t

We want obtain distance from sensor to obstacle, so we need to divide the distance by 2. So it turn into

S = (V * t) / 2

Ultrasonic is sound wave, so we already knew that the speed of sound is 340m/s. Then let arduino measure time required by ultrasonic to bounce back to sensor.  Say that time required is 100 uS. So the distance will be :

S = (340*100^-6)/2

S = 0,017m or 1,7cm

or you can simplify the formula into :

S = t/2/29.1

Apply the theory – Use HC-SR04 ultrasonics sensor with arduino

When we need distance sensor for our project, HC-SR04 can be the answer. HC-SR04 is very simple and cheap distance sensor. Now we will examine how to use this simple sensor.

Follow schematic below :

HC-SR04 arduino
HC-SR04 arduino

Use this sketch :

const int trig = 2;
const int ech = 3;

void setup() {
  pinMode(trig, OUTPUT);
  pinMode(ech, INPUT);
  Serial.begin(9600);
}

void loop() {
  digitalWrite(trig, LOW);
  delayMicroseconds(2);
  digitalWrite(trig, HIGH);
  delayMicroseconds(10);
  digitalWrite(trig, LOW);
  long timeRequied = pulseIn(ech, HIGH); //measure time required
  int distance = (timeRequied / 2) / 29.1; //calculate the distance
  Serial.println(distance);
  delay(1000);
}

The sketch above will display distance measured by sensor in Serial Monitor.

L293D motor driver with arduino

DC motor

Introducing to L293D motor driver

If you want to control an DC motor that can run forward or reverse you can do that in many ways. But I want to tell you the simplest way to drive DC motor. In this project we will control the DC motor using single IC called L293D. This IC is powerful enough to control DC motor with low current. Before we start the wiring. We will introduce you to L293D IC first. This is the pinout :

L293D Pinout
L293D Pinout




L293D can drive up to 2 motors with single IC. Use input 1 and Input 2 to control first motor. So first motor should be connected to Output 1 and Output 2. And if you want to use second motor, connect input control to Input 3 and Input 4. And motor to Output 3 and Output 4. VCC should be connected to 5V to power up the IC. VSS is input power for motors. So if you want to use 12V motor, this pin should connect to 12V power supply. Connect 12V and 5V ground to gnd, wire all gnd. And Enable pin is used to control speed of motors using PWM. Enable 1 used to control speed of first motor, and Enable 2 for second motor.

L293D schematic with motor example

So how we use this IC? check our example schematic below :

L293D with motors schematic
L293D with motors schematic

To Control first motor (left), you can give input from microncontroller like arduino to make motor run forward or reverse. Give Pin 2 HIGH/5V and Pin 3 LOW/0V to run motor forward. If you want to run motor reverse then give Pin 2 LOW/0V and Pin 3 HIGH/5V.  Give Pin 1 (Enable 1) PWM input to control the speed. If you use arduino UNO you can give PWM from 0-255. Mean that 255 is full speed and 0 is stopped. And if you don’t want to control the speed you can just connect Pin 1 to 5V.



Control the second motor (right) use pin 10 and 15 to give the direction, and Pin 9 to vary the speed.

Example in bread board

Here’s example of using L293D with an arduino UNO and a DC motor

L293D single motor bread board

L293D single motor bread board



In picture above, motor power supply using a 4x AAA batteries. And 5V supply for IC given from arduino 5V.

Code example :

const int motorPin1  = 2;  // Pin 14 of L293
const int motorPin2  = 3;  // Pin 10 of L293

void setup() {
  //Set pins as outputs
  pinMode(motorPin1, OUTPUT);
}


void loop() {
  //This code  will turn Motor forward for 2 sec.
  digitalWrite(motorPin1, HIGH);
  digitalWrite(motorPin2, LOW);
  delay(3000);
  //This code will turn Motor reverse for 2 sec.
  digitalWrite(motorPin1, LOW);
  digitalWrite(motorPin2, HIGH);
  delay(3000);
}

If you want to drive High current DC motor, you can visit here.

How to convert resistance to voltage

convert resistance to voltage

convert resistance to voltage
convert resistance to voltage

Converting resistance to voltage in electronics sometimes are so important. This happens because many electronics device such as microcontroller only can read voltage as analog input signal. Analog signal then will be converted to digital using ADC. But before we talk about ADC or microcontoller, how if our sensor has resistance output instead of voltage?

Voltage Divider as resistance to voltage converter

The only thing we can do to make our sensor readable by microcontroller is convert resistance to voltage. Converting a resistance to voltage is far more easier than converting to other quantity. So, how we do that?

The answer is very simple. Use voltage divider !

Voltage divider has capability to divide the voltage by comparison of two resistance. You can read more details about voltage divider here.

Application Example

I use an LDR for a light sensor. LDR has linear resistance to the light that exposed to it surface. When light getting brighter, the resistance will decreased. Otherwise when light brightness dercreases the resistance will increases. Here’s my schematic example:

voltage divider with ldr
voltage divider with ldr

The output voltage will be :

voltage divider
voltage divider

In this example, when light density is changed, the LDR resistance will changed too and of course Voltage output will changed accordingly.

Since the voltage will change in every change of light density, then you can connect this voltage output to an microcontroller ADC.

Little Tips

Pick the right R2 has a little trick. You have to choose the closest one to LDR reistance range to make the voltage output difference better. For example, if your LDR resistance will vary between 800 ohm to 1k ohm then used 1k ohm resistor as R2 will be ok. But if you has LDR with resistance output vary from 8k-10k don’t use 1k as R2, using 10k as R2 will better.