Need a circuit to detect when engine running from OBD2

michael_l
Tue Jun 06, 2017 12:29 pm
I have a small project that uses OBD2 connector and gets power from its pin. Now I would like to build a small circuit that would ‘turn on’ the circuit when engine’s running. I need approx. 200-250mA.

I created one with LM741 but it has a problem with hysteresis and it starts to “flap” at the edge. Now I’m seeking for some other ways to make this work. The circuit can use max 10mA when “sleeping”. I don’t necessarily need a ready circuit but just some pointers what kind of chips etc. to use. Thanks.


ahull
Tue Jun 06, 2017 12:57 pm
So why don’t you simply use sutable ldo voltage regulator powered from the switched side of the ignition switch.
http://uk.farnell.com/texas-instruments … dp/1755063
.. add an input and output smoothing cap, and you’re done.

The output of the voltage regulator should come up quite cleanly, and could be 3v3 or 5v or 12, whichever is appropriate to “wake up” the rest of your circuitry.


ag123
Tue Jun 06, 2017 5:09 pm
yup there are plenty of cheap car usb chargers in huge abundance on ebay as well as offline (maybe in the ‘flea’ markets) :lol:

on obd2 i think the ultimate most adventurous ones actually replace the fuel injection ecu with arduino, some even wants to fly with it, any 1 would try debugging over st-link jtag/swd at 60 miles an hour? :lol:
https://forum.arduino.cc/index.php?topic=213700.0
https://www.youtube.com/watch?v=GGhO0160SJ4
http://www.hainesengineering.com/rhaine … rduino.htm
or any 1 bother to do a ‘graphical’ ILI9341 fuel injection ecu that show the dynamic O2 concentration vs the cm3 per secs of petrol injected and dynamic ‘horse’ power computation with fft filtering to remove noise ? oh and for that you may need f4 that blow the tops of 500mflops overclocked
maybe add some whizz bang neural net machine learning to ‘auto tune’ for smallest cm3 per secs of petrol vs o2 concentration vs max engine ‘horse’ power produced per drop of fuel :lol:


michael_l
Tue Jun 06, 2017 7:50 pm
ahull wrote:So why don’t you simply use sutable ldo voltage regulator powered from the switched side of the ignition switch.
http://uk.farnell.com/texas-instruments … dp/1755063
.. add an input and output smoothing cap, and you’re done.

The output of the voltage regulator should come up quite cleanly, and could be 3v3 or 5v or 12, whichever is appropriate to “wake up” the rest of your circuitry.


michael_l
Tue Jun 06, 2017 7:52 pm
ag123 wrote:yup there are plenty of cheap car usb chargers in huge abundance on ebay as well as offline (maybe in the ‘flea’ markets) :lol:

on obd2 i think the ultimate most adventurous ones actually replace the fuel injection ecu with arduino, some even wants to fly with it, any 1 would try debugging over st-link jtag/swd at 60 miles an hour? :lol:
https://forum.arduino.cc/index.php?topic=213700.0
https://www.youtube.com/watch?v=GGhO0160SJ4
http://www.hainesengineering.com/rhaine … rduino.htm
or any 1 bother to do a ‘graphical’ ILI9341 fuel injection ecu that show the dynamic O2 concentration vs the cm3 per secs of petrol injected and dynamic ‘horse’ power computation with fft filtering to remove noise ? oh and for that you may need f4 that blow the tops of 500mflops overclocked
maybe add some whizz bang neural net machine learning to ‘auto tune’ for smallest cm3 per secs of petrol vs o2 concentration vs max engine ‘horse’ power produced per drop of fuel :lol:


ahull
Tue Jun 06, 2017 8:34 pm
michael_l wrote:ahull wrote:So why don’t you simply use sutable ldo voltage regulator powered from the switched side of the ignition switch.
http://uk.farnell.com/texas-instruments … dp/1755063
.. add an input and output smoothing cap, and you’re done.

The output of the voltage regulator should come up quite cleanly, and could be 3v3 or 5v or 12, whichever is appropriate to “wake up” the rest of your circuitry.


RogerClark
Tue Jun 06, 2017 9:36 pm
@bennehboy and I both have been investigating OBD2.

In only got as far as plugging on into my car and reading data via an android app, but @bennehboy is doing a lot more.

I am not an expert in this, But you can read engine RPM via OBD so in theory the device could use that data to determine if the engine is running.

I think the complication is that there are different communication protocols used by OBD2.


ahull
Tue Jun 06, 2017 11:56 pm
RogerClark wrote:@bennehboy and I both have been investigating OBD2.

In only got as far as plugging on into my car and reading data via an android app, but @bennehboy is doing a lot more.

