Using arduino to advance ignition timing on dirtbike?

Hello, I have a 2003 dirt bike that I would like to adjust the timing for. The timing is set very retarded from the factory for epa regulations at the time and I also just converted to e85 which I believe with the high octane will allow to advance timing for more power without sacrificing relability.

The way the system works (at least the basics) I believe, is their is a sensor on one of the flywheels which tracks cylinder rotation. On a lot of dirtbikes there is a slot to adjust the position of the flywheel relative to the sensor to advance or retard timing. This one does not have it and I have heard that honda greatly retarded the timing stock to try and meet epa regulations at that time. It was one of the few green sticker bikes as a result. Anyway signal goes to ecu and then to ignition coil I assume, I didn't track the wire yet and I know this doesn't sound reassuring lol.
There doesn't seem to be any simple way to change ignition timing, some do by modifying the flywheel/moving the sensor but that would be very extensive work just to make a future adjustment. It would sound like a very easy project if I wanted to retard the timing cause I could just concept the arduino between the ecu and coil and program a delay. However, no matter which way I look at it I can't think of an easy way to use the arduino to advance the timing. I asume that sensor on the flywheel only tracks when to fire spark and not the current position of the piston.
Is there some simple way to do this that I'm overlooking or is this a very extensive project?

Hellow fellow motorcyclist; Aprilia Tuono pilot here :slight_smile:

One way I've seen this done in past is to track engine speed using a crankshaft position sensor and set an output compare to trigger at some time past TDC. On a two-stroke you can trigger this every rotation; on a four stroke you can trigger it every rotation but ideally you'd know the position of the camshaft (so another sensor) and trigger after TDC on the exhaust stroke.

Suppose you wanted to trigger the ignition at 15-deg BTDC: If the engine is calculated to be spinning at 6000RPM (100 revolutions per second) then one full rotation takes 10mS. IOW, 360-degrees of crank rotation occur in 10mS. If you want to trigger a 15-deg BTDC, you want to fire the spark at 345-deg after the top of the exhaust stroke (recall that the top of the exhaust stroke is also the beginning of the intake stroke; 180-degrees later the piston begins rising on compression.)

If 360 degrees takes 10mS then 345-degrees take 345*10/360 or 9.583mS (or 9583uS) after the TDC edge.

If you use an input capture to capture the exact time of the CKP edge, you can then set an output compare to trigger at edgeTime + 9583uS.

On a four-stroke you have some time to calculate the timing of the next spark since it's only happening once every 20mS at 6000RPM.

So this requires a CKP/trigger signal; if the bike has one it may not be set to trigger at TDC so you may need to account for that. If it's a four-stroke a cam sensor would be nice. If you don't have that sensor, you can trigger on every TDC (vs every second one) and "waste" a spark on the exhaust stroke.

You'll probably want to measure more than engine RPM to set spark advance; MAP, throttle position, intake air temp etc would all be nice.

Sounds like a fun project. Could be challenging (esp. if the electrical system is noisy or you get RFI from the plug/coil/wire(s) into the Arduino...) but fun.

Blackfin:
Hellow fellow motorcyclist; Aprilia Tuono pilot here :slight_smile:

One way I've seen this done in past is to track engine speed using a crankshaft position sensor and set an output compare to trigger at some time past TDC. On a two-stroke you can trigger this every rotation; on a four stroke you can trigger it every rotation but ideally you'd know the position of the camshaft (so another sensor) and trigger after TDC on the exhaust stroke.

Suppose you wanted to trigger the ignition at 15-deg BTDC: If the engine is calculated to be spinning at 6000RPM (100 revolutions per second) then one full rotation takes 10mS. IOW, 360-degrees of crank rotation occur in 10mS. If you want to trigger a 15-deg BTDC, you want to fire the spark at 345-deg after the top of the exhaust stroke (recall that the top of the exhaust stroke is also the beginning of the intake stroke; 180-degrees later the piston begins rising on compression.)

If 360 degrees takes 10mS then 345-degrees take 345*10/360 or 9.583mS (or 9583uS) after the TDC edge.

If you use an input capture to capture the exact time of the CKP edge, you can then set an output compare to trigger at edgeTime + 9583uS.

On a four-stroke you have some time to calculate the timing of the next spark since it's only happening once every 20mS at 6000RPM.

So this requires a CKP/trigger signal; if the bike has one it may not be set to trigger at TDC so you may need to account for that. If it's a four-stroke a cam sensor would be nice. If you don't have that sensor, you can trigger on every TDC (vs every second one) and "waste" a spark on the exhaust stroke.

You'll probably want to measure more than engine RPM to set spark advance; MAP, throttle position, intake air temp etc would all be nice.

Sounds like a fun project. Could be challenging (esp. if the electrical system is noisy or you get RFI from the plug/coil/wire(s) into the Arduino...) but fun.

Thank you for the very detailed reply. The bike is a 4 stroke, xr400r to be exact. I was afraid that it would be this involved. It definitely will still be on my list of things to do but I think I'll make my own fuel injection with arduino first since it seems much simpler. Plus I'll need a map(which I have an extra boost sensor that reads vaccum which should work) and an rpm signal/throttle position which would help aid in this project. I'm gonna keep the pilot jet so I don't have to tune for idle and I hopefully won't need a battery.

You could face similar issues with fuel injection if you do any sort of "sequential" operation; you'll want to fire the injector on the back of the intake valve when it's closed (e.g. TDC on the compression stroke) and so will need to time that too.

When you say intake valve do you mean throttle plate in the carb or the intake valve of the engine. I'm not sure if it's required that I time the fuel when the intake is closed. I assume the carb always supplies fuel from the main jet when the throttle is opened since it gets delivered to the engine from the vaccum. What I was trying to do at least is simulate what a pumper carb would do to try and eliminate the off Idle bog when flooring the engine from idle. They sell a pumper carb for this bike but for like $400. I figured this would be cheaper and a fun project. Plus it may even perform much better than the carb being fuel injected and since I have more control than the carb does. Do you think it would matter if I put the injector after the thottle plate right before the engine? I ask this since the main jet is before the plate.
Please let me know if any of this sounds right.

Also, do you know of a good type of sensor I can put on the throttle cable/slide to read throttle position? Thanks.

Port fuel injection will inject fuel right into the intake port, behind the intake valve. If you want to emulate an "accelerator pump" you can probably get away with an injector a little further up in the intake tract. If you want to replace the carb with an injector placement will be much more critical.

Don't forget that you'll need a high pressure fuel pump and lines to feed the injector too.

Don't underestimate the ability of a properly tuned carburetor; they're actually very good analog computers when tuned right. :slight_smile: