I would like to determine the direction of rotation of 2 small DC motors with an ESP32 and ESPHOME as well as the voltage (-9V / 0V /+9V). The two small motors are managed externally by another mechanism (not by the ESP) and their power supply would be connected in parallel to some GPIOs (not directly obviously). I had thought using an INA226 but apparently the wiring to the VCC and GND terminals are fixed and we cannot reverse the wiring (I think I fried an INA226 doing that).
Is there a module (like INAxxx) that can be connected to an ESP and allows this type of measurement to be made?
My project is to find out if the motor power supplies are sufficient (+/- 9V) and to have the ESP perform some actions depending on the direction of rotation.
Electronics is not my field, I might be asking myself stupid questions.
Thank you in advance for your advice.
If you measure the voltage on motor contacts multimeter reading is swapping between +9V and -9V because polarity is swapping. But the voltage is just 9V.
If you measure between the power supply GND and motor contact there is only voltage +9V or 0.
I can’t see from your images where you could most easily connect multimeter to the power supply GND.
Anyway, you can detect the direction just trough simple voltage divider, no need for circuits for negative voltage. But you need to find power supply GND.
You need 2:1 voltage divider, but first you need to find the supply gnd. Not the one that is swapping by the motor controller.
I’m not so familiar with Lego components to even recognize what is the power supply , but power supply GND needs to be connected to Esp GND. Thereon motor contact voltages referred to GND are +9V or 0V, swapping when direction changes. From there with two voltage dividers (one per each pole) you can detect if motor is on or off and what is the direction.
During the transition I get -0.01 for a brief time (less 1 second) I don’t know if this will be a problem on the input GPIOs of the ESP also the -0V without rotation.
If you are using 9V “box” battery for your experiments with motors, may I suggest to replace it with 6AA setup.
9V “box” is good for fire alarms etc, not for high current (like motors) applications.
Your discharged battery’s open circuit voltage of 7.8V can drop to 2.7V when you draw little bit current.
It provides 9V on output, this is the voltage necessary for these Lego motors (Power Function models)
The outputs of my “voltage dividers” are 3V around now
I think it’s good (except the -0.01V during the direction change. I don’t know what the ESP will do with this voltage on a GPIO input).
I start the wiring with the ESP and the ESPHOME script
Honestly, I’m not able to follow your hardware setup.
But if you have voltage levels between 0 and 3, you are good to go.
-0.01 is not a problem, consider it 0.