I am not an expert in this, But you can read engine RPM via OBD so in theory the device could use that data to determine if the engine is running.

I think the complication is that there are different communication protocols used by OBD2.


michael_l
Wed Jun 07, 2017 4:49 am
The problem as to say is that in my car OBD2 battery pin gives constant +12V. My idea was that if the car is running the alternator will rise the battery voltage to at least 12.9-13Volts. In my circuit arrangement with LM741 I monitor battery voltage. If the batt. voltage is 12.9 or higher the output pin will output the same, the limit is configurable with potentiometer as basically there’s voltage divider. If lower than 12.9 then output is grounded (or at least very close to it). The basic idea was taken from here: http://www.reuk.co.uk/wordpress/electro … tor-lm741/

RogerClark
Wed Jun 07, 2017 5:59 am
Have you measured the voltage on the battery ?

I’m not sure it would be quite as simple as that. When the battery is charged it will indeed rise to around 14V, but I’m not sure for example if you turn the headlights on, then start the car, how long it will take the battery to get to 13V if the battery was not fully charged prior to starting the car

You may be better off looking for alternator ripple or other noise on the supply voltage, as alternators used to introduce some nice sine waves in the audio part of the spectrum.

i.e pass though a high pass filter or a band pass filter.


michael_l
Wed Jun 07, 2017 6:15 am
Yes, I have measured the voltage. The actual device needs to be switched on only when the car is running. When I turn off the engine it should shut down.

One possiblity could be to monitor for voltage drop which happens very quickly when car is started. Again, no idea how to detect this with a simple circuit that draws max 5-10mA.


RogerClark
Wed Jun 07, 2017 6:20 am
Yes.

I was going to mention that the battery voltage normally drops very sharply when the starter motor is running.

I’ve not checked my current car, but I remember some old cars I had the battery voltage dropped well below 10V when the starter was turning

Of course the car may not start if you just turn the key for a split second or release before it fires on a cold day, so I’m not sure the voltage drop method is that reliable

The alternator noise or OBD RPM data method are probably the most reliable methods


michael_l
Wed Jun 07, 2017 6:58 am
RogerClark wrote:Yes.

I was going to mention that the battery voltage normally drops very sharply when the starter motor is running.

I’ve not checked my current car, but I remember some old cars I had the battery voltage dropped well below 10V when the starter was turning

Of course the car may not start if you just turn the key for a split second or release before it fires on a cold day, so I’m not sure the voltage drop method is that reliable

The alternator noise or OBD RPM data method are probably the most reliable methods


RogerClark
Wed Jun 07, 2017 7:07 am
What car do you have ?

Have you checked what OBD protocol it uses.

I have an old Subaru, which seems to use a fairly standard protocol

I’m not sure where all of these things are listed but mine appears to be listed here

http://www.outilsobdfacile.com/vehicle- … bd2/subaru

and is compatible with the ELM327 module that I have


michael_l
Wed Jun 07, 2017 7:56 am
RogerClark wrote:What car do you have ?

Have you checked what OBD protocol it uses.

I have an old Subaru, which seems to use a fairly standard protocol

I’m not sure where all of these things are listed but mine appears to be listed here

http://www.outilsobdfacile.com/vehicle- … bd2/subaru

and is compatible with the ELM327 module that I have


RogerClark
Wed Jun 07, 2017 10:42 am
Actually I was thinking of digital data.

But it looks like your BMW may output RPM on pin 9 of OBD 2

https://en.wikipedia.org/wiki/On-board_ … ics#OBD-II

But it looks like BMW only.

In which case it should be fairly simply to trigger off that signal, either if its a pure analogue level or some sort of PWM or PPM etc


michael_l
Wed Jun 07, 2017 10:50 am
RogerClark wrote:Actually I was thinking of digital data.

But it looks like your BMW may output RPM on pin 9 of OBD 2

https://en.wikipedia.org/wiki/On-board_ … ics#OBD-II

But it looks like BMW only.

In which case it should be fairly simply to trigger off that signal, either if its a pure analogue level or some sort of PWM or PPM etc


zmemw16
Wed Jun 07, 2017 11:11 am
a diode, with a C and discharge R across C :?:
srp

ag123
Wed Jun 07, 2017 1:56 pm
actually 1 of the more common use of obd2 is to ‘clear fault codes’ :lol:
and i’d think the odb2 protocol itself seem to have messages to read engine rpm
https://en.wikipedia.org/wiki/OBD-II_PIDs#Mode_01
https://en.wikipedia.org/wiki/On-board_ … ics#OBD-II
https://en.wikipedia.org/wiki/OBD-II_PIDs

