Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SoftwareSerial.h>
- SoftwareSerial mySerial(10, 11); // 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 = 8;
- char inchar;
- int c, rfidArray[10];
- int res = 0;
- int passwordArray[10] = {50,53,49,49,56,52,49,50,13,10}; //Store the password elements here
- int ledPin = 12;
- 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);
- mySerial.begin(9600); //set SoftwareSerial port baud rate
- InitGsm(); //initialize GSM module
- digitalWrite(7,LOW);
- pinMode(7,OUTPUT);
- pinMode(ledPin, OUTPUT);
- pinMode(13,OUTPUT);
- pinMode(2,OUTPUT);//attach pin 2 of Ultrasonic Sensor to vcc
- pinMode(5,OUTPUT);//attach pin 5 of Ultrasonic Sensor to GND
- /*--- RFID PART BEGINS ---*/
- while(res==0){
- for(int i = 0; i< 10; i++){
- while(!(Serial.available()));// Start collecting the RFID information
- c = Serial.read();
- rfidArray[i] = c;
- //Serial.println(rfidArray[i]);
- // Wait for next character to arrive at Serial
- }
- // So now we have all the data from the RFID card.
- // Let's compare with passwordArray
- for(int i = 0; i< 10; i++){
- if(rfidArray[i]!=passwordArray[i]){
- res = 0;
- break;
- }
- else
- res = 1;
- }
- // Let's check res, and light up the green LED & run Motor if the right card was swiped
- if(res == 0)
- {
- digitalWrite(ledPin, LOW);
- }
- else
- {
- digitalWrite(ledPin, HIGH);
- delay(3000);
- digitalWrite(ledPin, LOW);
- }
- }
- /*--- If wrong RFID, go back, else come out and start checking Ultrasonic ---*/
- }
- void loop() // run over and over
- {
- /*--BEGIN ULTRASONIC Code--*/
- digitalWrite(2, HIGH);
- // establish variables for duration of the ping,
- // and the distance result in inches and centimeters:
- long duration, inches, cm;
- // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
- // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
- pinMode(3, OUTPUT);// attach pin 3 to Trig
- digitalWrite(3, LOW);
- delayMicroseconds(2);
- digitalWrite(3, HIGH);
- delayMicroseconds(5);
- digitalWrite(3, LOW);
- // The same pin is used to read the signal from the PING))): a HIGH
- // pulse whose duration is the time (in microseconds) from the sending
- // of the ping to the reception of its echo off of an object.
- pinMode (4, INPUT);//attach pin 4 to Echo
- duration = pulseIn(4, HIGH);
- // convert the time into a 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)
- {
- digitalWrite(7,HIGH);
- 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=='A')
- {
- delay(10);
- inchar=mySerial.read();
- if (inchar=='C') //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=='O') //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);
- }
- }
- }
- }
- long microsecondsToInches(long microseconds)
- {
- // According to Parallax's datasheet for the PING))), there are
- // 73.746 microseconds per inch (i.e. sound travels at 1130 feet per
- // second). This gives the distance travelled by the ping, outbound
- // and return, so we divide by 2 to get the distance of the obstacle.
- // See: http://www.parallax.com/dl/docs/prod/acc/28015-PING-v1.3.pdf
- return microseconds / 74 / 2;
- }
- long microsecondsToCentimeters(long microseconds)
- {
- // The speed of sound is 340 m/s or 29 microseconds per centimeter.
- // The ping travels out and back, so to find the distance of the
- // object we take half of the distance travelled.
- return microseconds / 29 / 2;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement