Anti theft and carjacking car alarm

Hi!

My name is Pierre, I’m from France, I like to build things myself and work on cars or RC things (planes, boats, cars…)

I’m fairly new to Arduino which I’m discovering with the projects from the book it came with and this will be my first real project for an everyday use.

I’m starting this topic to show what I’m doing and maybe help other people with a similar project and also to benefit from constructive criticism from people on the forum.

The Project :

Since I couldn’t find on the Internet a device simple and matching my needs for an affordable price I decided to build my own alarm system for my classic car (1994 Rover Mini Cooper).

What I want is that if someone breaks in the car and hotwire it (I thinks that’s how you guys say it ;)), the Arduino will start the hazard lights after something like 5 minutes, then after another minute turn the horn ON and OFF and at last after another minute shut the engine off (by cutting either the fuel pump or the ignition).

Ideally I would like the system to be reset by a combination of two buttons.

The Arduino will be powered by a step down 5 or 3 volt supply and the signal to set the alarm will come from the door switch (for the interior lights) and the 12V ignition (I don’t want the alarm to start if I forget my phone into the car or my wife her purse).

The alarm would also be useful in case of a carjacking because if someone opens the door and the ignition is ON, the alarm will start.

I played a little with the code and built a small scale circuit with 4LEDs and 4 switches and it’s working well for now.

//Global Variables
const int doorSwitch = 2; // our door signal
const int ignitionSwitch = 3; // our ignition signal
const int button1 = 4; // our button 1
const int button2 = 5; // our button 2
const int LED = 13; // to ON LED
const int hazard = 12; // to hazard lights
const int horn = 11; // to car horn
const int relay = 10; // to latchning relay (cuts off fuel pump)
int hornState = LOW;
 
unsigned long alarmOnMillis; // when alarm was activated
unsigned long hazardTurnOnDelay = 3000; // wait to turn on hazard
unsigned long hornTurnOnDelay = 4000; // wait to turn on horn
unsigned long relayTurnOnDelay = 5000; // wait to activat relay
unsigned long previousMillis = 0;
long interval = 500;           // horn ON and OFF interval
bool hazardOn = false; // 
bool hornOn = false; //
bool relayOn = false; //
bool alarmOn = false; // for when alarm is ON
bool ignitionOn = false;
bool doorOn = false;
 
void setup() {
 pinMode(doorSwitch, INPUT_PULLUP);
 pinMode(hazard, OUTPUT);
 pinMode(LED,OUTPUT);
 pinMode(horn,OUTPUT);
 pinMode(relay,OUTPUT);
 pinMode(button1,INPUT);
 pinMode(ignitionSwitch, INPUT);
}
 
void loop() {
 // get the time at the start of this loop()
if (digitalRead(ignitionSwitch) == HIGH){
  ignitionOn = true;
}
if (digitalRead(doorSwitch) == HIGH){
  doorOn = true;
}

 unsigned long currentMillis = millis(); 
if ((alarmOn) == false){
if ((doorOn) && (ignitionOn)){
  alarmOn = true;
  alarmOnMillis = currentMillis;
}
}

 // check the button
 if (alarmOn) {
  // update the time when button was pushed
        digitalWrite(LED,HIGH);
        hazardOn = true;
        hornOn = true;
        relayOn = true;
       }
       else{
        (digitalWrite(LED,LOW));
        hazardOn = false;
        (digitalWrite(hazard,LOW));
        hornOn = false;
        (digitalWrite(horn,LOW));
        relayOn = false;
        (digitalWrite(relay,LOW));
       }
  
 // make sure this code isn't checked until after button has been let go
 
 if (hazardOn) {
   if ((unsigned long)(currentMillis - alarmOnMillis) >= hazardTurnOnDelay) {
     digitalWrite(hazard, HIGH);
   }
 }

if (hornOn) {
   if ((unsigned long)(currentMillis - alarmOnMillis) >= hornTurnOnDelay) {
    
    if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the Klaxon is off turn it on and vice-versa:
    if (hornState == LOW) {
      hornState = HIGH;
    } else {
      hornState = LOW;
    }

    // set the horn with the hornState of the variable:
    digitalWrite(horn, hornState);
   }
}
}

if (relayOn) {
   if ((unsigned long)(currentMillis - alarmOnMillis) >= relayTurnOnDelay) {
     digitalWrite(relay, HIGH);
   }
}
 
 if (digitalRead(button1) && (digitalRead(button2)== HIGH)) {
  alarmOn = false;
  ignitionOn = false;
  doorOn = false;
 }
}