as for powering stm32, perhaps a ‘simplier’ way is to simply use an external battery, i think those blue pill / maple mini LDOs can easily take say 6v from 4×1.5v batteries :lol:


michael_l
Wed Jun 07, 2017 2:39 pm
The device will be permanently attached to car. That’s why the power consumption has to be minimized and I need an indication when the car is running.
Currently the wire that gets main power +12V will power the display from BP’s 5V pin. So it’s not enough to just put stm32 to sleep

ag123
Wed Jun 07, 2017 2:47 pm
try lipo batteries? seem like a good idea just that there’d be extra costs and circuits of a battery charger (this could make things somewhat bulky with so many pieces of modules stringing together)
‘usb 5v lipo chargers’ seemed rather abundant on ebay though
http://www.ebay.com/sch/i.html?_odkw=li … +&_sacat=0
and it seem there are some threads discussing if these lipo chargers are after all sufficiently safe

stm32 may be made to run in low power modes e.g. with the lipo batteries, perhaps adjust systick to fire at lower intervals (note this would break millis and system_uptime_millis) and perhaps poll obd2 periodically for the engine rpm, perhaps some kind of ’round robin scheduler’ and with WFI (wait for interrupt) to catch that systick interrupt. http://www.stm32duino.com/viewtopic.php?f=18&t=2117
the downside is that this is literally an ‘always-on’ design
i’d think to save power and perhaps even disable systick. one option may be to use RTC perhaps to set alarms, interrupts to fire at say a few seconds interval. but then this is still an ‘always-on’ polling design, just that the polling interval is ‘stretched out’

the alternatives may simply be to let stm32 boot up when you turn on power / ignition, then perhaps ‘talk’ over obd2 protocols to get the engine rpm. but this is ok if you don’t need an ‘always on’ design. e.g. assume that when there is no power, the engine should after all be ‘off’ :lol:


RogerClark
Wed Jun 07, 2017 9:41 pm
@ag123

I dont know if RPM is sent by all ODB but it works on my Subaru.

Though I think potentially that its not being “sent” but the phone app I’m using is probably constantly requesting RPM ( and other data depending on its configuration)

A whole load of other data seems to be available e.g. speed, engine temperature, air flow etc, and the app I use also displays fuel consumotion (mpg), but I dont know if its computing mpg from speed / fuel usage

Re: Problem with running from 12v

It sounds like the linear voltage regulator is the issue here, as they inherently take current all the time.

but, I thought @ahull had suggested a low current regulator.


michael_l
Fri Jun 09, 2017 10:47 am
Thanks for all the help. I did some more searching and found this one. This is basically what I want and need and it can handle about 200mA. Except that I’ll have to reverse the logic so that it turns output HIGH when voltage is over some limit. This 555 most probably won’t draw much current when it’s monitoring the voltage. Plus it has hysteresis as it has two comparators: threshold and trigger.

http://www.reuk.co.uk/wordpress/electri … ith-ne555/


zmemw16
Fri Jun 09, 2017 11:34 am
istr a warning about them having a large transient current when switching states, there are now more recent variants without this issue.
stephen

ag123
Sun Jun 11, 2017 9:43 am
RogerClark wrote:@ag123

I dont know if RPM is sent by all ODB but it works on my Subaru.

Though I think potentially that its not being “sent” but the phone app I’m using is probably constantly requesting RPM ( and other data depending on its configuration)

A whole load of other data seems to be available e.g. speed, engine temperature, air flow etc, and the app I use also displays fuel consumotion (mpg), but I dont know if its computing mpg from speed / fuel usage

Re: Problem with running from 12v

It sounds like the linear voltage regulator is the issue here, as they inherently take current all the time.

but, I thought @ahull had suggested a low current regulator.


michael_l
Thu Jun 22, 2017 9:54 am
About the powering. I just got an idea that I could perhaps make it work with ATTiny85 i.e. DIP-8 version. It is a)very small to fit inside OBD2 connector case b) it has ADC and digital outputs c) it does not consume power like STM32. So I could make a small arduino program that monitors battery voltage, say once per second then going to sleep. Power consumption would be minimal. I could use simple voltage divider to measure voltage, if over limit the output to HIGH, if lower then output LOW.

AS_Motion_Lab
Mon Jul 17, 2017 8:38 am
Does it definitely need to be OBD based?
You could tap into the ‘idiot’ light terminal from the alternator. This terminal goes high when the engine is running, so you could put a simple circuit in this line which would sense this and power up the mcu when the alternator is turning. The beauty of this is no power consumption when off, and it’s a neat hardware solution.

Leave a Reply

Your email address will not be published. Required fields are marked *