I have a project constructing a tank with tracks and moveable turret firing a red laser. There is target incorporating a LDR fixed to the tank to record laser hits to the tank. Ambient light levels are determined and whenever the light level rises appreciably above the ambient light then a “hit” on the tank is recorded. The problem is that the LDR readings jump by about 20% whenever the tank is moving (i.e the motors are running drawing current). This increase looks like a laser hit to the tank when it is not.
The Tank is composed of:
- 2-18650 3.7v batteries wired in series delivering 7.5v
- 2-32GB-520 6-12v motors for tracks.
- 2-MG90S servo motors for the turret
- L293D 16-pin IC Stepper Motor Driver Controller
- LDR Photo Light Sensitive Resistor Photoelectric Photoresistor w/ 10k ohm resistor
- L7805CV Voltage Regulator 5V
- ESP-32
The ESP-32 and the L293D run on 5V from the L7805. The motors operate on the full 7.5v battery pack. The LDR operates from the 3.3v pin on the ESP-32.
The tank draws 165mv when on and not moving. It can draw up to 450-500 mv when moving full speed. Ambient light levels generate ~1.6v under no motor load but when the motors are running the light level immediately jumps to ~2v.
This effect occurs regardless of adding 50Uf capacitors to the in/out pins of the 5v regulator. I have also tried powering the LDR with a completely separate power source so only the common ground and the LDR signal are involved.
I can provide fritzing if someone has any thoughts that could help.
Thanks
SacCha
Hi.
The analog reading of the ESP32 is not the most accurate and there are several issues reported if you search on forums.
With that said, it may be necessary to try to use different GPIOs for the LDR to see it it gets better.
Another alternative is to use an analog to digital converter to get more accurate analog readings from the LDR. These usually communicate via I2C communication protocol. One example is the ADS1115 module (at the moment, we don’t have a tutorial about it).
You can also try to use another method to measure the light, like the BH1750 Ambient Light Sensor: https://randomnerdtutorials.com/esp32-bh1750-ambient-light-sensor/
I hope this helps.
Regards,
Sara