Professional Documents
Culture Documents
Code tham kho trn Arduino, iu khin bt/tt thit b bng cch gi tin
nhn ti Module Sim900A
AT<CR><LF>
L nh:
ATE[x]<CR><LF>
L nh:
AT+IPR=[baud rate]<CR><LF>
baud rate :
ATD[S _in_thoai];<CR><LF>
L nh:
ATH<CR><LF>
ATA<CR><LF>
AT+CLIP=1<CR><LF>
AT+CMGF=1<CR><LF>
C u truc gi tin nh n
L nh:
AT+CMGS=S _i n _thoai<CR><LF>
i n khi co ky t > c gi v
Gi ni dung tin nh n : This is a test
Gi ma Ctrl+Z hay 0x1A k t thuc ni dung va gi tin nh n
Tra li : OK<CR><LF>
L nh:
AT+CMGR=1<CR><LF>
Chu n bi ph n cng v kt ni
1 Ngu n 12VDC/1A
1 Sim b t k (co th nghe , goi c)
1 Sim900A Shield
1 Uno VN01
1 Module Relay 12V
1 thit b in m bn mun iu khin. Trong bi hng dn ny mnh s dng
bong en 12V.
Dy k t ni
Ban co th xem hn
h se th y trc quan hn
Quy trn
h k t n i ,
n gin, ch cn c m Shield Sim900A ln kit Arduino Uno
new 1
// Bai toan : nhan tin dieu khien bat tat bong den
// Neu noi dung tin nhan la : LAMP_ON
thi bat bong den
// Neu noi dung tin nhan la : LAMP_OFF
thi tat bong den
void Gsm_Power_On();
void Gsm_Init();
Sim 900A
void Gsm_MakeCall(String phone);
void Gsm_MakeSMS(String phone,String content);
void setup() {
Serial.begin(9600);
digitalWrite(RELAY, LOW);
pinMode(RELAY, OUTPUT);
digitalWrite(PWR_KEY, LOW);
Sim 900A
pinMode(PWR_KEY, OUTPUT);
delay(1000);
Gsm_Power_On();
delay(10000);
Gsm_Init();
Gsm_MakeCall(myphone);
Gsm_MakeSMS(myphone,"I'm a test");
}
void loop() {
delay(1000);
Index_Lamp_On = RxBuff.indexOf("LAMP_ON");
trong bo dem nhan RxBuff
if(Index_Lamp_On >= 0)
"LAMP_ON" trong RxBuff
{
Index_Lamp_On = -1;
RxBuff = "";
dem
digitalWrite(RELAY, HIGH);
bat den // Bat bong den
}
// tre 1s
// Tim vi tri cua chuoi "LAMP_ON"
// Neu tim thay
//
// Xoa bo
// Dong Relay de
-1-
new 1
else
{
//
Neu khong tim thay "LAMP_ON" thi tiep tuc tim "LAMP_OFF"
Index_Lamp_Off = RxBuff.indexOf("LAMP_OFF");
// Tim vi tri cua chuoi "LAMP_OFF"
trong bo dem nhan RxBuff
if(Index_Lamp_Off >= 0)
// Neu tim thay
"LAMP_OFF" trong RxBuff
{
Index_Lamp_Off = -1;
//
RxBuff = "";
// Xoa bo
dem
digitalWrite(RELAY, LOW);
// Cat Relay de
tat den
}
}
}
void serialEvent() {
lieu
while (Serial.available()) {
// get the new byte:
char inChar = (char)Serial.read();
RxBuff += inChar;
RxBuff (ta se xu ly RxBuff trong vong loop())
if(RxBuff.length()>= 128)
dem di
{
RxBuff = "";
}
}
}
void Gsm_Power_On()
{
digitalWrite(PWR_KEY, HIGH);
delay(1500);
digitalWrite(PWR_KEY, LOW);
delay(100);
designed sim900A de hieu ro hon
}
void Gsm_Init()
{
Serial.println("ATE0");
delay(2000);
Serial.println("AT+IPR=9600");
delay(2000);
Serial.println("AT+CMGF=1");
delay(2000);
Serial.println("AT+CLIP=1");
delay(2000);
Serial.println("AT+CNMI=2,2");
delay(2000);
}
new 1
// Goi dien
// Sau 10s
// Ngat cuoc goi
}
void Gsm_MakeSMS(String phone,String content)
{
Serial.println("AT+CMGS=\"" + phone + "\"");
delay(3000);
ve
Serial.print(content);
Serial.print((char)26);
ket thuc noi dung tin nhan va gui tin di
delay(5000);
}
-3-
http://smart-techvn.com/bai-viet-ki-thuat/huong-dan-su-dung-cac-module/9216-huongdan-lap-trinh-module-sim900a-va-arduino.html