Keyless Entry - Any Ideas?

Hello Arduino-Community,

I am new to the Arduino Universe, but have a project in mind that includes CAN-Bus and BLE shields to communicate with my car. I am studying in the IT segment at the moment but don’t have a lot of experience yet. I know some c# already.

The Reason behind it:
The pre owner of my car apparently dropped the key fob in a bucket of water, so the remote unlock and such don’t work anymore. Because of that I have to unlock the car with the key and when it is really cold it doesn’t work due to freezing.

The Goal:
The goal is to be able to unlock the car, when my phone connects to the Bluetooth as I walk to it and locks again when I walk away (including some safety logic at some point) without having to touch my phone at all.

I think I will need some help making this work and I plan on updating this post so at the end it will include everything for others to basically just follow directly as a guide.

The Plan:
Figure out how to grab the CAN-Bus messages
Test the found messages
Test the connection with the phone without sending messages
Include everything in the main code that is supposed to run.

The Parts:
-Arduino Uno (It is a cheaper copy but seems to do the same things)
-DIY More CAN-BUS Shield V1.2
-HM-10 BLE module (turns out to be a CC41-a)
-a Car (french)

The Questions:
How can I check if my phone is close by?

The Code for the steps (will be updated as I’m working on it)

Step 1 - Getting the CAN-Bus Messages
(With a code I want to print the received messages over the USB connection, currently I’m testing without the Bluetooth connection and this code)

~~(No code just yet)

Step 2 - Testing the CAN-Bus Messages
(With this code I’m testing if the Messages actually do what I think they should, the test is again without Bluetooth connection)

~~(No code just yet)

Step 3 - Connecting the phone
(I want only 2 phones to actually work, the BLE modules allows 3 MAC-addresses to connect so that's perfect. Here I just want to see if I can trigger something by connecting to the Bluetooth)

#include <SoftwareSerial.h>
SoftwareSerial BTSerial(4, 5); //RX|TX
int x=0;
void setup(){
  
  Serial.begin(9600);
  BTSerial.begin(9600); // default baud rate
  while(!Serial); //if it is an Arduino Micro
  Serial.println("Started!");
  
}
 
void loop(){
  //read from the HM-10 and print in the Serial
  if(BTSerial.available())
    Serial.write(BTSerial.read());
    if (x==0)
    {
      Serial.println("Tested!");
      BTSerial.write("AT+Help");
      x=1;
      
    }
    
    
  //read from the Serial and print to the HM-10
  if(Serial.available())
     BTSerial.write(Serial.read());
}

Step 4 - The Unlock/Lock Code
(This is the basic function, so far it includes more of a what I want to do when than actual code)

main
bool trigger=false;
bool DoorOpen;
int timer=0;

Loop
//trigger shows if this is the first connection or continuous
if ((connectionBLE==true) && (trigger == false)) //First connection to the Phone unlocks car, trigger switches
{
    send unlock CAN Msg;
    trigger=true;
    timer start;
    
    while (timer<3min)
    {
        Check if Door got opened //I’m not sure how to get this signal yet, I might have to do it a different way. I thought about checking if the engine has been turned on, but I can already see a problem with that. Opening the car, putting the key in accidentally and then leave again would lock the key inside of the car. Any Ideas?
        if (Door got opened=true)
        {
            DoorOpen=true;
            break;
        }
        else
            DoorOpen=false;
    }
}

else if ((connectionBLE==false) && (trigger==true)) //Connection is lost and the trigger is true
{
    send lock Can Msg;
    trigger=false;
}


if (timer>3min && DoorOpen==false)  //When the car has been unlocked, is still connected but wasn't opened it locks again
                                    //trigger doesn't get reset so the car stays locked until I reset the BLE connection 
                                    //Lost connection will bring me back to the locking part of the code
{
    timer=0;
    DoorOpen=false;
    send lock Can Msg;
}

Last but not least I want to thank the following people for helping me:

~~(No questions answered yet)

If you have any questions or suggestions let me know, I would love to have more input.

In Regards,
Enno

Do you know the actual codes you have to send to your car's computer to do the locking/unlocking?

Have you tried getting a new key and fob from the dealer and pairing it to the car?

wvmarle:
Do you know the actual codes you have to send to your car's computer to do the locking/unlocking?

I have to get them by testing and reading the CAN-Bus. Hopefully I will be able to get them.

saildude:
Have you tried getting a new key and fob from the dealer and pairing it to the car?

Where is the fun in that? I wanted to use an arduino for quite some time already and have found a fun little project

Seems like the entire project hangs on whether you can get and interpret the CAN bus codes.

Doesn't sound like a "little" project to me.

jremington:
Seems like the entire project hangs on whether you can get and interpret the CAN bus codes.

Kind of, but for now I'm not worried, I try to find a way to tell the arduino I am close to the car without having to use an app.

wvmarle:
Doesn't sound like a "little" project to me.

I'm open for a bigger one too.

As long as you don't really care about a precise range, bluetooth will do as it maxes out at about 10 meters (depending on the module). Your transponder listens for a transmission from the car, when in range and the transmission is received, it responds with a transmission of itself, so the car knows you're in range. When walking away, the car still sends transmissions to your sensor (every second or so), then when it stops receiving a reply it knows you've walked away.

One issue of this trick is battery life. Your transponder has to be actively listening all the time so no sleep possible.

wvmarle:
As long as you don't really care about a precise range, bluetooth will do as it maxes out at about 10 meters (depending on the module). Your transponder listens for a transmission from the car, when in range and the transmission is received, it responds with a transmission of itself, so the car knows you're in range. When walking away, the car still sends transmissions to your sensor (every second or so), then when it stops receiving a reply it knows you've walked away.

One issue of this trick is battery life. Your transponder has to be actively listening all the time so no sleep possible.

That's perfect, that's what I want to use my phone for as I always carry it on me. The only thing I can't figure out at the moment is how I can tell my program that my phone is connected to the Bluetooth or wifi.

so did you figure out how to detect when your phone is in range? all the Arduino Bluetooth boards require a custom app to run to connect to the chip. I can't figure out how to make the board automatically scan for the phone. I know it's totally doable since my tesla does exactly that i.e. I walk up to my car and it unlocks without having me to take out my phone or run any apps. I just cannot figure out how to implement it. Is it with BLE central/peripheral? I just need some pointers.