[Help] Adding some cool features to my cars using arduino

Lasted main problem: controlling the central locking of my car using arduino (see down)

This month i discovered arduino and because i know some programming and also a little, little bit of electrics i tought about some features that would be easy and cool to add them to my car.

1.[Locking car using RFID]
First of all my car radio key is broken and it costs me too much to repair it (x10 arduinos) and i tought that with a RFID module i can unlock my car more easly then inserting the key, today i opened the door to see how my locking sistem works and it have 3 wires.

1- ground
2- lock 0.10V
3- unlock 0.10V
Whenever 2 or 3 touch the ground the car is opened or closed, a single touch is enough but the car is keeping that connection continious.
something like this:
Where the switch is the main door locking switch by hand or key

so, what i think is that the car know from what wire i drow the current and also i can't just drow current from both of them, there might be a problem trying to control it but i'll figure it out if you don't know too.

I'm thinking to use MFRC522 as a RFID module. after a lot of google searches for 1+ m RFID module which costs a lot from what i founded

2.[Alarm using Piezo Vibration module]
From an old broken car alarm i recovered the vibration sensor which have a piezo sensor and can give me digital sign whenever it detects even a big clap (it also have a potentiometer)
For this feature will be real simple to code but the biggest problem is to detect whenever the car is locked or not.

What i writed so far is just a few because i was focused on the car itself and how it works, diagrams...
here's only the alarm, very simple, not tested, maybe i'm embarrass myself with this but anyway

[OUTDATED]

// Car alarm project @2016

const int statusOFFPin=12; // status led for alarm
const int statusONPin=11; // status led for alarm
const int sensorVPin=13; // piezo vibration sensor module - alarm
const int sensorPPin=0; // PIR sensor module - autolocking if unlocked, no movement, autolocking button - on
const int triggerPin=0; // horn, lights, car wipers ...
const int carlockPin=0; // car locked ?
int alarmtime=5000 // time for horn, light to turn off

void setup()
{
pinMode(statusONPin, OUTPUT);
pinMode(statusOFFPin, OUTPUT);
pinMode(sensorVPin, INPUT);
pinMode(sensorPPin, INPUT);
pinMode(triggerPin, OUTPUT); //relay 
pinMode(carlockPin, INPUT); //with resistor
}

void loop()
{
//check for sensors if car is locked
delay(100)
if (carlockPin > 0)
{
    digitalWrite(statusONPin, HIGH)
    digitalWrite(statusOFFPin, LOW)
  if (digitalRead(sensorVPin) > 0)
  {
    digitalWrite(triggerPin, HIGH)
    delay(alarmtime) //alarm time
  }
  else
  {
    digitalWrite(triggerPin, LOW)
  }
}
else
{
    digitalWrite(statusOFFPin, HIGH)
    digitalWrite(statusONPin, LOW)
}
}

This might work better if you actually read the pin:-

if (carlockPin > 0)

Possibly:-

if(digitalRead(carlockpin)==HIGH)

Also, it's better if you use "HIGH" with the comparison of your other digital read too, instead of ">0". If nothing else, it's more correct. :slight_smile:
(But your current method will work.)

retouched all the code, still a lot to do:

// Car alarm project G3orG3 @2016

const int statusOFFPin=12; // status led for alarm
const int statusONPin=11; // status led for alarm
const int sensorVPin=13; // piezo vibration sensor module - alarm
const int sensorPPin=0; // PIR sensor module - autolocking !!!
const int autolockPin=0; // autolocking toggler using PIR toggler
const int triggerPin=0; // horn, lights, car wipers ...
const int carlockPin=0; // car locked ?
const int contactPin=0; // car contact on ?
const int buzzerPin=0; // sound alerts
const int alarmPin=0; // alarm toggler 
int alarmtime=15000 // time for horn, light to turn off

void setup()
{
pinMode(statusONPin, OUTPUT);
pinMode(statusOFFPin, OUTPUT);
pinMode(sensorVPin, INPUT);
pinMode(sensorPPin, INPUT);
pinMode(triggerPin, OUTPUT); //relay 
pinMode(carlockPin, INPUT); //with resistor
pinMode(buzzerPin, OUTPUT);
pinMode(contactPin, INPUT);
pinMode(autolockPin, INPUT);
pinMode(alarmPin, INPUT);

 if (digitalRead(autolockPin) ==HIGH){ //if autolocking is ON by the toggler
unlock_door(); //unlock testing + recover keys from the car method
delay(1000);
lock_door();
}
}

void unlock_door()
{
  //check the doors status before unlocking the car
}

void lock_door()
{
  //check the doors status before locking the car
}

