-
-
Save carlosdelfino/e86446ca0439999b7044 to your computer and use it in GitHub Desktop.
um exemplo de código para envio de SMS, o codigo pode ser melhorado e optimizado em muitos pontos.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SoftwareSerial.h> | |
SoftwareSerial mySerial(2, 3); //RX, TX | |
//Ligando o Shield GSM SIM900. | |
int powerkey = 5; | |
int statuspin = 6; | |
int pinState = 0; | |
//Definindo Botao: | |
const int buttonPin = 13; | |
const int buttonPin2 = 12; | |
const int buttonPin3 = 11; | |
const int buttonPin4 = 10; | |
const int buttonPin5 = 9; | |
//Variavel de Apoio: | |
bool buttonState = LOW; | |
bool buttonState2 = LOW; | |
bool buttonState3 = LOW; | |
bool buttonState4 = LOW; | |
bool buttonState5 = LOW; | |
void setup() | |
{ | |
pinMode(buttonPin, INPUT); | |
pinMode(buttonPin2, INPUT); | |
pinMode(buttonPin3, INPUT); | |
pinMode(buttonPin4, INPUT); | |
pinMode(buttonPin5, INPUT); | |
pinMode(powerkey, OUTPUT); | |
pinMode(statuspin, INPUT); | |
//Serial Por Software Para o SIM900 Funcionar. | |
mySerial.begin(9600); | |
Serial.begin(9600); | |
//Delay Necessario Para o SIM900 Estabilizar. | |
delay(10000); | |
} | |
void loop() | |
{ | |
pinState = digitalRead(statuspin); | |
if (pinState == LOW) { | |
digitalWrite(powerkey, HIGH); | |
delay(2000); | |
digitalWrite(powerkey, LOW); | |
} | |
buttonState = digitalRead(buttonPin); | |
if (buttonState == HIGH) | |
{ | |
delay(20000); | |
mySerial.println("AT+CMGF=1"); | |
delay(200); | |
mySerial.print("AT+CMGS="); | |
mySerial.write(byte(34)); | |
mySerial.print("11974389125"); | |
mySerial.write(byte(34)); | |
mySerial.println(); | |
delay(200); | |
mySerial.print("A porta do motorista foi aberta."); | |
mySerial.write(byte(26)); | |
while (1); | |
} | |
buttonState2 = digitalRead(buttonPin2); | |
if (buttonState2 == HIGH) | |
{ | |
delay(20000); | |
mySerial.println("AT+CMGF=1"); | |
delay(200); | |
mySerial.print("AT+CMGS="); | |
mySerial.write(byte(34)); | |
mySerial.print("11974389125"); | |
mySerial.write(byte(34)); | |
mySerial.println(); | |
delay(200); | |
mySerial.print("A porta do passageiro foi aberta."); | |
mySerial.write(byte(26)); | |
while (1); | |
} | |
buttonState3 = digitalRead(buttonPin3); | |
if (buttonState3 == HIGH) | |
{ | |
delay(20000); | |
mySerial.println("AT+CMGF=1"); | |
delay(200); | |
mySerial.print("AT+CMGS="); | |
mySerial.write(byte(34)); | |
mySerial.print("11974389125"); | |
mySerial.write(byte(34)); | |
mySerial.println(); | |
delay(200); | |
mySerial.print("A porta de tras do motorista foi aberta."); | |
mySerial.write(byte(26)); | |
while (1); | |
} | |
buttonState4 = digitalRead(buttonPin4); | |
if (buttonState4 == HIGH) | |
{ | |
delay(20000); | |
mySerial.println("AT+CMGF=1"); | |
delay(200); | |
mySerial.print("AT+CMGS="); | |
mySerial.write(byte(34)); | |
mySerial.print("11974389125"); | |
mySerial.write(byte(34)); | |
mySerial.println(); | |
delay(200); | |
mySerial.print("A de tras porta do passageiro foi aberta."); | |
mySerial.write(byte(26)); | |
while (1); | |
} | |
buttonState5 = digitalRead(buttonPin5); | |
if (buttonState5 == HIGH) | |
{ | |
delay(20000); | |
mySerial.println("AT+CMGF=1"); | |
delay(200); | |
mySerial.print("AT+CMGS="); | |
mySerial.write(byte(34)); | |
mySerial.print("11974389125"); | |
mySerial.write(byte(34)); | |
mySerial.println(); | |
delay(200); | |
mySerial.print("O porta malas foi aberto."); | |
mySerial.write(byte(26)); | |
while (1); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment