Would like some help interfacing Arduino with OBD2 computer on car

Hi Guys

My name is Lorant and I bought the arduino kit to build what I had in mind but I am having a really hard time and I would like to ask for some help please.

I have written the logical diagram of what I would like the Arduino do for me but i am having trouble with the coding.

What I would like is

my engine running normal, is the the engine above 50C?

car stopped?

clutch depressed?

in neutral?

engine stops.

if one statement is not valid from any one above engine runs.

if car in neutral, with clutch depressed, engine starts

if above statement not valid, engine stays off.

Would someone be kind to help as I am stuck and I don't know where to start.

I appreciate you guys help in advance.

Thank you

By saying that you're having trouble with the coding, you are suggesting that you already have the hardware sorted out.

How are you detecting that the car is at a standing still?
Do you have the switch mounted to detect the clutch is depressed?
Do you have an input that tells you that the car is in neutral?
Do you have something attached to the arduino to detect the temperature?
Do you even have any method to detect if the engine is, indeed, running?

I'd also suggest that on the average car this project would give you more grief than it's worth. Nonetheless, if you can get these issues sorted it would be a very easy project to implement.

[edit] Post schematic of you circuit.

Post a parts list of your components. Post a mechanical drawing if you have one.

My apologies for previous comments Lorant. You seem to be on the level.

Strikes me the mechanical aspects are wayyyyy more complex than the computing. If your car already has accessible sensors for all of those things you need to sense, well that's a good start.

By accessible I mean not just physically (in the sense you can get your hands on a wire) but electrically in terms of voltages and so on.

If there are no such sensors, it will be a major pita to try fit some I'd say. How would you fit a switch to the gearbox / gear lever for example, to sense neutral?

Then of course there's the whole aspect of making it bullet proof so the engine doesn't cut out at the worst possible moment.

Hi guys

I am actually a licensed auto service tech, who does have a vw golf, and I want to save a little bit on fuel by having the arduino programmed to my needs. Im 34 and work at a tool store, Im not a University student and I don't have homework to do. Its for my personal use only and yes I do have all the hardware kit that came with the Arduino.

Question from before

How are you detecting that the car is at a standing still? I will use the signal wire from the speed sensor on the car, the speed sensor has 3 wires, one ground, one 5 volt and one signal wire. Arduino has to look for 0 sine wave then one "if statement" will be accomplished.

Do you have the switch mounted to detect the clutch is depressed? there is almost always a switch on the clutch pedal, mine has one.
Do you have an input that tells you that the car is in neutral? There will be a momentary switch mounted on the shift lever above the transmission.

Do you have something attached to the arduino to detect the temperature? I was thinking of using a thermistor, but I could use a 50C on/off temp sensor to do the job.

I am willing to work with someone here online to get my little project completed.

I have nothing to hide. Just a lonely sole trying to save a little in fuel.

Thank you guys

Any help is surely appreciated.
If you guys need proof i can take images of the car and what i have done so far.

Cheers
Do you even have any method to detect if the engine is, indeed, running?

If you were to pass the the ignition wire through the contacts of a relay, you'd then have a simple method to kill the engine with a simple digitalOut.

Another relay could be used to send a signal to the starter solenoid to turn over the engine. This would need to be turned off once the engine is running.

So the final sketch would be quite simple, but along the way you'd have to write quite a few small test sketches to ensure that all of your input signals are behaving the way you expect.

What I'd suggest would be to attach your arduino to a laptop and then, one by one, get each input working. Any 12v signals would need to be put through a voltage divider to make them compatible with the IO voltage levels of the arduino.

The following code could help you ascertain that any inputs are doing what you expect.

#define inputPin 2

void setup()
{
Serial.begin(9600); 
}

bool lastInput=0;
void loop()
{
bool inputState=digitalRead(inputPin);
if(inputState != lastInput)
  {Serial.print("Input State changed to ");
   Serial.println( (inputState==HIGH)? "HIGH":"LOW" );
  }
lastInput=inputState;
}

There's a basic logical problem in the middle there.

Lorant:
clutch depressed? in neutral? engine stops.

if car in neutral, with clutch depressed, engine starts

Your conditions for stopping the engine are the same as for starting it. I hope your "logical diagram" has a bit more detail than this.

The basic idea seems simple enough but it gets complex dealing with a real engine. How long does the Arduino hold the 'start' relay to ensure that the engine has actually started? Does it need to sense engine RPM and hold the starter on until a minimum speed is reached? How quickly can it detect this speed threshold? You may have noticed a lot of cars in the last few years have a more automated start sequence - this indicates to me that it's a hard problem that the car manufacturers have only recently solved.

Stopping the engine without basically cutting the ignition is also going to be difficult - you don't want your indicators and brake lights to switch off in this state, let alone the music you are listening to. Doing this in a way that won't freak out the car's existing engine management system will require some intimate knowledge of that system.

Lorant:
I don't have homework to do.

On the homework thing, well I can't apologise on another member's behalf, but this rant:

raschemmel:
When is your homework due? (this isn't our first Rodeo) We know what you're doing. This post is so ridiculously fake it's not even funny. You are not doing any project. There is no car. You are trying to get us to do your homework.

..... was just a member being a bigger ass than normal.

So, moving on....

This project cries out to be treated as a state machine, on which at least two members here have info:

Nick Gammon
Grumpy Mike

I'd really encourage you to do this as a state machine. If nothing else, a state diagram will help clarify all the circumstances the system may be in, and when you put all the possible events on top of that, you'll see all the ways it can change from one to another. In particular it might help identify any illegal or undesirable behaviours.

Hi Guys.

I thank you for all your great help so far. So far the last few post have been very helpful. I am very good with auto electrical in general, looking at wiring diagrams and figuring out what the ecu is doing or not doing or what sensor is intermittent but when it comes to microcomputers and code programming I have to say that is on my weaker side. I admit I truly suck at it and that is why I am here asking for help from knowledgeable people.

So the idea I had... here is what I would like to program into the arduino or at least get some help with it.

Starting with the previous questions...

How are you detecting that the car is at a standing still? I will use the signal wire from the speed sensor on the car, the speed sensor has 3 wires, one ground, one 5 volt and one signal wire. Arduino has to look for 0 sine wave then one "if statement" will be accomplished. Or if rpm is below 1200 rpm, then its an accomplished task.

Do you have the switch mounted to detect the clutch is depressed? there is almost always a switch on the clutch pedal, mine has one.

Input that tells you that the car is in neutral? There will be a momentary switch mounted on the shift lever above the transmission.

To detect the temperature? I was thinking of using a thermistor, but I could use a 50C on/off temp sensor to do the job.

Do you even have any method to detect if the engine is, indeed, running? To detect that the engine is running I would get a clamp style pince inductive pickup, similar to the ones used on timing lights. That way I can clamp it to one of the spark plug wires and when the clamp produces inductance as there is spark, then it would tell the arduino to stop cranking.

I would like to put the same arduino in my wife's golf diesel, and for crank signal im not sure what kind of feedback i would use, maybe increase in battery voltage as it would go from 12.5V to 14.4 volts, actually it might be easier to detect the battery voltage and keep it simple. Voltage increase stops cranking type of thing. Or I could take a signal wire from the crank sensor to have a signal for the arduino to see, soon as it sees the square wave, stops cranking.

Ken would you be able to explain in detail what you mean? I really like the idea but I want the system to be foolproof. We are all on the right track I believe. Lots and lots of great info. The relay part I get, the arduino part I don't. The coding you sent over, what does that actually do?

Morgan, as for the logical problem, I would like to differentiate between " clutch and clutch" the arduino has to see that I have depress the clutch, then the shift lever has to be in neutral, then release the clutch pedal, then the car stops, the engine only restarts if you depress the clutch pedal. Seems simple but I cant get my head around it even though I've been in the automotive field for 15 years full time.

As for fuel cut off, diesel is simple, splice into the fuel cut off solenoid, then arduino activates a 12v relay then applies voltage to the solenoid, engine shuts off, as for the gas engine, cut the 12V side of the fuel pump, or spice into the fuel relay wire.

Jimbo thank you for those great sites. I will read through them for sure.

Would I have to do the entire coding myself or would some you be able to help me code my arduino R3, its a little over the top when it comes to coding.

Thank you guys

Your method of using an inductive coil from the spark plug MIGHT work, alternatively perhaps the signal going for one of the injectors would do the trick more reliably. Either way, just testing for it's existence wouldn't mean the engine is running. These signals are present even when the car is being cranked but not yet fired up. So the test should be how fast the engine is turning (ie time between those signals).

Most cars will not crank faster than about 120 RPM and also it's unlikely that they'll still be running with a tickover of less than about 500 RPM So When the engine is being cranked, a threshold of around 300 RPM should ensure that the engine is actually running on it's own steam.

The kill switch would be simple to implement as would the starter. A basic 2 relay shield would be ideal. The trickiest part is going to be getting all of your various inputs available to the arduino in a form that is acceptable. I assume you're familiar with the simple method of using two resistors as a voltage divider?

... was just a member being a bigger ass than normal.

Thank you for sharing....

raschemmel:
Thank you for sharing....

If I had any say, you would be banned for rudeness. But let's not let that spoil this new member's thread.

Lorant, when you post, on the bottom right is a button marked preview. when you press that , the screen changes and you see a new section of smiley faces. just above them is a row of icons. 6th in from the right is a bubble.
you can type a line, hit enter a couple times to create blank lines below, then highlight it then click that bubble

I typed this line, then highlighted, then clicked the quote icon

then you can post a response to that comment,
it will make it easier to read your posts.

me, I missed the rodeo....

can you connect to the ECU with an OBD ?

maybe you can get the ECU to just hand over the information ?

engine RPM and vehicle speed are both available.

also, run time since engine start is (may) be available.

if you can just pull the data from the existing ecu, then all you need is programming.

someone asked about the incompatible logic of if car is not moving, then start, if car is not moving, shut off.
well, if car is not moving and time since engine start is greater than 3 minutes, then shut off.

also mentioned was knowing when the engine is running and when to stop energizing the solenoid to the starter. RPM. at idle, over 600, while starting, under 100. simple to detect and just as easy to control.

JimboZA:
If I had any say, you would be banned for rudeness. But let's not let that spoil this new member's thread.

// rant mode ON
how can we get the next revision of this forum to have a thumbs up and thumbs down ? there are quite a few posts of people just asking stoopid questions that are annoying because they do not contribute anything. would love that we as a community could tick off that box for those that tick us off.
// rant mode OFF

Lorant, I suggest you go back to your first post and change the subject line. a subject line that includes words like car sensors, ODB, and such will draw in those that know about those things. just asking for programming help on the project guidance section of the forum does not get you in the software/coding section. and the vague subject line does not catch the eye of your equals on car electronics.

need help interfacing with OBD computer on car

would catch the eye of those that already do that. as you can tell, half of us have been to a rodeo.... others, seem to be trying to figure out how to milk that bull.

Hey guys

I believe the inductive coil will work as if the ardunio sees voltage/signal for more than 5 seconds then stops cranking.

Alternatively perhaps the signal going for one of the injectors would do the trick more reliably. Either way, just testing for it's existence wouldn't mean the engine is running. These signals are present even when the car is being cranked but not yet fired up. So the test should be how fast the engine is turning (ie time between those signals). Hmm I understand where you are coming from but i would be 65 years old before i could program/code something like that.

How would I code the arduino for a 2 relay shield? I have no idea how to do that to be honest. Smart... but not that smart.

Using 2 resistors as a voltage divider....hmm, stuck again.

Dave you are right on..... OBD2 would work best and it would work like a dream, you have all the inputs from ALL the sensors,

including engine temp, variable resistor sensor
clutch switch position, momentary switch on pedal
speed of vehicle, abs sensor
12 v feed power is already there
ground is already there.

How am i going to connect the arduino with the OBD2 is way above my knowledge level. I believe I would like some help please. I can do all the 12V wiring for sure, but coding.... :frowning:

I like both ideas, either the 2 relay shield or the OBD2 connected to arduino.

Which would be easier/ simpler? From experience I would say OBD2 ( then I basically have to make a OBD2 homemade scanner), although reading what can an arduino can do with the right code is just blows my mind.

What do you guys think?

Did I mention you guys are great? :slight_smile:

Thanks again

Hey

Do I need this for my project?

http://www.ebay.com/itm/Can-Bus-Shield-/201205674118?pt=LH_DefaultDomain_0&hash=item2ed8caf086

can bus shield

or this?

http://www.ebay.com/itm/Vehicle-OBD-II-Digital-Gauge-DIY-Kit-Arduino-Nano-OLED-OBD-II-Adapter-/251754745127?pt=AU_Car_Parts_Accessories&hash=item3a9dc08d27&vxp=mtr

or this

http://www.ebay.com/itm/USB-KKL-VAG-COM-409-1-Cable-For-OBDII-OBD2-Car-Diagnostic-Scanner-8340-/181336830840?hash=item2a38847378&item=181336830840&pt=Motors_Automotive_Tools&vxp=mtr

Ok, its 1 am here, Lorant sensor; low ;

{

}

If you want to read OBD2 via serial you could just buy a genuine ELM327, and the documentation for the genuine one is available on their website. See here.

There are a lot of fake ELM327s about.

Isn't there a signal or circuitry already present that prevents cranking if the engine is already running that could be used for some cases in this project? - Scotty