I am really very sorry for the short forms... sorry..
and yes I am from India...
Thanku soo much for your suggestions..
I am attaching my code below with what I could come up till now... kindly have a look on it.. also I have made a rough wiring diagram...
#include <LiquidCrystal.h>
#include <SPI.h>
#include <MMA_7455.h>
#include <MFRC522.h>
#include <Adafruit_GPS.h>
#include <SoftwareSerial.h>
int SS_PIN = 14;
int RST_PIN = 9;
SoftwareSerial gsm(10,9);
SoftwareSerial mySerial(16,15 );
MMA_7455 tilt = MMA_7455(); //Make an instance of MMA_7455
LiquidCrystal lcd(0, 1, 5, 4, 3, 2);
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
Adafruit_GPS GPS(&mySerial);
char xVal, yVal, zVal;
int backLight = 6;
int TRIGPIN = 7;
int ECHOPIN = 8;
int pir = 17;
int pirState = LOW;
int val = 0;
int speaker = 13;
int red = 12;
int green = 11;
#define GPSECHO true
#define MASTERCARD 4294943745
void setup() {
SPI.begin();
Serial.begin(9600);
pinMode(backLight, OUTPUT);
digitalWrite(backLight, HIGH);
lcd.begin(16, 2);
lcd.clear();
lcd.print(F("Please Insert Ur"));
lcd.setCursor(2,1);
lcd.print(F("MASTERCARD"));
delay(10000);
digitalWrite(backLight, LOW);
delay(2000);
digitalWrite(backLight, HIGH);
delay(1000);
digitalWrite(backLight,LOW);
delay(100);
tilt.initSensitivity(2);
mfrc522.PCD_Init(); // Init MFRC522
mfrc522.PCD_DumpVersionToSerial();
Serial.println(F("PLease Scan Your MASTERCARD..."));
pinMode(ECHOPIN, INPUT);
pinMode(TRIGPIN, OUTPUT);
pinMode(red, OUTPUT);
pinMode(green,OUTPUT);
pinMode(pir, INPUT);
pinMode(speaker, OUTPUT);
GPS.begin(9600);
GPS.sendCommand(PMTK_SET_NMEA_OUTPUT_RMCGGA);
GPS.sendCommand(PMTK_SET_NMEA_UPDATE_1HZ); // 1 Hz update rate
GPS.sendCommand(PGCMD_ANTENNA);
}
/*Code to get Card UID */
unsigned long getID(){
if ( ! mfrc522.PICC_ReadCardSerial()){
return -1;
}
unsigned long hex_num;
hex_num = mfrc522.uid.uidByte[0] << 24;
hex_num += mfrc522.uid.uidByte[1] << 16;
hex_num += mfrc522.uid.uidByte[2] << 8;
hex_num += mfrc522.uid.uidByte[3];
mfrc522.PICC_HaltA(); // Stop reading
return hex_num;
}
void loop() {
analogWrite(SS_PIN,100);
unsigned long uid;
if(mfrc522.PICC_IsNewCardPresent()) {
uid = getID();
if(uid != -1)
{
Serial.print(F("Card detected, UID: ")); Serial.println(uid);
if(uid==MASTERCARD){
delay(10);
lcd.clear();
lcd.print(F("Enjoy Your Drive.. "));
lcd.setCursor(0,1);
lcd.print(F(":)"));
pinMode(backLight,HIGH);
delay(10000);
lcd.clear();
digitalWrite(green,HIGH);
delay(1000);
digitalWrite(green,LOW);
delay(1000);
digitalWrite(green,HIGH);
xVal = tilt.readAxis('x'); //Read out the 'x' Axis
yVal = tilt.readAxis('y'); //Read out the 'y' Axis
zVal = tilt.readAxis('z'); //Read out the 'z' Axis
if (xVal < -20 || xVal > 20 || zVal < -45 )
{
Serial.println("");
tone(speaker, 500, 1000);
lcd.clear();
lcd.setCursor(2,0);
lcd.print(F("Accident"));
lcd.setCursor(2,1);
lcd.print(F("Detected"));
digitalWrite(red,HIGH);// turn LED On
delay(1000);
digitalWrite(red,LOW);// turn LED On
//GPS CODING...!!!!!
/*
if (! usingInterrupt) {
// read data from the GPS in the 'main loop'
char c = GPS.read();
// if you want to debug, this is a good time to do it!
if (GPSECHO)
if (c) Serial.print(c);
}
// if a sentence is received, we can check the checksum, parse it...
if (GPS.newNMEAreceived()) {
if (!GPS.parse(GPS.lastNMEA())) // this also sets the newNMEAreceived() flag to false
return; // we can fail to parse a sentence in which case we should just wait for another
}
// if millis() or timer wraps around, we'll just reset it
if (timer > millis()) timer = millis();
// approximately every 2 seconds or so, print out the current stats
if (millis() - timer > 2500) {
timer = millis(); // reset the timer
Serial.print("\nTime: ");
Serial.print(GPS.hour, DEC); Serial.print(':');
Serial.print(GPS.minute, DEC); Serial.print(':');
Serial.print(GPS.seconds, DEC); Serial.print('.');
Serial.println(GPS.milliseconds);
Serial.print("Date: ");
Serial.print(GPS.day, DEC); Serial.print('/');
Serial.print(GPS.month, DEC); Serial.print("/20");
Serial.println(GPS.year, DEC);
Serial.print("Fix: "); Serial.print((int)GPS.fix);
Serial.print(" quality: "); Serial.println((int)GPS.fixquality);
*/
if (GPS.fix) {
Serial.print("Location: ");
Serial.print(GPS.latitude, 4); Serial.print(GPS.lat);
Serial.print(", ");
Serial.print(GPS.longitude, 4); Serial.println(GPS.lon);
Serial.print("Location (in degrees, works with Google Maps): ");
Serial.print(GPS.latitudeDegrees, 4);
Serial.print(", ");
Serial.println(GPS.longitudeDegrees, 4);
Serial.print("Speed (knots): "); Serial.println(GPS.speed);
Serial.print("Angle: "); Serial.println(GPS.angle);
Serial.print("Altitude: "); Serial.println(GPS.altitude);
Serial.print("Satellites: "); Serial.println((int)GPS.satellites);
//delay(10000);
Serial.println("");
Serial.println("Sending to Database...");
Serial.println("");
Serial.println("");
}
// Ultrasonic Sensor...!!!!
digitalWrite(TRIGPIN, LOW);
delayMicroseconds(1000);
digitalWrite(TRIGPIN, HIGH);
delayMicroseconds(1000);
digitalWrite(TRIGPIN, LOW);
//Distance calculation
float distance = pulseIn(ECHOPIN, HIGH);
distance= distance/58;
delay(1000);
if (distance>=2 && distance<=50){
lcd.clear();
lcd.setCursor(1,0);
lcd.print(distance);
lcd.println(F(" cm"));
lcd.setCursor(3,1);
lcd.print("DANGER");
digitalWrite(red,HIGH);
tone(speaker, 500, 500);
Serial.println("");
}
else {
lcd.clear();
digitalWrite(red,LOW);
noTone(speaker);
}
}
}
// IF FAKE CARD INSERTED...!!!
else {
lcd.clear();
lcd.setCursor(0,0);
lcd.println(F("Access Denied..."));
lcd.clear();
lcd.setCursor(0,1);
lcd.println(F(":( ..."));
digitalWrite(TRIGPIN, LOW);
tone(speaker, 500, 500);
exit;
}
}
// PIR MOTIION SENSOR WHEN CARD IS ABSENT....!!!
else
{
digitalWrite(TRIGPIN, LOW);
val = digitalRead(pir); // read Sensor_Pin
if (val == HIGH) // check if the input is HIGH
{
digitalWrite(red,HIGH); // turn LED On
tone(speaker, 500, 500);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(F("UNAUTHORISED"));
lcd.setCursor(2,1);
lcd.print("ACCESS...");
}
else {
digitalWrite(red,LOW);
noTone(speaker);
}
}
}
I am using the ICSP pins for RFID