Millis for Alarm | SMS Sim 800L

Hello I'm new to Arduino.

I'm creating a project which is called "Illegal Parking Alarm". This project concerns about the illegal parking in streets which causes accidents or traffic. In our area, cars that are illegally parked will be clamped. I am concerned for both the authorities since they need to stroll around out area to check if there is illegal parking. So I've decided to create a project that will alarm the owner and send sms to authorities.

The main reason why am I here is because of the millis(); thingy. As I said, I am new to arduino. I wanted the alarm to start a timer when the sensor (ultrasonic) detected an obstacle so that it won't alarm immediately. I wanted it to wait for 5 mins before the alarm starts and message sends. The alarm works properly but I've never tried to put a timer. Also, the SMS is my concern. I am using SIM 800L and I am also new to it.

Please tell me where am I wrong or where are the parts I should fix. Thank you.

(I haven't inserted a program for millis since I don't know where to start)

#include<SoftwareSerial.h>

#define trigPin 9
#define echoPin 10
int Buzzer = 8;

SoftwareSerial mySerial(2, 3);

int normalDistance;
boolean triggered = false;
long duration;
long distance;

String number = "xxxxxxxxxx";

void setup() {
mySerial.begin(9600);
Serial.begin (9600);
pinMode(trigPin,OUTPUT);
pinMode(echoPin,INPUT);
pinMode(Buzzer,OUTPUT);

long duration, distance;
}

void loop() {
digitalWrite(trigPin,LOW);
delayMicroseconds(2);
digitalWrite(trigPin,HIGH);
delayMicroseconds(10);

digitalWrite(trigPin,LOW);

duration = pulseIn(echoPin,HIGH);
distance = duration /58.2;

if (distance >= 50||distance <= 0){
Serial.println("no object detected");
digitalWrite(Buzzer,LOW);
triggered = true;
}

else {
Serial.println("object detected");
delay(10);
tone(Buzzer,400);
delay(500);
tone(Buzzer,800);
delay(100);

noTone(Buzzer);

triggered = false;
}

if (triggered){
mySerial.println("AT+CMGF=1");
delay(150);

mySerial.println("AT+CMGS="+63"+number+""");
delay(150);

mySerial.println("CAR DETECTED!CAR DETECTED!");
mySerial.println((char)28);
delay(150);
mySerial.write((byte)0x1A);

delay(50);

mySerial.println();

}}

Please tell me where am I wrong or where are the parts I should fix. Thank you.

the first thing you got wrong is to use the quote tags instead of the code tags to post your code.. that makes it difficult to read

Please correct your post above and add code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code].

It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)


to your code:

I don't see any time management? you need some sort of a state machine where you remember that you detected something and if that does not change for a certain time ∆t, then you send the SMS. your triggered variable could be used for this.

  • why do you have  long duration, distance;at the end of the setup?

  • why is triggered set to false if you detect something ? don't you want this to be the case when you send the SMS ?