Go Down

Topic: Ardunio as ECU ~(2 cylinder engine) (Read 5725 times) previous topic - next topic


I have done a little bit of looking round on the internet to try and dig up info on if this idea was possible. Basically I have an old motorbike (a Kawasaki 250cc twin cylinder) and while I have been busy building some of my vehicles to diesel, I want to keep some fun ones petrol.

With the idea of keeping the bike petrol I wanted to look at ways on how I could make it super efficient, so the old twin carbs would probably be better replaced with injection setup. I know that a while back when the bike did run the contact breakers for the ignition were a bit of a problem, so I would look to make the iginition electronic.

you can obviously get a 'megasquirt' kit to do this type of thing but its megamoney and I want to build something cheap and from scratch. I have injectors knocking about already, I am going to need a few sensors I think but I think my main concern would be if the arduino was up to the job?

Sensor wise I know I will need engine temp (which will be fun on an old aircooled end) I thinking I will need some sort of engine position sensor, I was thinking of using maybe an optical cutter wheel setup maybe out of something like a mouse as that would give pretty accurate resolution(maybe too much) I'll probably need an exhaust sensor, but its the airflow sensor I am none to sure about. Modern bikes do have fuel injection but I dont know how they measure airflow.

Bit of a side project this one to research over time, but only worth doing if the ardunio would be upto it. Running a 2 cylinder aircooled engine that revs to approx 8000-10000rpm.

What are your thoughts on this?


If fuel economy is your aim, I think you should look at Megasquirt again. If you build it yourself they're relatively cheap.

I'm quite sure you can get an ECU good enough to run the engine with an Arduino, with enough development time and money. But I don't think you'll like the result. Arduino doesn't have the storage or processing speed to do the sort of fully mapped solution that Arduino gives, or the temp compensation, cranking, transient enrichment algorithms and so on that Megasquirt provides out of the box.


Well I was kind of thinking that perhaps using something like an SD card for testing I could maybe build my own tabling system and work out a set of rules. Megasquirt works out at hundreds of pounds, an arduino basic I can build for just £7! also I think the arduino can be built to be much more compact than a megasquirt system.

My basic train of thought with this system was that spark control might not be to difficult as essentially you can almost get electronics to run that on its own, although I'd like to maybe be able to program my own spark curve eventually, but my thinking is there must be a standardised rule that could be built for this with some sort of table. As for the fuel injection system I figured we have to start by effectivelly making an electronic carburettor, which just introduces some fuel at the right point, to get the right fuel ratio for given conditions or working from a table.

I am sure I could figure something simple out if I spent enough time working out a table.

I guess realistically, I like the idea of messing about with it to get it working and then refine it, from what I have read online it seems that the main mention is the actual processing power of the arduino and if it can handle the calculations fast enough.


Buying a fully assembled Megasquirt can set you back hundreds of pounds, but you can buy the PCB and components far cheaper than that.

I suggest you start working out on paper what your fuelling algorithm is going to look like. Bear in mind that it is not only steady state warm running that you need to deal with. You need at least a 2-D map, and you will need several modifiers on top of that. You will also have to condition your sensor inputs to get indexes into the map. You will need driver hardware for all the inputs and outputs. Would you be using EDIS ignition with a crank trigger wheel? That at least deals with most of the time-critical stuff for you and gives you a reliable engine speed input but you still need to provide coolant temp sender, TPS, EGO, MAP inputs and EDIS (or coil driver) outputs and an injector driver. By the time you've bought wiring and connectors this will start adding up - I spend well over a hundred quid just on raw materials to make an ECU loom.

You will need to have a way to develop your tune. The most practical way to do this is with wideband lambda monitoring, but to be practical you need to have data logging capabilities built into the ECU so that you can correlate the EGO feedback with the fuelling that was applied at the time. If you don't have a wideband EGO sensor/controller then this won't be an option, since this will cost more than the Megasquirt. It's possible to map it with a narrowband sensor but it's quite a painful process. Real time data logging adds to the CPU and memory requirements, of course.