Video test (don't know how to put a video in the text)

If you push the first button (door signal) and then the second (ignition signal) or the other way around, the green light lights (alarm ON light that will be on the dashboard), then 4 seconds later the Yellow LED starts (representing hazard lights) a second later the blue LED starts blinking (representing the horn) and at last the red LED starts (representing the latching relay that will cut the engine off).

For now I have to push simultaneously on button 3 and 4 to disable the alarm but I want to figure out a way to use a combination (like 1-1-2-2-1-2) with the two buttons to turn the alarm OFF.

I would like to use a smaller board than the Uno to save space and draw less power and I will have to add 3 or 4 relays for the outputs and 4 relays for the input to send only 3V into the inputs.
Depending on how much time I have to work on this project, I will try to update it with my problems / solutions.

I built a car alarm with a different microcontroller about 20 years ago. I still have the vehicle but the alarm died last year. I have "plans" to build an Arduino version. (Mine had a timer and a hidden switch. If the alarm goes off before you find the switch, the only to shut it off was to remove the fuse.)

and 4 relays for the input to send only 3V into the inputs.

You don't need relays on the inputs. Use [u]voltage dividers[/u] (2 rewsistors), and a [u]protection diodes[/u] (because you can get "unexpected" spikes on the 12 volts). Opto-isolators would be another option.

the Arduino will start the hazard lights after something like 5 minutes, then after another minute turn the horn ON and OFF and at last after another minute shut the engine off (by cutting either the fuel pump or the ignition).

Someone can drive a long way in 5 minutes! I think I gave 60-90 seconds for the pre-alarm buzzer, then the hazard lights and the high/low horns alternating. There was a fuel cut-off, but I don't remember if there was another delay for that.

I also had an exit-delay. The alarm wasn't armed for maybe 1 minute after the doors were closed. (And if you re-opened the door, the timer would re-start.)

Oh, that was actually my 2nd alarm... The 1st one I built (of a different even-older car) didn't have a blinking LED to warn the thieves... I was afraid they would disable the alarm. But the car was broken-into and they tried to steal the stereo. They ran away, but I was left with a broken window. So, the next alarm had a blinking light as a warning and nobody messed with it. (Here in California, you are far more likely to have your car broken-into and they'll steal the contents or the stereo, than to have the car stolen or carjacked... In San Francisco it will happen sooner or later if you leave your car on the street. It's a "non-violent" misdemeanor and I think they just give a ticket if they catch someone.)

My next alarm (if I get around to it) will have an LED that blinks whenever the ignition is off, even if the alarm isn't really armed. (You can actually wire-up a self-blinking LED to do that, with no microcontroller or any other electronics).

I work for a military equipment manufacturer who supplies non-aligned countries and I have three personal vehicles that obviously spend much time parked.

Automobile applications are in a tough environment for programmable devices and whilst I have access to all manner of devices, and easy PCB acquisition. Whilst I realise the object of you project is to use a microprocessor, I have found hard-wired logic to be the most reliable in the many extremes of mobile / vehicle operation.

All these were easily constructed using CMOS. Whilst there is pain in modifying circuits, aforethought and expandable design (access through PCB strip connectors). CMOS also has an elevated operating voltage.

My present systems (1) Prevent starter operation (concealed 'touch' point to permit operation - the touch point is a screw head); (2) RFID receiver that permits continued operation ONLY by chip holder; (3) motion detector(s); (4) electric gas (petrol) pump timeout; (5) Strobe alarm light; (6) Audible alarm.

The starter control is a standalone circuit and housed is a greasy pipe (disguise). All wire is made to look like original equipment to make add-on identification difficult. The RFID chip(s) can be carried in a wallet or purse and defeats snatch or take-over theft. Additional chips qualify other users. The motion detector(s) look after trunks (boots) and other movable accessory. The gas timer stops the pump so that the vehicle stalls in mod-traffic. A strobe light is way more effective that a flashing LED. Vehicle horns draw too much current to be used.

The rest of the circuitry is contained within a box that looks like part of the vehicle. It also has a battery, float charged off the main battery, that defeats thieves who disconnect batteries as part of their Modus Operandi.

For my motorcycle and All Terrain Vehicle I find chaining the vehicle to a road drain or sewer cover handle to deter even police.

Finally, don't forget a key-operated defeat switch so mechanics can do their work!