arduino motorcycle

hi guys! I'm working on a project for my motorbike. i installed an arduino mega on my yamaha tdm 850, i pick up the wheels speeds and the engine speed, and i made a "sensitive" shift lever to make the clutchless shift. i'm also trying to make a traction control, "cutting" an ignition coil if the rear wheel turn faster than the front wheel. it works now, but the signals are very spiky, so i need to smooth them...someone can help me for this? i tried to use the smoothing example in the arduino ide but with no results...i need to smooth the wheels speeds,and the rpm of the engine.
i also need to smooth the sensitive lever sensor, because i used a lighter piezo element, and the output is affected by vibrations.
thanks a lot!! sorry for my probably messy english! ::slight_smile:

1 Like

"smoothing" is mathematically a running average over a fixed number of historical measurements.

A low pass filter might be solution for the vibration issues

hi guys! I'm working on a project for my motorbike. i installed an arduino mega on my yamaha tdm 850, i pick up the wheels speeds and the engine speed, and i made a "sensitive" shift lever to make the clutchless shift. i'm also trying to make a traction control, "cutting" an ignition coil if the rear wheel turn faster than the front wheel. it works now, but the signals are very spiky, so i need to smooth them...someone can help me for this? i tried to use the smoothing example in the arduino ide but with no results...i need to smooth the wheels speeds,and the rpm of the engine.
i also need to smooth the sensitive lever sensor, because i used a lighter piezo element, and the output is affected by vibrations.
thanks a lot!! sorry for my probably messy english!

your english is fine but you might need to explain more. how are you getting the speed and rpm readings? Is it the electrical signals that are spiky or the results inside the arduino? I have run something similar on my motorcycle and i had more trouble with the integer math than the circuits.

how does the "sensitive" shift lever work? You're a bold man to experiment ith traction control!

thanks! this is my setup:
an inductive pick up reads the pinion tooth (42 each wheel turn), the output is alternate, then it is squared by an operational amplifier and sent to an interrupt pin.

the front wheel is monitored by 4 pick up reading the 10 brake disk pivot (with glued magnets) for a total of 40 pulses for 1 turn, and squared like the rear wheel.

the tach signal comes out from the motorcycle tachometer.

i read the 3 interrupts this way:
void tach pulse ++
void loop
if (pulse >= 2){rpm =(60000/(millis()-startime)*pulse) ; startime = millis();pulse = 0;}
if (millis()-startime > 400){rpm = 0;}

obviously for the wheels the values are different
i'm trying to clean all the signals coming out from the motorcycle, so i'm setting up an oscilloscope using the same arduino to scan for electrical noises.
the only way i tried to debug the system is to make a led light when a certain rpm is reached, alternatively for the wheels and the engine speed. the thresold was regulated by a potentiometer.
the shift load cell is inside a home made rod that connect the lever to the engine lever...i opened a piezo lighter and used the piezo element inside it, without the spring mechanism. the piezo metals output a voltage when compressed, so i send it to the analog pin with a 10k pulldown resistor. on the other side it is very sensible at vibrations, so i'm trying to filter that signal too.the clutchless shift is a system that cuts the ignition coils current for a short time, depending on the ride speeds and rpm.in that moment the gears pressure is reduced and the gears can be shifted easily without the use of the clutch.it works great without engine wear.
i also have a 7 segment display showing the gear, but if i don't clean the values it is useless...i use a shift register to pilot it.
the clutchless shift is very nice to use also if i have to make it work properly.
i know this will sound crazy, but i placed a pair of injector right over the carburettors, and throttle position and temperature sensors too!
i want to fuel inject my motorbike, but i want to practice a bit with these "softer" features before that.(i also have to build a camshaft position pickup...)
i'd like to post some pics, but i don't know how!when i click on the "insert image button", it just write into the post...

wow you're ambitious - it's exciting to hear about your project.

I would say start by cleaning up your signal but you'll have to think about your code too. For example, at 3000 rpm there's 20ms between tach pulses. If your loop checks the count just before a pulse vs just after one you would get a big variation in RPM. I would suggest, for the engine at least, you have the interrupt routine accumulate the time for 5 or 10 tach pulses and post that. I don't know what to say about the wheels - I guess accumulate at least enough pulses to get a full revolution and time that.

Your current code might be fine if you're just spinning in the loop and catching all the pulses quickly but if you get delays and stuff in your main line I think you will need to do it differently. You should also disable interrupts while you're reading the values updated by an interrupt routine.

For a while I was doing RPM and speed smoothing in software - just averaging the last reading with the running average - but once I got my math straight I didn't find I needed to do that.