Yeah fueling is the big part, needs to start with a basis that at AFR is 14.7:1, then calculate approx what air quantity the engine is likely to inhale per minute, thus being able to work out how much fuel in theory you need to mix with that for it to burn at ideal. Then dividing that amount by the RPM would give you the amount of injector pulses per minute and you would have to work out the amount of fuel to push through per pulse. You could probably build a fairly uniform table for that. but alot of head work and I am just throwing the idea out there before I start trying to do the computations.

to Fire the injectors I believe you can use mofsets, the ones in computer PSU's handle a fair amount of juice so I am sure they will be fit for purpose (I had been reading on these else where on the internet). Throttle position sensor is just a pot, the duel bike throttle body I happen to already have has one on the side. I need to invent an engine temperature sensor as being aircooled it doesn have one!

I didnt plan on using EDIS, theres not the room for the EDIS pack considering how big they are, I was just going to trigger the existing bike coils using some power transistors/mofsets/something the same way electronic ignition systems used to work, meaning the arduino would just need to be a small switch to earth. As for trigger wheel I was thinking of building my own optical wheel setup using something like the parts out of a mouse, my only issue there would be the amount of heat it was subject too, making a hall effect sensor more useful, once again though space is a limit.

Wiring and connectors, well I have a complete loom from an early 90s mitsubishi, theres more than enough wire and connectors on that to use for this project!

Data logging wise, the arduino is capable of that using SD cards and I guess to some extent the purpose here is that you would need to data logging to start with, so build the engine and fit all the sensors, but have the engine running on carbs/points to get some data together, then tune a table for the running.

I havent really thought it all through yet, the biggest thing is trying to get my head round the amount of instructions the arduino could do per second, as relatively speaking there isnt tons going on, its just the speed at which it happens like an injector having to fire 250-2500 times a second to get the fuel in (think thats right but there may be a different way of doing it). I may be barking up the wrong tree a little, but at least I have some ideas and a starting point I think :)


