Understanding how to use negative trigger with Arduino in a car

Thread Starter

Ping pong

Joined Feb 13, 2022
78
I have been working on a small project that adds the coming home feature in my car (turns the car headlights on for a set time when the car is unlocked).
The wire in my car that I am tapping into shows 5v constant normally but when the car is unlocked, it pulses with a ground or low signal before returning back to 5v. However, when the car is in its sleep state, the voltage in this wire drops down to about 2.5-3v. This is the wire I'm using as a trigger for the Arduino to turn on the headlights.
The problem that I'm facing is that when I connect this wire to Arduino using a pull-up resistor, the Arduino maintains the voltage of the unlock wire at 5v which isn't a problem but when the car enters its sleep state, this unlock wire isn't able to drop to 2.5v rather it draws power from the 5v source of the pull up resistor and hence remains at a constant 5v.
I probably cannot use diodes or relays since those wouldn't be effective in this case.
I haven't had a problem as of yet but I'm pretty sure that in the long run the result might not be in my favor. Either the battery is going to start going bad or worse some electrical fault is going to pop up in the car. Hence why I've decided to remove this from the car for now.
I have worked on similar projects on my car multiple times, but this is probably the first time I'm using a negative trigger hence why somewhat confused. will be attaching a small diagram below that will help explain everything in case I haven't been able to explain it properly above.
 

Attachments

boostbuck

Joined Oct 5, 2017
516
Could you explain why you have added a pull-up resistor to the signal line? If you are using the Arduino to monitor the line why do you modify it?
 

Thread Starter

Ping pong

Joined Feb 13, 2022
78
Could you explain why you have added a pull-up resistor to the signal line? If you are using the Arduino to monitor the line why do you modify it?
That has to do something with the controller where if either the internal or an external pull up resistor isn't used, it randomly changes from high to low due to electrical noise or something (that is what the internet told me).
I usually test the project first with a separate 12v battery before hooking it up to the car considering that is what the cars electrical systems works on. While testing, if I add a trigger (negative wire from the battery to simulate the unlock signal from the car) without the resistors, the Arduino would randomly change the trigger state while the trigger is not active (the wire from the negative terminal of the battery is disconnected) and hence cause the relay that would control the car lights to turn on randomly. the pull up resistor helped fix this.
 
Last edited:

geekoftheweek

Joined Oct 6, 2013
1,218
I haven't worked with Arduino so I don't know the capabilities, but what would probably work the best is a couple of comparators connected to your Arduino. One that triggers when under say .5V and another that triggers when over 4.5V. I don't know if they have the option, but if you can configure your pin as a Schmidt Trigger input that would be an easier option.

The reason the Arduino randomly changes when the wire is idle (~2.5V) has to do with the input thresholds of the Arduino.
 

Thread Starter

Ping pong

Joined Feb 13, 2022
78
Come to think of it, maybe I don't need the resistors since the unlock wire in the car is either high or low. It is never left floating or not connected to anything. From what I understand, the resistor is needed only when the trigger wire is left to float which was the case during my testing where to simulate the unlocking of the car, I would either connect or disconnect the wire from the negative terminal of the battery. when connected to the battery, it would give a low signal to the Arduino. however, when disconnected, it was left to float which caused the random switching of the trigger state.
Am i correct on this theory?
 

dendad

Joined Feb 20, 2016
4,476
You could read the signal via a 10K resistor and a 100nF bypass cap to the Arduino, using an analog input so to read the voltage, not rely on a logic level.
 

Jon Chandler

Joined Jun 12, 2008
1,051
The line is already pulled high by the car. It doesn't need your help.

As far as the Arduino knows, the line is either high or low. It's pulled high by the car, so there will not be a noise problem. Your "test" is flawed.
 

Thread Starter

Ping pong

Joined Feb 13, 2022
78
The line is already pulled high by the car. It doesn't need your help.

As far as the Arduino knows, the line is either high or low. It's pulled high by the car, so there will not be a noise problem. Your "test" is flawed.
yeah exactly. it wasn't until @boostbucks comment that i realized that i didn't need the resistor. But what would happen when the car enters its sleep state and steps down the voltage to 2.5v. I'm using an Arduino nano which runs on 5v. would that effect the trigger state or will the arduino still consider 2.5v as HIGH?
 

Thread Starter

Ping pong

Joined Feb 13, 2022
78
You could read the signal via a 10K resistor and a 100nF bypass cap to the Arduino, using an analog input so to read the voltage, not rely on a logic level.
I've searched this up and can definitely use it in my project as well. will the Arduino be able to tell when the wire has been grounded or will i have to set a threshold of lets say lower than 1v that turns on the relay.
 

dendad

Joined Feb 20, 2016
4,476
Your code can read the analog input each time through the loop and then the number is used to make decisions. So you will be able to see if the input is grounded, say less that 20 reading, and also if the car is in sleep mode. What I do in developing things is to display the readings on an LCD or use the serial monitor so you can see what the readings are. Often I divide the reading so small numbers are used.
Depending on the results, something like... (I am not a real good programmer!!!)
Code:
int reading;
.
.
.
loop() {
reading = (analogRead(A0/256););

switch (reading) {
case 0:
{ turnheadlightson();
}
break;

case 1:
{   // maybe nothing
}
break;

case 2:
{  sleeping();
}
break;

case 3:
{   // running
}
break;
}
}
 

Thread Starter

Ping pong

Joined Feb 13, 2022
78
Your code can read the analog input each time through the loop and then the number is used to make decisions. So you will be able to see if the input is grounded, say less that 20 reading, and also if the car is in sleep mode. What I do in developing things is to display the readings on an LCD or use the serial monitor so you can see what the readings are. Often I divide the reading so small numbers are used.
That is perfect. Thank you!!
 
Top