For picking which gear I'm in I found I had to resort to floating point math to track the ratio between engine and wheel rpm and allow for some slack in the calculation. If you think about it, you're trying to determine how many times the engine fires in a wheel revolution. The numbers are small (4 to 12 for my bike) and there's a lot of potential for overlap.

to post pictures, get them up online somewhere like picasa and then post the url of an image (like http:...) between the [...] [/...] tags.

ok i'm trying to show you the pics!
http://picasaweb.google.it/darioland79/FotoRidotte?authkey=Gv1sRgCNOGkbCu2OCvjwE#5426582852307551938
these are the solid state relays that cut the current to the ignition coils...

http://picasaweb.google.it/darioland79/FotoRidotte?authkey=Gv1sRgCNOGkbCu2OCvjwE#5426582893942716130
this is the injectors installment inside the air box...

http://picasaweb.google.it/darioland79/FotoRidotte?authkey=Gv1sRgCNOGkbCu2OCvjwE#5426582877549872626
and this is the final result, tha air box is closed, and these 2 manifolds go right on the carburettors.

http://picasaweb.google.it/darioland79/FotoRidotte?authkey=Gv1sRgCNOGkbCu2OCvjwE#5426582941122272002
this is the sensitive rod, and on its background you can see the aluminum bracket for the pinion pickup

http://picasaweb.google.it/darioland79/FotoRidotte?authkey=Gv1sRgCNOGkbCu2OCvjwE#5426582932958017650
this is the display inside the tachometer...

http://picasaweb.google.it/darioland79/FotoRidotte?authkey=Gv1sRgCNOGkbCu2OCvjwE#5426582924550707650
and this lovely usb b socket to upload sketches without removing anything!
I think I will follow your hint! the only problem these days is that it's very cold to try my sketches riding!! :-/
if I disable interrupts, don't i risk to miss pulses?anyway, i don't use the delay function at all, i only use millis(). thank you for replying!!
and sorry for the way i'm showing the pics...

yay, the words straight math worked great in my mind!
i found the easy way to solve the gear indicator problem
now i count the pulses of the tach and the rear wheel over a 500 millisecond time, then i multiply * 100 the wheel pulses and divide it by the tach pulses. this way i can work only with integers avoiding float values. the sketch runs around 1300 loops per second, but if I enable all the analog sensors readings it slow down to 780...
i'm going to post my sketch, but i want to translate it in english because it's written in italian.

I have some doubts...could somebody help me?
these are the questions:
if i disable interrupts while i do calculation, don't i risk to miss pulses?
i made all the code in the loop function, except the interrupts, if I use many separate functions instead a big one, is the program quicker? are the external functions (outside the loop) ran simoultaneously? thanks a lot!

if i disable interrupts while i do calculation

Try not to perform calculations with interrupts disabled. Try to have as little code as possible with interrupts disabled. What bill2009 said...

You should also disable interrupts while you're reading the values updated by an interrupt routine.

Look for returnCounter1 for an example...
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1261124850/4#4

i made all the code in the loop function, except the interrupts, if I use many separate functions instead a big one, is the program quicker?

No. Slower. Function calls have some overhead.

are the external functions (outside the loop) ran simoultaneously?

Technically, nothing is run simultaneously on an AVR processor. It can only do one thing at a time. There is an illusiion of simultaneous because of interrupts.

The external functions only run simultaneously if they are called by an interrupt service routine.

yay, the words straight math worked great in my mind!
i found the easy way to solve the gear indicator problem
now i count the pulses of the tach and the rear wheel over a 500 millisecond time, then i multiply * 100 the wheel pulses and divide it by the tach pulses. this way i can work only with integers avoiding float values. the sketch runs around 1300 loops per second, but if I enable all the analog sensors readings it slow down to 780...

great work on the math - that's the kind of thing you need to do.

I found it better to track the time for a set number of pulses rather than the number of pulses in a given time - at 10 kph your wheels are only turning a few times a second. I guess you've got a bunch of interrupts per turn of the front wheel but even so...

if i disable interrupts while i do calculation, don't i risk to miss pulses?
i made all the code in the loop function, except the interrupts, if I use many separate functions instead a big one, is the program quicker? are the external functions (outside the loop) ran simoultaneously? thanks a lot!

You only need to disable the interrupts for a microsecond while you copy the variable that the interrupt routine updates to one in your Loop procedure - you won't miss any interrupts since the ISR will run when you reenable them.

Do post your code - I'm going to go look at your pics now.


Boy that's a great display. nicely done!
Her's mine below (just to show the gear).

