Electronic – Checking when a car horn is pressed

automotivemicrochipmicrocontrollerpicvoltage

I want to detect when a car horn is pressed. The only way I can detect it currently is using the voltage on its line.
When the car is turned on, there is always 12V being supplied to the horn through the battery i.e. When the horn is NOT being used the voltage to it is 12V.

When the horn is being used the line voltage drops between 2V-1V due to the consumption by the horn.
I was thinking of using the High/Low voltage detect module of the pic 18f4520 to detect this voltage drop when the horn is pressed. But the module seems to be more for detecting a drop in operational voltage. Is there a downside to using the HLDV in such a manner, also is there a better/other way to do this? Any code snippets to HLVD or other methods are greatly appreciated.

Thank you for your time and have a great day.

Best Answer

I'm assuming that you're measuring the voltage with respect to ground, not across the horn terminals. If so, what you are describing sounds like this:

img1

Except that the switch is likely a relay, MOSFET, SSR, or some other device that has a non-zero resistance even when "closed".

In this case, both wires across the horn will be at the battery voltage when the horn is off. When the switch closes the bottom wire will drop towards ground and current will start to flow. The reason it doesn't actually reach zero volts is because of the resistance of the switch.

It is important to realize that the top wire won't vary (much) from the battery voltage whether the horn is active or not.

You'll need to monitor the line between the horn and the switch. To interface this to a PIC (or other microcontroller), you will need to scale the voltage so that it doesn't exceed the PIC's Vdd (probably 3.3V or 5V in your circuit). You would do this by using a voltage divider:

img2

Say that your Vdd is 5V. Assume that the horn voltage swings from 15V to 2V. If you divide the voltage by 3, the output swings from 5V to 0.66V. This is within spec of the PIC. If Vdd = 3.3V, you will need to scale appropriately.

As far as the interface method, you have a few options:

  1. The HLVD module. This would work just fine, and has the benefit of "set-and-forget". Once it is configured, you just wait for an interrupt.

  2. An analog input. This also works, but you'll need to regularly sample the input.

  3. If the scaling works out, you may be able to simply use the horn signal as a digital input! Make sure that when the signal goes low that it is below the \$V_{IL}\$ of the PIC, found on page 335 of the datasheet.

However, you'll need to add some extra protections. The power systems of automobiles are very noisy and hard to deal with. You can get false triggers, and large voltage spikes when starting the engine that can damage your microcontroller.

By the time you account for these things the circuit can become considerably more complicated. See some of the other answers. @tcrosley even shows how to create a safe, filtered Vdd for the PIC!

Good luck :)