0% found this document useful (0 votes)
61 views3 pages

GSM Codes

1. The document describes an Arduino sketch that measures light intensity with an LDR sensor, sends SMS messages with the light reading measurements via a GSM module, and includes functions for initializing the GSM module and sending SMS messages. 2. It defines variables for the LDR pin, GSM send status, light reading sum, and SMS data. The setup function initializes the serial connection and GSM module. 3. The loop function reads the LDR, calculates the light level in cm, sends an SMS if the button is pressed and GSM send is not active, and resets the timer after sending. It uses functions to send commands to the GSM module, clear strings, and read serial data.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
61 views3 pages

GSM Codes

1. The document describes an Arduino sketch that measures light intensity with an LDR sensor, sends SMS messages with the light reading measurements via a GSM module, and includes functions for initializing the GSM module and sending SMS messages. 2. It defines variables for the LDR pin, GSM send status, light reading sum, and SMS data. The setup function initializes the serial connection and GSM module. 3. The loop function reads the LDR, calculates the light level in cm, sends an SMS if the button is pressed and GSM send is not active, and resets the timer after sending. It uses functions to send commands to the GSM module, clear strings, and read serial data.
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

char Rx_data[50]; int LDRPIN = A0; unsigned char Rx_index = 0; int i = 0; char msg[160]; int sig; char data[160];

String reader = ""; unsigned timer = 0; int gsmsend = 0; int sum = 0; long cm,inches; void setup() { Serial.begin(38400); pinMode(3,INPUT_PULLUP); initGSM(); } void loop() { int buttonstat = digitalRead(3); // ITO BABAGUHIN NIYO: int reading2 = analogRead(LDRPIN)/2; sum+=reading2; delay(10); inches = sum/60; cm = inches * 2.54; int reading = cm; // WAG NIYO NA GAGALAWIN: itoa(reading,data,10); if(buttonstat == 0 && gsmsend == 0) { gsmsend = 1; Serial.println("MESSAGE SENT!"); Serial.println(cm); send_msg("09151272080", data); // STRING? float to "char" } if(gsmsend == 1) {

timer++; delay(25); } if(timer == 100) { gsmsend = 0; timer = 0; } }

void send_msg(char *number, char *msg) { char at_cmgs_cmd[30] = { '\0' }; char msg1[160] = { '\0' }; char ctl_z = 0x1A; sprintf(msg1, "%s%c", msg, ctl_z); sprintf(at_cmgs_cmd, "AT+CMGS=\"%s\"\r\n",number); sendGSM(at_cmgs_cmd); delay(100); delay(100); delay(100); sendGSM(msg1); delay(100); } void sendGSM(char *string){ Serial.write(string); delay(90); } void clearString(char *strArray) { int j; for (j = 100; j > 0; j--) strArray[j] = 0x00; } void send_cmd(char *at_cmd, char clr){ char *stat = '\0'; while(!stat){ sendGSM(at_cmd); delay(90); readSerialString(Rx_data);

stat = strstr(Rx_data, "OK"); } if (clr){ clearString(Rx_data); delay(200); stat = '\0'; } }

// INITIALIZE GSM: void initGSM(){ send_cmd("AT\r\n",1); send_cmd("ATE0\r\n",1); // Turn off automatic echo of the GSM Module send_cmd("AT+CMGF=1\r\n",1); // Set message format to text mode //Sucess Serial.println("Success"); delay(1000); delay(1000); delay(1000); } void readSerialString (char *strArray) { if(!Serial.available()) { return; } while(Serial.available()) { strArray[i] = Serial.read(); i++; } }

You might also like