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 !