void loop()
{
delay(100)

// BEGIN RFID UNLOCKING
   //upcoming 
// END RFID UNLOCKING

// BEGIN AUTOLOCK
 if (digitalRead(autolockPin) ==HIGH){ //if autolocking is ON by the toggler
  if (digitalRead(contactPin) ==LOW) { //if there is no contact
if (digitalRead(carlockPin) ==LOW) { // if car isn't locked
  if (digitalRead(sensorPPin) ==LOW){ //if the sensor got no movement
    digitalWrite(buzzerPin, HIGH) //alert the driver that the car will be locked
  delay(5000) // give the driver some time to realise 
    digitalWrite(buzzerPin, LOW)
  if (digitalRead(sensorPPin) ==LOW) { //if the sensor got no movement
    delay(5000)
  lock_door()
     }
    }
   }
  }
 }
// END AUTOLOCK

// BEGIN ALARM
if (digitalRead(alarmPin) ==HIGH) { //if the alarm is enabled
if (digitalRead(carlockPin) ==HIGH) { //if the car is locked
    digitalWrite(statusONPin, HIGH)
    digitalWrite(statusOFFPin, LOW)
  if (digitalRead(sensorVPin) ==HIGH) { //if vibrations are detected
    digitalWrite(triggerPin, HIGH) //the alarm itself
    lock_door() //make sure the doors are locked
    delay(alarmtime) //alarm time
    digitalWrite(triggerPin, LOW) //turn the alarm off
  }
}
else //if alarm is disabled because the car is not locked
{
    digitalWrite(statusOFFPin, HIGH)
    digitalWrite(statusONPin, LOW)
}
}
// END ALARM
}

Next tip:
To format your code correctly with proper indentations where they're needed, you can hit Ctrl-T in the IDE, or click on >Tools >Auto format.
It makes it much easier to read, and also highlights some of the errors.

Also, you forgot the semicolon at the end of many lines of your code.

i fixed that too, but i realise that i already have used a lot of pins + when i'll implement the rfid module i don't know if my pins are enough, is there a way of saving them, a shift register maybe ?

prologikus:
i fixed that too, but i realise that i already have used a lot of pins + when i'll implement the rfid module i don't know if my pins are enough, is there a way of saving them, a shift register maybe ?

Yes, you can use shift registers, or multiplexers, or an I2C port expander, (or you could buy a Mega2560).

I really apreciate that you're helping me @OldSteve, i already gave u same karma :smiley:

About the project i'll use multiplexer probably.
A few minutes ago i opened my car door again tring to figure out how it works and i'll try to explain here as much as i understand:

