2 stroke on board diagnostics for sprint engine

Hi All,

Completely new to to the world of electrickery and arduino. And although new I plan to build a 'Magic Box' that can be mounted on my sprint bike and take a feed from the 12v supply from my ignition system. A number of sensors will conect to the 'Magic Box' will will record to an SD card as well as displaying some of the data to an LCD display mounted on the dashboard.

The sensors required are:

Speed Sensor - Sensor on forks picking up a pulse from a magnet located on the front wheel hub.
RPM - Wire wrapped around the HT lead
EGT - Exhaust Gas Temperature
CHT - Cylinder Head Temperature
BHP and Torque - Can be calculated using an accelerometer to calculate GForce. I can then use this combined with the RPM and weight of the bike/rider to calculate BHP/Torque
Lambda - God only knows how I'm going to do this and he hasn't decided wether or not he's going to share this yet :slight_smile:

So my questions are :slight_smile: . . . . . . . . . . .

  • Can I run all of these sensors off an UNO? I have just bought one of these.
  • How do I get a single voltage reading from a ADXL335 accerometer? If I can pick up the voltage I can do the math
  • Is it possible to log the data from multiple sensors to the SD on one line of a .csv or .txt file
  • How often could I log this data to the SD card. I really need the data to be logged as fast as possible to really see whats going on over a quarter mile distance. Its all over in around 14 seconds

The bike is actually a classic scooter that has a basic wiring loom so none of the cool modern stuff that I can just splice into.

ps Standard the scooter did 28mph, last recorded speed was 79.9mph, new target is 100mph :slight_smile:
To get there the engine needs to be set up precisely hense the need for the 'Magic Box'

pps Not sure if I was supposed to say hello anywhere? If I am please point me there and if not then Hi I'm Wayne, you'll be hearing a lot from me over the next few months :slight_smile:

How do I get a single voltage reading from a ADXL335 accerometer?

This question makes no sense. An accelerometer reports instantaneous acceleration (change of velocity). Typically, an accelerometer will contain 3 measuring systems, at right angles to each other, so that you can get acceleration in x, y, and z directions independently.

If I can pick up the voltage I can do the math

Yeah, right.

PaulS:

How do I get a single voltage reading from a ADXL335 accerometer?

This question makes no sense. An accelerometer reports instantaneous acceleration (change of velocity). Typically, an accelerometer will contain 3 measuring systems, at right angles to each other, so that you can get acceleration in x, y, and z directions independently.

The seller states that:

0 volts = -3G
1.65 Volts = 0 G
3.3 Volts = +3G

There is a way to do this, I’m just trying to understand how I can implement it. Do fix the accelerometer at a certain angle; facing in a certain direction and just use one of the axis. Or is there a formula that I can use taking a reference from all three axis. Has anybody tried to do this?

See second paragraph of description from seller below:

This breakout comes with 3 analog outputs for X, Y and Z axis measurements on a 0.75"x0.75" breakout board. The ADXL335 is the latest and greatest from Analog Devices, known for their exceptional quality MEMS devices. The VCC takes up to 5V in and regulates it to 3.3V with an output pin. The analog outputs are ratiometric: that means that 0g measurement output is always at half of the 3.3V output (1.65V), -3g is at 0v and 3g is at 3.3V with full scaling in between.

PaulS:

If I can pick up the voltage I can do the math

Yeah, right.

Its simple, To calculate volts into G Force using the numbers from the supplier I use (Volts/0.55)-3
To calulate G force into lbs/In I just use ((Volts/0.55)-3) x Weight of Scooter and Rider combined
To calculate BHP at any given RPM I use RPM x (((Volts/0.55)-3)x(Weight))/63025
And to calculate Torque I use (BHP/RPM)*5252

Like I said I can do the math, I just need to know how to take the readings from the ADXL335 but thanks anyway for your constructive comments :slight_smile:

Regarding the acelerometer, I've just found the data sheet and it states that the ADXL335 is ratiometric, therefore the output is relative to the input. Would I be right in saying that in order to record the acceleration of my scooter I need to set my accelerometer at the correct angle in the correct direction and only monitor one axis. I also need to calculate a formula to work out the output in volts based on the input in volts or have I got this completely wrong?

Thanks in advance for any response

Ha, this is too easy! 8)

Ive just read up on some stuff and it seems that the numbers being outputted are Analog to Digital Converter (ADC) values 0-1024. Therefore I know that :

0 volts = -3G
1.65 Volts = 0 G
3.3 Volts = +3G

so this simply converts to:

0 ADC = -3G
338 ADC = 0 G
676 ADC = +3G

So read G from the accelerometer I use this formula:

(ADC-338)/112.6667

Therefore if I update my formulas everything should work

To calculate ADC into G Force I use (ADC-338)/112.6667
To calulate G force into lbs/In I just use ((ADC-338)/112.6667) x Weight of Scooter and Rider combined
To calculate BHP at any given RPM I use RPM x (((ADC-338)/112.6667)x(Weight))/63025
And to calculate Torque I use (BHP/RPM)*5252

OK, So thats the accelerometer sorted, so back to my original questions:

The sensors required are:

Speed Sensor - Sensor on forks picking up a pulse from a magnet located on the front wheel hub.
RPM - Wire wrapped around the HT lead
EGT - Exhaust Gas Temperature
CHT - Cylinder Head Temperature
BHP and Torque - Can be calculated using an accelerometer to calculate GForce. I can then use this combined with the RPM and weight of the bike/rider to calculate BHP/Torque
Lambda - God only knows how I'm going to do this and he hasn't decided wether or not he's going to share this yet :slight_smile:

My questions are :slight_smile: . . . . . . . . . . .

  • Can I run all of these sensors off an UNO? I have just bought one of these.
  • How do I get a single voltage reading from a ADXL335 accerometer? If I can pick up the voltage I can do the math SOLVED
  • Is it possible to log the data from multiple sensors to the SD on one line of a .csv or .txt file
  • How often could I log this data to the SD card. I really need the data to be logged as fast as possible to really see whats going on over a quarter mile distance. Its all over in around 14 seconds

Can I run all of these sensors off an UNO?

You don't "run" the sensors. You read the sensors. Exactly how depends on exactly which sensor you are talking about. The speed sensor is typically a hall-effect sensor that reacts to a magnet moving past. One wire to read.

The "RPM sensor" is typically the same thing, with the pulses from the hall-effect sensor meaning something else. One wire to read.

The temperature sensors need one analog pin each.

So, having removed BHP (there is no sensor for that), torque (no direct sensor for that), and lambda (nowhere near enough information) from the picture, you need an Arduino with 4 inputs - two analog and two digital. Any Arduino would work.

Is it possible to log the data from multiple sensors to the SD on one line of a .csv or .txt file

Of course it is.

How often could I log this data to the SD card.

That depends on how you log it. As binary data, quite fast. As text data, not near as fast. Details matter.

Just one thing to remember about the G sensors, the output varies as the G changes but between 0V and the supply voltage. So if you read the absolute voltage you will need a fixed supply voltage.
If the supply voltage changes then the G voltage will also change slightly
It might be better to also measure the supply voltage and then work out the ratio of the G sensor to the supply voltage. ie
G sensorvolts/ supply volts.
This will make the G reading more reliable.

David0072:
It might be better to also measure the supply voltage and then work out the ratio of the G sensor to the supply voltage. ie
G sensorvolts/ supply volts.
This will make the G reading more reliable.

Hi Dave, thats a great idea and sounds good to me:

So if I monitor the supply voltage (SV) I could use this formula to work out the MAX ADC

((SV/100)*1024)/5

I could then use this as my formula to calculate G

(ADC-(((SV/100)*1024)/5)/2)/(((SV/100)*1024)/5)/6)

Therefore if the supply voltage was 330mV it would look like this

(ADC-337.92)/112.64

and if the supply voltage was 320mV it would look like this

(ADC-327.68)/109.2267

:slight_smile:

So this now begs the question how would I measure the supply voltage? take a feed to another pin somewhere?

Just a quick question Dave, should I expect the supply voltage to fluctuate if I take a feed from the 3v3 ouput from the Uno?

wayne_miller:
OK, So thats the accelerometer sorted

If you're using a single axis accelerometer to measure horizontal acceleration you will need to take account of the pitch changes that occur during the recording. I'm not familiar with sprint bikes but on cars the pitch changes are enough to mess up the results unless they're dealt with correctly.

There are lots of ways to measure and log and calculate power and torque from each other. If you're going to work from vehicle performance then you're dealing with power at the road and your best bet is to measure vehicle acceleration and vehicle speed. This gets you as close as possible to the things that matter i.e. actual performance.

Note that there are two ways of defining speed (whether you include wheel slip or not) and you need to be clear which you're using. If you measure vehicle speed plus slip you are calculating power delivered to the wheel. If you measure vehicle speed ignoring slip then you are calculating power delivered to the road. If you're trying to optimise engine output, you want the former. If you're trying to optimise traction you want the latter.

The 3.3 volts on the Arduino board is supposed to be regulated ie automatically kept at 3.3 volts but like life this will not be perfect. It may be good enough though.

This ratio technique will mean that you are immune to any fluctuations.

It will also allow you to power the g sensor from the main battery or external power supply which could then vary without any problem.

I think the formula for reading the G is:

G = ((Vg/Vsupp)-1/2) * 6

where Vg is the measured voltage from the G sensor (goes from 0 to Vsupp as the G goes from -3G to +3G

Vsupp is the measured supply voltage

I like this Dave

G = ((Vg/Vsupp)-1/2) * 6

However its slightly flawed due the the Vg value not being in volts. The voltage is actually converted by the ardunio from analog to digit 0-1024

I we change it as per below it should work

G = (((Vg*(5/1024))/Vsupp)-1/2) * 6

It definately looks better than my 1st attempt

G = (ADC-(((SV/100)*1024)/5)/2)/(((SV/100)*1024)/5)/6)

The rest of my parts arrive tomorrow so I can start to build and code :slight_smile:

Yes, you are correct. I was just showing what the maths was, you will need to do as you suggest to actually do the maths.

Good luck.

So stoked i came across this thread, i am looking at doing the exact same thing for my 2stroke bike. not a sprint bike, just a daily rider.

W.
i am extremely interested in your build. would you be able to post a list of your hardware?