如何使用Arduino和Gprs Shield V2.1开启/关闭Led,代码如下 [英] How Can I Turn Led On/Off With Arduino And Gprs Shield V2.1 With The Code Below
本文介绍了如何使用Arduino和Gprs Shield V2.1开启/关闭Led,代码如下的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// Product name: GPS/GPRS/GSM Module V3.0
// # Product SKU : TEL0051
// # Description:
// # The sketch for controling the GSM/GPRS/GPS module via SMS.
// # Steps:
// # 1. Curved the pin 0 and 1. Make sure when you plug the module to UNO, they won't connect to the RX and TX.
// # 2. At the same time , connect P0 to P10, and P1 to P11 by jumper cable.
// # 3. Upload the sketch to the Arduino board(Make sure turn off other Serial monitor )
// # 4. Turn the S1 switch to the comm(left side)
// # 6. Turn the S2 switch to the Arduino(right side)
// # 7. RST the board until the START led is on(make sure you have >6V power supply)
// # 8. Plug the long side of LED into pin 8 and short side into GND
// # 9. Start sending "LH" and "LL" to your board to turn LED on and off.
/*
* created: 2013-11-14
* by: Grey
* Version: 0.3
* Attention: if you send the wrong SMS command to the module, just need to press RST.
* This version use the SoftwareSerial port. You can check the status of the module in the serial port for debuging
*/
#include <SoftwareSerial.h>
SoftwareSerial mySerial(0, 1); // Define SoftwareSerial pin RX, TX
int gsmDriverPin[3] = {
3,4,5}; //The default digital driver pins for the GSM and GPS mode
//If you want to change the digital driver pins
//or you have a conflict with D3~D5 on Arduino board,
//you can remove the J10~J12 jumpers to reconnect other driver pins for the module!
int ledpin = 6;
char inchar;
void InitGsm()
{
for(int i = 0 ; i < 3; i++)
{
pinMode(gsmDriverPin[i],OUTPUT);
}
pinMode(ledpin,OUTPUT);
digitalWrite(5,HIGH); //Output GSM Timing
delay(1500);
digitalWrite(5,LOW);
digitalWrite(3,LOW); //Enable the GSM mode
digitalWrite(4,HIGH); //Disable the GPS mode
delay(5000); //call ready
delay(5000);
mySerial.println("AT+CMGD=1,4"); //Delete all SMS in box
}
void setup()
{
Serial.begin(9600); //set Serial port baud rate
mySerial.begin(9600); //set SoftwareSerial port baud rate
InitGsm(); //initialize GSM module
}
void loop()
{
if(mySerial.available()>0)
{
inchar=mySerial.read();
Serial.print(inchar); //Display the GPS/GPRS/GSM Module status
if(inchar=='T')
{
delay(10);
inchar=mySerial.read();
if (inchar=='I') //When the GSM module get the message, it will display the sign '+CMTI "SM", 1' in the SoftwareSerial port
{
delay(10);
mySerial.println("AT+CMGR=1"); //When Arduino read the sign, send the "read" AT command to the module
delay(10);
}
}
else if (inchar=='L')
{
delay(10);
inchar=mySerial.read();
if (inchar=='H') //Thw SMS("LH") was display in the SoftwareSerial port, and Arduino has recognize it.
{
delay(10);
digitalWrite(ledpin,HIGH); //Turn on led
delay(50);
mySerial.println("AT+CMGD=1,4"); //Delete all message
delay(500);
}
if (inchar=='L') //Thw SMS("LH") was display in the SoftwareSerial port, and Arduino has recognize it.
{
delay(10);
digitalWrite(ledpin,LOW); //Turn off led
delay(50);
mySerial.println("AT+CMGD=1,4");//Delete all message
delay(500);
}
}
}
}
推荐答案
如何打开LED使用arduino M10 gsm盾牌
how to turn on a led with arduino M10 gsm shield
这篇关于如何使用Arduino和Gprs Shield V2.1开启/关闭Led,代码如下的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文