Hello everyone,
I have a problem with my Arduino Nano. I need to read a frequency (between 260Hz - 5000Hz) which tells my robot which direction it should go. The signal first goes through a LMV358 amplifier. I made a little program to do it. Notice I am not interested in knowing the exact value of the frequency, so I directly convert it in something I can use.
for (int i = 0; i < 10; i++) {
frequency += pulseIn(8, LOW);
}
if (frequency < 2000) {
mDirection = frequency / 10 / 10;
mDirection -= 25;
} else {
mDirection = frequency / 10 / 100;
mDirection -= 7;
}
mDirection *= 5;
frequency = 0;
It works really well, but when I turn the batteries on for my motors (I am using a Pololu DRV8833 motor driver), the program is not working anymore (mDirection always returns -125). Why is this happening and how should I reslove the problem?
PS: The output from the LMV358 is connected to D8 and not D7.
EDIT: I forgot to mention, but when the 9V battery from the arduino is turned off and the 6V from battery from the motors is turned on, the lights on the Arduino are turned on, so the arduino gets power from the 6V.
Thanks in advance.