80Views8Replies

Author Options:

Can someone help with my anti auto theft arduino device? I am trying to use a reed switch and a relay. Answered

     I am trying to build a device for my engineering project which is a anti theft device for cargo trucks in third world countries. Since cargo stealing is very common truckers already use satellite tracking. The device works in the following way, in an attempt to steal the truck a thieve tries to breach into the truck"s electrics to disable the satellite tracking, but the reed switch detects the breach and the arduino stops feeding power to a relay which is connected truck's electronic fuel injection system, thus making the truck's engine to stop and consequently immobilizing the cargo.
     The system uses a 4x4 matrix keypad, one relay(I might add more) and one reed switch but I am planning to use two. When the sensor is breached the arduino is supposed to cut power to the relay. If the correct password in entered in the keypad the system turns the relays on until the sensor is breached again, if the wrong password is entered it remains locked.
     I managed to find a password code a guy shared which worked with the keypad and the relays, but when I try to add a if statement to lock when the sensor is breached it simply does not work.

Thanks in advance for the help.

#include<Keypad.h>

int Relay1 = 13;
int Relay2 = 12;
int greenPin = 11;

int Sensor1 = A1;

int Sensor1Valor = analogRead(Sensor1);

int position = 0;

const char * password = "123";

const byte ROWS = 4;
const byte COLS = 4;

char keys[ROWS][COLS] = {
 
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};

byte rowPins[ROWS] = { 8, 7, 6, 9 };
byte colPins[COLS] = { 5, 4, 3, 2 };

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup()
{
Serial.begin(9600);

pinMode(Sensor1, INPUT);

pinMode(Relay1, OUTPUT);
pinMode(Relay2, OUTPUT);
pinMode(greenPin, OUTPUT);

digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);

setLocked(false);
}

void loop() 
{
char key = keypad.getKey();

Serial.println(analogRead(A1));

if (key == '*' || key == '#')

{
position = 0;
setLocked(true);
}

if (key == password[position])
{
position ++;
}

if (position == 3)

{
setLocked(false);
}

if (analogRead(A1) > 300);
{
setLocked(true);
}
}

void setLocked(int locked)

{
if (locked)

{

digitalWrite(greenPin, LOW);
digitalWrite(Relay1, LOW);
digitalWrite(Relay2, LOW);
}

else

{

digitalWrite(greenPin, HIGH);
digitalWrite(Relay1, HIGH);
digitalWrite(Relay2, HIGH);
}
}

Discussions

0
None
Vyger

2 years ago

You might think about going with a trunk monkey instead.

0
None
steveastrouk

2 years ago

What is the analog read for ?

0
None
steveastroukLuccaL1

Answer 2 years ago

Make sure you have either an external pullup resistor or you turn on the ones in the Arduino. My preference is the external resistor

0
None
LuccaL1steveastrouk

Answer 2 years ago

oh thank you, i did not know I had to use resistors with this sensor, why is that?

0
None
steveastroukLuccaL1

Answer 2 years ago

because for the instant they are transitioning, the voltage on the input pin is not defined.

0
None
steveastroukLuccaL1

Answer 2 years ago

Switches are generally treated as digital input devices - connect to +5 = on, gnd = off.

0
None
LuccaL1steveastrouk

Answer 2 years ago

I thought the same thing but for some reason when I tried to use it as a digital sensor it only showed 0's completely ignoring if it was closed or opened. When I tried as an analog sensor it gave me values I could work with, usually between 0 and 500.