So, there are 2 wires : WHITE, RED

  1. When WHITE touch ground the car tries to lock if it isn't / RED unlock it.
  2. Those wires are connected to the main door lock which can be actioned by either the key(in the door) or by pulling a interior trigger, WHAT THE MAIN DOOR actually does is simply connect EITHER the WHITE, EITHER the RED to the ground (it have a special ground pin but it works with the car's ground too)

For controling them i tought about using 2 transistors just like here:

BUT then i won't be able to control the lock by the key and also i can't detect with arduino if the car is locked or not

It's very confusing, i don't know if there will be an easy solution for it

prologikus:
I really apreciate that you're helping me @OldSteve, i already gave u same karma :smiley:

Thank you for that. :slight_smile:

About the project i'll use multiplexer probably.
A few minutes ago i opened my car door again tring to figure out how it works and i'll try to explain here as much as i understand:

So, there are 2 wires : WHITE, RED

  1. When WHITE touch ground the car tries to lock if it isn't / RED unlock it.
  2. Those wires are connected to the main door lock which can be actioned by either the key(in the door) or by pulling a interior trigger, WHAT THE MAIN DOOR actually does is simply connect EITHER the WHITE, EITHER the RED to the ground (it have a special ground pin but it works with the car's ground too)

For controling them i tought about using 2 transistors just like here:

BUT then i won't be able to control the lock by the key and also i can't detect with arduino if the car is locked or not

It's very confusing, i don't know if there will be an easy solution for it

The connections in your diagram won't do what you expect. With the door in the locked position as shown, switching the transistor attached to D3 on will do nothing. It still doesn't switch the red wire to ground.

And while with the switch in it's current position, having the transistor attached to D2 turned on will connect the white wire to ground, when you turn that transistor off, the white will no longer be connected to ground, but neither will the red wire.
At the same time that you connect one or the other wire to ground, you also need to disconnect the wire that the existing switch connects to ground. Do you see what I mean?

Are you sure about the original connections? What you really need to do is get your hands on the complete original wiring diagram for the door locking system, then work from that. I suspect that it uses a relay somewhere in there, that's toggled between two positions. If that's the case, and if you can get the full diagram, it won't be hard to work something out.

Yess, of course, i didn't notice this at all, now i got it, half of it because the other half when i need to disconnect the wires is complicated to me.

Now i already did a lot of searches before and didn't find nothing about the location of my central locking sistem or even if i have one or not.
What i know is that there is no relay for locking.

and this is the only image that shows a central locking on my car.

Today or maybe tomorrow i'll search for it deeper in my car and then reporting, as u said it will be much easier to do those things directly from there, but i expect there will be no notes on the pins of the module and there will be a little problem.

OldSteve:
[...]

I just founded them, you were right !
Open in a new tab to see the full img




so.. as expected, there are no notes for any pins
and i can't just connect to the relays and controlling them, i'm right ?
_* by controling them i mean following this tutorial : http://www.instructables.com/id/Connecting-a-12V-Relay-to-Arduino*_
I'll wait till you reply, searching for a schematic


the only diagram i just founded, is this useful ?

No, there's not really enough information there. And I can't see the white wire and the red wire that you referred to anywhere. There don't appear to be any white wires in that diagram.

Red and White wires are actually brown with red and brown with white, i just simplificated

I'm not good at deciphering auto schematics, they use symbols I'm not used to. To me, the red/blue and red/white wires appear to control the solenoids. Without knowing exactly what goes on in the central locking module, it's hard to tell if it's safe to switch them separately without damaging the module.

OldSteve:
I'm not good at deciphering auto schematics, they use symbols I'm not used to. To me, the red/blue and red/white wires appear to control the solenoids. Without knowing exactly what goes on in the central locking module, it's hard to tell if it's safe to switch them separately without damaging the module.


This is the only solution that i can found
I connect to an relay from the central lock just to know if the car is locked or not, use a resistor to reduce it's voltage

Then, to control it i can do the thing with the transistors, connect either wire to ground, and even if it already have a connection, by connecting the other wire to the ground i can trick the central lock so it send another signal to all the doors to lock

What do you think ?
also, the resistors values are good ?

That would mean that at times both the red and white wires would be pulled to ground. I have no idea if that will damage anything.

by connecting the other wire to the ground i can trick the central lock

You're relying on guesswork here.

Anyway, I don't know enough about the system to comment further, so I'll have to leave you to it. I don't want to give any bad advice that results in damage. :slight_smile:

OldSteve:
I don't want to give any bad advice that results in damage. :slight_smile:

If u have any advice just say it, i won't blame you anyway;
And yes, the red and the white wire will be both connected to the ground for a short short period of time (like 0.3s) then because the other is connected to the ground it sends a signal to the door switch to change it's normal position to the one i choosed, if u know what i mean ...
The voltage mesured by the multimeter shows 0.10V DC or 0.02AC, i don't know what is this.
So... any idea, better or not will help me doing this

prologikus:
If u have any advice just say it, i won't blame you anyway;
And yes, the red and the white wire will be both connected to the ground for a short short period of time (like 0.3s) then because the other is connected to the ground it sends a signal to the door switch to change it's normal position to the one i choosed, if u know what i mean ...

The controller won't know which of the two is valid.

The voltage mesured by the multimeter shows 0.10V DC or 0.02AC, i don't know what is this.

neither do I.

Your best bet is to post details of your car, and hope that someone comes along who's familiar with it's central locking system.

Alternatively, design a circuit that disconnects the original switch altogether, then pulls whichever wire you want low. That would be the safe approach.

I was thinking along these lines:-
img004.JPG

In operation, if either "W" or "R" are taken high by the Arduino, Q2 switches Q1 off, disconnecting the original switch from ground, while simultaneously pulling the RED or WHITE wire to ground.

The drawback is that current would always be flowing through R1, but to stop that Q1 could be replaced by a relay, with it's normally-closed contacts connecting the original switch to ground. Q2 could operate the relay, so that the contacts opened if either Q3 or Q4 were turned on.
A little more complex, but that way no current would flow unless the Arduino took one of the inputs high.

The resistor values shown are only tentative, and might need changing, but I think they'd be OK. R1 could possibly be a higher value, like 47K to reduce the idle current, but too high and it might suffer from jitter due to noise.

Edit: If you knew how much current flows through the red or white wires when they're switched to ground, I could choose better values for the resistors. Also, voltage dividers could be added to the bases of Q3 and Q4, so that they switched slightly later than Q2, ensuring that the original switch is disconnected before the wires are pulled to ground by your circuit.

You could disconnect the original switch from ground, and then connect the multimeter between it and ground, for an accurate reading without upsetting anything. If more than 5mA to 10mA flows, the resistor values will definitely need to change, especially if voltage dividers are implemented. The red and white wires might be switching relays/solenoids, in which case more current will be flowing than I imagined.
So far, in your diagrams, you've shown currents ranging from 0.5pA to 442.8uA to 100mA, so I don't know what's right and what's wrong.

OldSteve:

I really liked your idea but before tring it i already did some tests (see the video)
However i don't have those transistor, the best transistor that i have is c1815

Then, there is no current flow showing on the multimeter, it must be some pulses or i don't know, i tested multiple times.
The diagram was made using real 0.10V but i don't know how much the car is giving me, i don't have a osiloscope either, also when i connect the mutimeter with ACV it gives me 0.02-0.03 as i said before.

Here i made a video testing without any disconections.
The thing is that the ground is connected to multiple things and i'm not so happy cuting it, also i tought that the switch itself, from the door, might have both red and white wires connected to the ground for a few ms, which i can simulate myself with arduino, but there will be more ms with both wires connected, i don't know if something is wrong doing, tell me know what do you think after you saw the video

as u can see i set the arduino to give me 1s impulse of voltage so i can turn on the transistor but i think even if i use a 200ms pulse it can work too, less time, more safer, i'm right ?
I was using 2 transistors, i don't know not why (c1815)
Arduino powered by 12V from the car but only when the car wasn't ignited, i'll use a step down in future (if i can make one :smiley: :smiley: )