I’m building another obstacle avoider/finder based on a few components controlled by an Arduino. I’m calling it QB
QB is a cube shaped (hence the name Cubee) so far fitted with:
- a HC-SR04 sonar distance sensor (which look like eyes),
- two chunky 66mm dia x 25mm wide wheels driven by geared DC mini motors
- a free spinning ball bearing which acts as a sort third wheel and keeps QB level and stable)
- two HC-020K optical switch encoders (1 for the axle of each wheel).
- a ZK-5AD dual DC motor driver module based on the TA6586 IC (Note ZK-5AD is the brand/model name of the module) to drive the two DC motors.
- 2 X 9V polymer ion rechargeable batteries. One for the Arduino Nano and sensors the other to power both the motors.
QB is controlled by an Arduino Nano MCU, mounted on a UNO/Nano prototyping shield that many convenient pin out options. I am aiming for “compact cuteness”. I may add other sensors in the future, but for now I want to be able to program QB to find several objects in say a 3mx3m arena, or to manage its way through a maze.
All of this has been done before and reported severally on YouTube and other forums such as this, but you may have noticed the HC-020K and the ZK-5AD are not common choices among those that have come before me…
I had a lot of trouble with the HC-020K encoder - It turns out that as supplied, they do not provide accurate counts per turn of the motor axle (read: they need to be modified to be of any use). This article explains why Optical Motor Speed Sensors (electroschematics.com). What is more, the discrepancy is different depending on whether the Arduino is powered by USB or by battery, making me think the problem was with the quality of the battery power and this set me on a very long very frustrating chase of wild geese. There are a couple of solutions to the problem described here and there on the internet. The easiest one to implement is to solder a 100nF capacitor between G and OUT on the HC-020K module. A 0.22 micro F capacitor works fine too.
Now for something I still have not solved (seeking your help)
The ZK-5AD driver requires inputs from 4 PWM capable pins on the Arduino Nano (2 for each motor). The only ones that are available to me for this purpose as Pins 5,6,9,10. The trouble is that the two motors spin at different speed even when I send them the same PWM value using the Arduino Analog-write() command the PWM vs Speed response is quite different for each motor too. The difference is large and impossible to compensate for in software. (There is no PWM setting at which the speed of the motors is the same)
I checked the resistance for each motor and both appear to be the same. When I checked the PWM signals coming out of pins 5,6,9,10 all have the same peak to peak voltage (5V), and the same RMS voltage for a given PWM setting but the frequency and width of the pulses on pins 5 and 6 are very different to the frequency and width of the pulses coming out of pins 9 and 10.
Microsoft’s AI bot Co-Pilot says that this is expected behaviour from those pins, that its likely to be causing the speed differences, and that for optimal DC motor control I need to change the Arduino’s internal timers, Timer0 and Timer1 so that the frequency of the PWM signals match and above are above 1 kHz, warning that this will also affect any code that uses functions like delay() and millis().
There are literally dozens of YouTube videos describing similar builds, and I’ve never seen any mention of needing to change the Arduino’s timers. I am hoping that someone here has do this sort of thing before and can confirm:
1- that the differences in frequency on the PWM pulses are the likely causes of for the motor speed differences (Note the PtP and RMS Voltage are the same)
2- That changing the Timers is an appropriate solution,