0% found this document useful (0 votes)
45 views

Arduino Proj Network

This code uses a SIM900 GSM/GPRS shield to submit an HTTP request and control LEDs based on the response. It includes the SIM900 library, sets up software serial communication and pins for three LEDs. The setup function powers everything on. The main loop continuously submits requests and delays. The SubmitHttpRequest function attaches to GPRS, sets the APN, initiates an HTTP request, reads the response and changes the LED states accordingly based on substrings in the response.

Uploaded by

Study Time
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

Arduino Proj Network

This code uses a SIM900 GSM/GPRS shield to submit an HTTP request and control LEDs based on the response. It includes the SIM900 library, sets up software serial communication and pins for three LEDs. The setup function powers everything on. The main loop continuously submits requests and delays. The SubmitHttpRequest function attaches to GPRS, sets the APN, initiates an HTTP request, reads the response and changes the LED states accordingly based on substrings in the response.

Uploaded by

Study Time
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

#include <sim900.

h>

#include <SPI.h>

#include <SoftwareSerial.h>

SoftwareSerial SIM900(7, 8); // configure software serial port

int REDLed=2;

int GREENLed= 10;

int BLUELed= 11;

void setup() {

pinMode(REDLed, OUTPUT);

pinMode(GREENLed, OUTPUT);

pinMode(BLUELed, OUTPUT);

SIM900.begin(19200);

Serial.begin(19200);

Serial.print("power up" );

delay(10000);

digitalWrite(REDLed,HIGH);

digitalWrite(GREENLed,HIGH);

digitalWrite(BLUELed,HIGH);

}
void loop()

Serial.println("SubmitHttpRequest - started" );

SubmitHttpRequest();

Serial.println("SubmitHttpRequest - finished" );

delay(10000);

void SubmitHttpRequest()

SIM900.println("AT+CSQ"); // Signal quality check

delay(100);

ShowSerialData();// this code is to show the data from gprs shield, in order to easily see the process of
how the gprs shield submit a http request, and the following is for this purpose too.

SIM900.println("AT+CGATT?"); //Attach or Detach from GPRS Support

delay(100);

ShowSerialData();
SIM900.println("AT+SAPBR=3,1,\"CONTYPE\",\"GPRS\"");//setting the SAPBR, the connection type is
using gprs

delay(1000);

ShowSerialData();

SIM900.println("AT+SAPBR=3,1,\"APN\",\"CMNET\"");//setting the APN, Access point name string

delay(4000);

ShowSerialData();

SIM900.println("AT+SAPBR=1,1");//setting the SAPBR

delay(2000);

ShowSerialData();

SIM900.println("AT+HTTPINIT"); //init the HTTP request

delay(2000);

ShowSerialData();

SIM900.println("AT+CIPSEND=?");

delay(2000);

ShowSerialData();
SIM900.println("AT+HTTPREAD");// read the data from the website you access

delay(300);

changeLed();

ShowSerialData();

SIM900.println("");

delay(100);

void changeLed()

String content = "";

// String RedState = content.substring();

while(SIM900.available()!=0)

//Serial.write(SIM900.read());

content = content + String(char (SIM900.read()));

Serial.println(content);

if(content.substring(28,29)== "1")

digitalWrite(REDLed, LOW);

else if (content.substring(28,29)== "0")

{
digitalWrite(REDLed, HIGH);

if(content.substring(29,30)== "1")

digitalWrite(GREENLed, LOW);

else if (content.substring(29,30)== "0")

digitalWrite(GREENLed, HIGH);

if(content.substring(30,31)== "1")

digitalWrite(BLUELed, LOW);

else if (content.substring(30,31)== "0")

digitalWrite(BLUELed, HIGH);

char(SIM900.write("111"));

content = "";

void ShowSerialData()

{
while(SIM900.available()!=0)

Serial.write(char (SIM900.read()));

void sendData(String thisData) {

Serial.println(postRequest);

delay(1500);

countTrueCommand++;

You might also like