//-----------------------------rear wheel-----------------------------------//
void rearwheel(){++z;++z1;++zcount;}                                        //
//----------------------------front wheel-----------------------------------//
void frontwheel(){++f;}                                                     //
//---------------------------tach signal------------------------------------//
void tach() {++r;++r1;}                                                     //
//--------------------------------------------------------------------------//

these are the interrupts

//////////////////////////////////////////////////////////////////////////////
//-----------------------------GEAR INDICATOR-------------------------------// 
//////////////////////////////////////////////////////////////////////////////                                                 
 if(z1 >= 200)                                                              // 
 {ratio = (z1*10) / r1;z1 = 0; r1 = 0;}                                     //
neutralpin = digitalRead (7);                                               //
if (neutralpin == LOW) {gear = 0;}                                          //
else{                                                                       //
if ( 35  <=ratio && ratio <=  50 )                                          //
{gear = 1;}                                                                 //
if ( 56  <=ratio && ratio <= 67    )                                        //
{gear = 2;}                                                                 //
if (  68 <=ratio && ratio <=   80)                                          //
{gear = 3;}                                                                 //
if ( 89 <=ratio && ratio <=   90 )                                          //
{gear = 4;}                                                                 //
if (  102 <= ratio && ratio <=117 )                                         //
{gear = 5;}                                                                 //
//if (   <=ratio <=      ) {gear = 6;}                                      //
if (ratio < 30 || ratio > 130) {gear = 11;}}                                //

this is the gear indicator section, where I use the interrupts variables...

//--------------------------TRACTION CONTROL--------------------------------//
//////////////////////////////////////////////////////////////////////////////
//--------------------------SLIP CONDITIONS---------------------------------//
if (z>=20)                                                                  //
 {if (f > 0 && n > 13)                                                      //
 {rpmdiff = (z * 100) / f;}else{rpmdiff = 0;} z = 0; f = 0;}                //                                           
 //y = map (potval,0,1023,0,10000);                                         //
// if (rpmdiff > y && n > 3) {slip = 1;}else {slip = 0;}                    //                                                                                       
if (slip == 1){coil1state = 0;}else{coil1state = 1;}                        //   
//////////////////////////////////////////////////////////////////////////////

i also use variables coming out from interrupts in other places...i can't post the whole code because it's too big...
thanks so much for the help!
I like your instrument! it's very nice for chrome motorbikes!

thanks for posting the code. It's fun to see someone else's work. A couple of things:

  1. Your code and your math look great(except for the bottom part of the gear indicator stuff -maybe you got tired of coding?). The worst I would say is that at low wheel speeds you'll be a slow to notice a gear change and you'll get some bad readings across gear changes - maybe you don't care.
  2. You should declare your z's, f's, and r's as volatile and you should turn off interrupts while you read and reset them. It's as simple as:
{noInterrupts();ratio = (z1*10) / r1;z1 = 0; r1 = 0; interrupts();}

If you don't do this, sooner or later you'll get bad data. It doesn't matter much to the gear indicator but for fuel injection and traction control....

Have you tried it on the bike? Are you still seeing spiky electrical pulses?

thanks for your reply! yes I knew it wasn't the most elegant way to do the gear indicator...i was tired of studying! :slight_smile: this is my first project and I'm learning, I also studied on your sketch of the gear indicator, but sometimes it's very difficult to me to understand someone else sketches, so i tried to make it my own. I'm having great results trying to straighten the math as possible, using integers instead floats ecc. and now It's almost working without filters and rolling averages. The traction control is great in the mudd but these days it's very cold, and I can't try the bike for more than an hour a day...but the clutchless shift is greater! the nice thing, is that the current cut time, is self adjusting depending on the gear and rpm, so you can use it in the city centre or in circuit. the kits you can buy, haven't the self adjusting cut time, so they can only be used at max rpm. now I'm working on the same sketch, for the odometer, but I'trying to find an easy way to save unsigned long values into the arduino eeprom.I want to show the total road and the trip master on a 2 lines lcd, how could i drive it with less pins as possible?can I use shift registers?I have arduino under my seat and I don't want to send too many wires to the dash...

I want to show the total road and the trip master on a 2 lines lcd, how could i drive it with less pins as possible?can I use shift registers?I have arduino under my seat and I don't want to send too many wires to the dash...

I believe there are serial lcd modules you can buy for $20-$25 that would only a few wires.Serial Enabled 16x2 LCD - White on Black 5V - LCD-09395 - SparkFun Electronics is one.

yes that's what i need! is there a library to use that or i just have to use the same serial communication I use to the pc?
It's fun, I added the nointerrupts and interrupts commands to my code and nothing works anymore! ahahaha
I'm going to debug right now...would you like to help me for the electronic injection code?I'd be really pleased!
thanx