The problem with that theory is that you have no way of measuring the mass of air being drawn in. Even supposing you add a MAF sensor (which you don't seem to be proposing) it doesn't measure true air mass.

At first glance you have a processor capable of reading inputs and turning outputs on and off and that's what an ECU is. My point is that to manage the fuelling well enough to have a tractable engine needs non-trivial mapping and algorithms and your Arduino has very little processing power and next to no RAM at all.

BTW, at 6000 rpm your crank is rotating at 100 Hz which means each cylinder is firing at 50 Hz (4 stroke), double that for 2 stroke. You don't need to be driving injectors at thousands of Hz. But if you're doing all the trigger wheel / phased locked loop stuff yourself and calculating load and speed and then interpolating fuel and ignition requirements and managing the dwell and transient enrichment and temperature related enrichment and so on there is a lot going on. I don't think the Arduino has enough processing power and RAM available to do everything you would need to do.

And I also think that by the time you've priced up all the driver hardware and connectors and actually built the thing, you won't have saved much money over a Megasquirt kit and you will have spent a hell of a lot more time getting a working solution which (a) is inherently very limited and (b) requires you to debug the hardware and software and develop your own data logging analysis techniques / applications at the same time as you're trying to get the engine to run and tune it.

Nothing to stop you trying, and if you're clever and determined enough maybe you will make it work, but my advice is that starting from scratch you have set your self a tough challenge and by basing your solution on Arduino you have made it much harder still.


I don't know much about motorbikes, but traditional car alternators use RPM and vacuum to advance the curve which should be easy enough with arduino. RPM alone from a hall effect sensor should be enough to get you started. I'd go with the ignition first and then the injection. I wouldn't try to calculate the mix so much as tune in a practical way based on experiment. Hopefully the arduino will cope with the lookups at the top end.

I suspect that you could get the bike running with RPM sensors alone.

Sounds like a cool project but I think it'll be an uphill battle to get good results.


I think you have a great little project here ! I have been considering doing this myself, I have a little garden tractor I'd like to convert!

First of all I think the arduino has the ability to do the job, however it will have to be optimized fairly well and you will prolly need to take a few shortcuts ...

If you already have points on the engine you could use that as your 1/rev signal ... You will need to determine the offset however,

You need to determine the relationship of your cylinders and crank, if both cylinders are beside each other and move up and down at the same time you can just fire both cylinders together on every revolution,

If you want to run continuous injection you can prolly use the pwm outputs at a sufficient frequency, depending on the injectors you decide to use the pulse length might be a few ms,

Use a mass airflow sensor ... Such as a Hotwire sensor , this will correct for inlet temp pressure and density,

Throttle position sensor will help you fine tune the system,

Using the once per rev signal ( interupt ) you will be able to calculate timer interupts for the spark and if you choose for the injector pulse,

After that you could add an oxygen sensor in the exhaust to trim the fuel air ratio,

Remember a carb is a very crude fuel metering device... It should be relatively easy to replicate, having a fully tuned fuel injection loop will be a little trickier ... But I have no doubt you should be able to get it running!


Remember a carb is a very crude fuel metering device... It should be relatively easy to replicate, having a fully tuned fuel injection loop will be a little trickier ... But I have no doubt you should be able to get it running!

Your ECU has to work pretty darned well to match the fuelling accuracy of a properly setup SU, and the SU will win hands down in terms of mixture preparation.


Your ECU has to work pretty darned well to match the fuelling accuracy of a properly setup SU, and the SU will win hands down in terms of mixture preparation.

All engineering is best defined as an activity to select design variables that least compromise or best suit the application at hand. Every engineering project is an accumulation of compromises that accomplishes a task.

The current post is not a debate on whether an su carb will have better mixture control than a home built arduino fuel injection system. The OP wanted to know if it would be possible to build a fuel injection system for a 2 cyl engine and have some certainty that it will work. And the answer to that is YES. I am glad you have come to offer your input, however the op Is obviously interested in learning all the ins and outs of of designing a fuel injection system and is looking for help and encouragement, personally I find your posts pessimistic in response. He did not come here to be told to go buy a mega squirt. 

It is a pet peeve of mine when questions are asked in regards to research and design and people have nothing constructive to input!  Instead they say things like don't bother it's really hard! Or don't touch the mains it's really scary! Or you cant run a gasoline engine on propane without a fancy fuel metering system! Etc etc

Perhaps you could use your "extensive knowledge" in a way which contributes to the project ...

This link is worth a look ...

And to prove my point about how simple it can be ... This was the article that inspired me...

I have run gasoline engines by dripping gas into a carburetor from a pop bottle, some carbs are fancier than others, yet the main goal is nothing more than to meter the proper fuel for the given airflow. The more precisely you want to run this number the more variables you need to account for.

This will be a fun little project and you will learn all kinds of things ! 

A few hints ... 

Mass airflow sensor...

Calibrate your injectors on a bench before you install them to get an idea of what kind of pulse length you will need ...

Good luck and I look forward to seeing your results ! 


Here's another link to estimate the mass airflow from a map sensor


At 10k rpm 1 rev would be about 6ms which should be lots of time to calculate what you need ... Even if it took 2 rotations ... 12ms ... At 10k rpm fuel calcs would make little difference, spark ignition timing would be the critical one. You could also split the calcs in half over 5k and do half the calcs or acquire sensor values one rev and then calculate the next rev...


The current post is not a debate on whether an su carb will have better mixture control than a home built arduino fuel injection system.

I was responding to the comment above that carbs are crude fuel metering devices. They aren't. A well designed and well set up carb can be a highly accurate fuel metering device, and they have some inherent advantages over fuel injection. By mixing the fuel into a turbulent air flow in phase with the air flow it can be arranged to mix well and evenly. On the other hand, supplying fuel by opening and closing a tap for brief periods and hoping that the fuel will splash around inside the inlet port and evaporate and mix with the air is a much cruder approach. With a smart enough control algorithm, and the injectors in the right place so that you can get decent evaporation off the valves, it works fine. And of course modern systems do that. But with a simplistic control algorithm, this may end up no better than the petrol squirted in from a bottle that you mention.

Certainly you can get it working well enough for the engine to run. Engines will usually run over a wide range of AFRs. Whether it will produce an engine that is tractable and economical is another matter. If this problem could be solved well using such limited hardware, there would be no need for OEM and aftermarket ECUs to be as complex and expensive as they are. Even WITH these sophisticated control algorithms, it takes a lot of development work to get decent power and economy and tractability. For a motorbike where fuel economy has been described as a primary requirement, I expect these to be important.

As a fun project there's no reason not to run the engine using an Arduino. But if the goal is to get a tractable and economical engine, I think the Arduino is the wrong tool for the job.

You suggest that I should be more constructive, but when the OP is asking how to do something that is not sensible, the best advice that I can give is that it's not sensible. By encouraging him to build up false expectations I would not be doing him any favours.


@ PeterH, what you think about the processors like stm32 on olimexino/armduino or maple/chipkit 2 ?, these boards are fairly economical and loaded up with sd card shield etc  and they are much more powerful than the arduino, Are they feasible?
"Real Men can Accomplish  Anything"

- skype : nishants5  
ਫ਼ਤੇਹ ਕਰੁਂ!


I quickly tried to find it, but had no such luck. There are ECU/ECM AVR projects out there. Some of them attempt to rival the squirt project. From reading some of these projects, its pretty clear that the squirt has its own laundry list of problems, issues, and miscalculations. One of the projects I was reading, the author is developing his for high HP applications. Its a project which spans many, many years. Last I read, he had blown up his (IIRC - slept a lot since then) [6-8]00-HP engine on it. I even watched a video or two online of people running around in 4-6 cylinder engines. The project was no where near as popular as the squirt nor does it have anywhere near as many testers. Regardless, finding projects to leverage is just a matter of surfing to find the material.

Clearly, a large mega can meet the needs of an ECU. And given you can fairly easily add memory (up to 512K) to some of the higher end AVRs, I'm not seeing anything with such a project which AVR can't do. 512K should be plenty of memory for a large variety of look up tables and because of native CPU support, the overhead incurred for accessing this memory is very minimal (IIRC, one or two extra cycles to change banks). And that's far more memory than many ECUs had available to them several decades ago. Now then, I'm not saying AVR is the perfect choice for an ECU project, but its certainly a very viable option, which has been demonstratively proven.

I also want to add, carbs are really not that great. That's not to say they are bad. Far from it. They do a perfectly adequate job of metering fuel. But good fuel economy requires much more than just metering fuel. And in comparison, carbs frequently have a much harder time getting good atomization compared to fuel injection, especially compared to throttle body injection or more advanced techniques such as was described above. And because of how carbs work, they typically are slowly reactive at best (usually vacuum driven) whereas ECUs can be predictive. As such, all things considered, its not difficult to meet what a carb can do. That is, in fact, why everyone went to fuel injection and ECUs (one of many reasons in fact). Beating the results of what a carb can do is where the real challenge begins. With the know how and right array of sensors, its easily possible to exceed what can be achieved with the best of carbs. And for many people, that challenge is where the fun is at.


Is the bike you are wanting to convert a 2 stroke or a 4 stroke?

As far as sensors - My sons both had Suzuki SV650's and they were both OPEN-LOOP systems. Meaning they had Throttle sensors, RPM sensors, temperature sensors and probably airflow or vacuum sensors. No oxygen sensors, and on a 2stroke the oxygen sensors would probably not last.

Go Up