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