combining the rfid door lock code and the recieve sms-LED glow code
i making security system project , require rfid door lock , ultrasonic sensor test code , gsm code work 1 after other. tried on own rfid door lock , ultrasonic test code working while gsm part not working ie. led not glow when message sent. sending code tried. plzzzzzzzz asap!! urgent!!
#include <softwareserial.h>
softwareserial myserial(10, 11); // define softwareserial pin rx, tx
int gsmdriverpin[3] = {3,4,5}; // default digital driver pins gsm , gps mode
//if want change digital driver pins
//or have conflict d3~d5 on arduino board,
//you can remove j10~j12 jumpers reconnect other driver pins module!
int ledpin = 8;
char inchar;
int c, rfidarray[10];
int res = 0;
int passwordarray[10] = {50,53,49,49,56,52,49,50,13,10}; //store password elements here
int ledpin = 12;
void initgsm()
{
for(int = 0 ; < 3; i++){
pinmode(gsmdriverpin,output);
}
pinmode(ledpin,output);
digitalwrite(5,high); //output gsm timing
delay(1500);
digitalwrite(5,low);
digitalwrite(3,low); //enable gsm mode
digitalwrite(4,high); //disable gps mode
delay(5000); //call ready
delay(5000);
myserial.println("at+cmgd=1,4"); //delete sms in box
}
void setup()
{
serial.begin(9600);
myserial.begin(9600); //set softwareserial port baud rate
initgsm(); //initialize gsm module
pinmode(ledpin, output);
pinmode(13,output);
pinmode(2,output);//attach pin 2 of ultrasonic sensor vcc
pinmode(5,output);//attach pin 5 of ultrasonic sensor gnd
/*--- rfid part begins ---*/
while(res==0){
for(int = 0; i< 10; i++){
while(!(serial.available()));// start collecting rfid information
c = serial.read();
rfidarray = c;
//serial.println(rfidarray);
// wait next character arrive @ serial
}
// have data rfid card.
// let's compare passwordarray
for(int = 0; i< 10; i++){
if(rfidarray!=passwordarray){
res = 0;
break;
}
else
res = 1;
}
// let's check res, , light green led & run motor if right card swiped
if(res == 0)
{
digitalwrite(ledpin, low);
}
else
{
digitalwrite(ledpin, high);
delay(3000);
digitalwrite(ledpin, low);
}
}
/*--- if wrong rfid, go back, else come out , start checking ultrasonic ---*/
}
void loop() // run on , over
{
/*--begin ultrasonic code--*/
digitalwrite(2, high);
// establish variables duration of ping,
// , distance result in inches , centimeters:
long duration, inches, cm;
// ping))) triggered high pulse of 2 or more microseconds.
// give short low pulse beforehand ensure clean high pulse:
pinmode(3, output);// attach pin 3 trig
digitalwrite(3, low);
delaymicroseconds(2);
digitalwrite(3, high);
delaymicroseconds(5);
digitalwrite(3, low);
// same pin used read signal ping))): high
// pulse duration time (in microseconds) sending
// of ping reception of echo off of object.
pinmode (4, input);//attach pin 4 echo
duration = pulsein(4, high);
// convert time distance
inches = microsecondstoinches(duration);
cm = microsecondstocentimeters(duration);
if(inches < 4)
digitalwrite(13,high);
else
digitalwrite(13,low);
/*---- end of ultrasonic code -----*/
/*---- gsm part ----*/
if(myserial.available()>0)
{
inchar=myserial.read();
//serial.print(inchar); //display gps/gprs/gsm module status
if(inchar=='t')
{
delay(10);
inchar=myserial.read();
if (inchar=='i') //when gsm module message, display sign '+cmti "sm", 1' in softwareserial port
{
delay(10);
myserial.println("at+cmgr=1"); //when arduino read sign, send "read" @ command module
delay(10);
}
}
else if (inchar=='a')
{
delay(10);
inchar=myserial.read();
if (inchar=='c') //thw sms("lh") display in softwareserial port, , arduino has recognize it.
{
delay(10);
digitalwrite(ledpin,high); //turn on led
delay(50);
myserial.println("at+cmgd=1,4"); //delete message
delay(500);
}
if (inchar=='o') //thw sms("lh") display in softwareserial port, , arduino has recognize it.
{
delay(10);
digitalwrite(ledpin,low); //turn off led
delay(50);
myserial.println("at+cmgd=1,4");//delete message
delay(500);
}
}
}
}
long microsecondstoinches(long microseconds)
{
// according parallax's datasheet ping))), there are
// 73.746 microseconds per inch (i.e. sound travels @ 1130 feet per
// second). gives distance travelled ping, outbound
// , return, divide 2 distance of obstacle.
// see: http://www.parallax.com/dl/docs/prod/acc/28015-ping-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondstocentimeters(long microseconds)
{
// speed of sound 340 m/s or 29 microseconds per centimeter.
// ping travels out , back, find distance of the
// object take half of distance travelled.
return microseconds / 29 / 2;
}
#include <softwareserial.h>
softwareserial myserial(10, 11); // define softwareserial pin rx, tx
int gsmdriverpin[3] = {3,4,5}; // default digital driver pins gsm , gps mode
//if want change digital driver pins
//or have conflict d3~d5 on arduino board,
//you can remove j10~j12 jumpers reconnect other driver pins module!
int ledpin = 8;
char inchar;
int c, rfidarray[10];
int res = 0;
int passwordarray[10] = {50,53,49,49,56,52,49,50,13,10}; //store password elements here
int ledpin = 12;
void initgsm()
{
for(int = 0 ; < 3; i++){
pinmode(gsmdriverpin,output);
}
pinmode(ledpin,output);
digitalwrite(5,high); //output gsm timing
delay(1500);
digitalwrite(5,low);
digitalwrite(3,low); //enable gsm mode
digitalwrite(4,high); //disable gps mode
delay(5000); //call ready
delay(5000);
myserial.println("at+cmgd=1,4"); //delete sms in box
}
void setup()
{
serial.begin(9600);
myserial.begin(9600); //set softwareserial port baud rate
initgsm(); //initialize gsm module
pinmode(ledpin, output);
pinmode(13,output);
pinmode(2,output);//attach pin 2 of ultrasonic sensor vcc
pinmode(5,output);//attach pin 5 of ultrasonic sensor gnd
/*--- rfid part begins ---*/
while(res==0){
for(int = 0; i< 10; i++){
while(!(serial.available()));// start collecting rfid information
c = serial.read();
rfidarray = c;
//serial.println(rfidarray);
// wait next character arrive @ serial
}
// have data rfid card.
// let's compare passwordarray
for(int = 0; i< 10; i++){
if(rfidarray!=passwordarray){
res = 0;
break;
}
else
res = 1;
}
// let's check res, , light green led & run motor if right card swiped
if(res == 0)
{
digitalwrite(ledpin, low);
}
else
{
digitalwrite(ledpin, high);
delay(3000);
digitalwrite(ledpin, low);
}
}
/*--- if wrong rfid, go back, else come out , start checking ultrasonic ---*/
}
void loop() // run on , over
{
/*--begin ultrasonic code--*/
digitalwrite(2, high);
// establish variables duration of ping,
// , distance result in inches , centimeters:
long duration, inches, cm;
// ping))) triggered high pulse of 2 or more microseconds.
// give short low pulse beforehand ensure clean high pulse:
pinmode(3, output);// attach pin 3 trig
digitalwrite(3, low);
delaymicroseconds(2);
digitalwrite(3, high);
delaymicroseconds(5);
digitalwrite(3, low);
// same pin used read signal ping))): high
// pulse duration time (in microseconds) sending
// of ping reception of echo off of object.
pinmode (4, input);//attach pin 4 echo
duration = pulsein(4, high);
// convert time distance
inches = microsecondstoinches(duration);
cm = microsecondstocentimeters(duration);
if(inches < 4)
digitalwrite(13,high);
else
digitalwrite(13,low);
/*---- end of ultrasonic code -----*/
/*---- gsm part ----*/
if(myserial.available()>0)
{
inchar=myserial.read();
//serial.print(inchar); //display gps/gprs/gsm module status
if(inchar=='t')
{
delay(10);
inchar=myserial.read();
if (inchar=='i') //when gsm module message, display sign '+cmti "sm", 1' in softwareserial port
{
delay(10);
myserial.println("at+cmgr=1"); //when arduino read sign, send "read" @ command module
delay(10);
}
}
else if (inchar=='a')
{
delay(10);
inchar=myserial.read();
if (inchar=='c') //thw sms("lh") display in softwareserial port, , arduino has recognize it.
{
delay(10);
digitalwrite(ledpin,high); //turn on led
delay(50);
myserial.println("at+cmgd=1,4"); //delete message
delay(500);
}
if (inchar=='o') //thw sms("lh") display in softwareserial port, , arduino has recognize it.
{
delay(10);
digitalwrite(ledpin,low); //turn off led
delay(50);
myserial.println("at+cmgd=1,4");//delete message
delay(500);
}
}
}
}
long microsecondstoinches(long microseconds)
{
// according parallax's datasheet ping))), there are
// 73.746 microseconds per inch (i.e. sound travels @ 1130 feet per
// second). gives distance travelled ping, outbound
// , return, divide 2 distance of obstacle.
// see: http://www.parallax.com/dl/docs/prod/acc/28015-ping-v1.3.pdf
return microseconds / 74 / 2;
}
long microsecondstocentimeters(long microseconds)
{
// speed of sound 340 m/s or 29 microseconds per centimeter.
// ping travels out , back, find distance of the
// object take half of distance travelled.
return microseconds / 29 / 2;
}
edit post , include code tags!
Arduino Forum > Using Arduino > Project Guidance > combining the rfid door lock code and the recieve sms-LED glow code
arduino
Comments
Post a Comment