So I am making an arduino project for my school wherein if there is any overspeeding, the rfid of the car is recorded and sent to any department handling with such cases. But the problem is I want to store the entire rfid value in one variable but I am confused on how to do that. I got the rfid value to be printed in the Serial monitor but I really dont know how to send it in a single message. Any help would be appreciated.
Here's my code so far:
#include <LiquidCrystal.h>
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3);
const int pin_RS = 8;
const int pin_EN = 9;
const int pin_d4 = 4;
const int pin_d5 = 5;
const int pin_d6 = 6;
const int pin_d7 = 7;
const int pin_BL = 10;
LiquidCrystal lcd( pin_RS, pin_EN, pin_d4, pin_d5, pin_d6, pin_d7);
int timer1;
int timer2;
float Time;
int flag1 = 0;
int flag2 = 0;
int i;
float distance = 5.0;
float speed;
char value = 0;
String serialmonitor = "Unique ID of overspeeding car: ";
String space = " ";
int ir_s1 = A6;
int ir_s2 = A7;
int buzzer = 22;
void setup(){
pinMode(ir_s1, INPUT);
pinMode(ir_s2, INPUT);
pinMode(buzzer, OUTPUT);
lcd.begin(16,2);
lcd.clear();
lcd.setCursor(0,0);
Serial.begin(9600);
mySerial.begin(9600);
}
void loop() {
if(digitalRead (ir_s1) == LOW && flag1==0){
timer1 = millis(); flag1=1;
}
if(digitalRead (ir_s2) == LOW && flag2==0){
timer2 = millis(); flag2=1;
}
if (flag1==1 && flag2==1){
if(timer1 > timer2){
Time = timer1 - timer2;
}
else if(timer2 > timer1){Time = timer2 - timer1;}
Time=Time/1000;//convert millisecond to second
speed=(distance/Time);
speed=speed*3600;
speed=speed/1000;
}
if(speed==0){
lcd.setCursor(0, 1);
if(flag1==0 && flag2==0){
lcd.print("No car detected");
//Serial.println("No car detected");
}
else{
lcd.print("Searching... ");
//Serial.println("Searching...");
}}
else{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Speed:");
Serial.println("Speed: ");
lcd.print(speed,1);
Serial.print(speed,1);
lcd.print("km/hr ");
Serial.print(" Km/Hr");
lcd.setCursor(0, 1);
if(speed > 100){
lcd.print(" Over Speeding ");
Serial.println(" Over Speeding");
digitalWrite(buzzer, HIGH);
if(Serial.available()>0)
Serial.println(serialmonitor + space);
for(i=1;i<=12;i++) {
if(Serial.available()>0) {
value = Serial.read();
Serial.print(value);
}}
mySerial.println("AT+CMGF=1"); //Sets the GSM Module in Text Mode
delay(1000);
mySerial.println("AT+CMGS=\"+xxxxxxxxxxxx\"\r");
delay(1000);
mySerial.println(serialmonitor + space + value);
delay(100);
mySerial.println((char)26);// ASCII code of CTRL+Z
delay(1000);
}
else{
lcd.print(" Normal Speed ");
Serial.println(" Normal Speed");
}
delay(3000);
digitalWrite(buzzer, LOW);
speed = 0;
flag1 = 0;
flag2 = 0;
}}