Yes, I am not as well someone that just find a solution and leave it that way without understanding but in this case the problem is my electronics knowledge is close to 0 (I personally had a feeling that after a resistor the voltage should drop; when nothing worked I started just to experiment with a multimeter in hands; so I discovered that after the resistor the voltage was exactly the same 4.5V and tried what will happen if I put it before the arduino; I am feeling like experimentators 1000 yers ago
I am sure this is pretty simple to calculate anyway.
But the interesting question is where the oscilations come, why after the resistor Arduino sometimes had double interrupts with a delay of just 12-16 micro seconds; and for me - why 100K Ohms? I just tried with 300 K - it is still working. I guess at some point of increase it will start losing the signal so I'd like to know:
How to calculate the right resistor's value, so the signal is still strong for Arduino, while the current is the smaller, so it doesn't mess when going back into Arduino when it is switched off and panic the controller at the same time.
So the scheme was the same all the time:
- I've got the yellow wire of one of the hall sensors from the motor
- soldered it to an unused wire of the pedelec signal to get it out of motor
- in the beginning - just put it in the INT0 of arduino (this is a digital input that can be used to triger interrupts)
- then the only change I did is to add the resistor (the red one)
- all the time I was using the setting "RISING" for the interrupts which should mean that an interrupt should be generated only when the voltage changes from low level (I guess under 2.5V) to high level
Without the resistor the know problems were 3:
- on switched off Arduino, the voltage of the hall sensor dropped to 1.35V and so the MP3 was panicked
- many people told me that it can damage the Arduino as back current goes into it's scheme
- and the strange oscillations - when the current was 4.5V Arduino was generating for some reason 2500-5000 interrupts; even more strange - when the signal from hall sensor was 0V, Arduino generated 200-300,000 interrupts
With the resistor the 3 problems were fixed:
- on switched off Arduino, MP3 now works
- I guess as just a small portion of the current now goes into Arduino it can't be damaged
- oscillations disappeared like with a magic
BUT I discovered new 2 problems:
a) rarely interrupt has been generating not on RISING but when the voltages drops to 0 (i.e. FALLING)
b) rarely when the voltage goes from 0 to 4.5V Arduino generated 2 consecutive interrupts; I measured the time difference and it was 12-16 micro (not milli) seconds
I fixed these by changing the interrupt setting to "CHANGE", so my function is called on any change - that way I fixed problem a), and then I started to measure the time between interrupts and if an interrupt happens too fast (I set it < 1000 microsenods to be sure) I just ignore it.
As a result I am increasing the counter just once per any change of the state of the hall sensor's signal.
Now:
- why the Arduino was generating so much interrupts?
- why the resistor fixed that
- why anyway sometimes there were double interrupts
- why anyway sometimes an interrupt rised on signal drop while it was set to catch the rising signal
- is the 100K resistor OK, or I can/have to replace it with 300 or more K Ohms? And how to decide which is the best?
The connection are those that I have already posted: