Motorcycle Tachometer (rpm)

Hi everyone,

I'm actually building a dashboard for my 2 stroke 20 years old motorcycle.

The sensors on this bike for the RPM & Speed or mechanical.

What I'm trying to do is to get the signal from the primary ignition coil, exactly like in that post: https://forum.arduino.cc/index.php?topic=388852.15

Here it is my setup: https://i.imgur.com/cL7PFqv.png

Here it is the code I'm using to check what's the signal looks like:

int coilSignal = 2; // coilSignal
volatile byte counts;
unsigned int rpm; //unsigned gives only positive values
unsigned long previoustime;
void count_function()
{
counts++;
}
void setup() {
Serial.begin(9600);
//Intiates Serial communications
attachInterrupt(0, count_function, FALLING); //Interrupts are called on Rise of Input
pinMode(coilSignal, INPUT); //Sets sensor as input
counts= 0;
rpm = 0;
previoustime = 0; //Initialise the values
}

void loop()
{
delay(1000);//Update RPM every second
detachInterrupt(0); //Interrupts are disabled
rpm = 60*1000/(millis() - previoustime)*counts;
previoustime = millis(); //Resets the clock
counts= 0; //Resets the counter
Serial.print("RPM=");
Serial.println(rpm); //Calculated values are displayed
attachInterrupt(0, count_function, FALLING); //Counter restarted
}

But I finally realised that when the bike was running, even when I unplugged the wires from the bike, the serial monitor kept writing values... (up to 1 meter far away from the motorbike) :o

So I tried to find out the problem until I removed all the wires from my Arduino UNO board.

I just plugged one wire on the digital input 2, and even the wire is connected to nowhere, I have values on the monitor.

It seems like the wire plugged into that input is getting some magnetic noises which disturbed all the values I'm trying to get.

I would like to know if I'm missing something and how to solve this problem.

If anyone has a clue about that..

Thank's !

You've just discovered how much EMI an ignition system generates. You may need everything fully shielded,
arduino in metal box, shield cables, shielded box for the display, then you've got a chance of clean signals.

If you don't have suppressed leads (plug leads with a high resistance core) that's the first thing to remedy
though as copper-cored spark leads generate by far the worst interference possible.

Hi thank you very much for the answer ! I'll try to fix that problem following your advices.

I'm just wondering why with this simple code without using interrupt method, I have clear values on the serial monitor, without these kind of noises? I don't really find answers for that.

int tachSignal = 2;
int debounceSignal = 10;
unsigned long lastDebounceSignal;
int rpm;
bool readingSignal;
bool outSignal;


void setup() {
Serial.begin(9600);
pinMode(tachSignal, INPUT);

}

void loop(){

int readingSignal = digitalRead(tachSignal);


if (readingSignal != tachSignal)
{
  lastDebounceSignal = millis(); 
}
 
if  (digitalRead(tachSignal) == LOW)
{

  if (millis() - lastDebounceSignal > debounceSignal)
  {
    lastDebounceSignal = millis();
    outSignal = LOW;
    Serial.print("LOW  ");
  }
   
  }
}

thank you

hi there, well. Eliminating interrupts you control the timing. isnt ? maybe is a good approach to make your own window counting pulses I mean.

there are some articles about noise in optocouplers that you might read. some use a calibration for the "integrator" at the input and others also put a fast diode to ground .
theres capacitance effect if the diode is on a higher voltage than the transistor . i couldnt find the article. ill keep searching.