I’m making a device to water my basil plants. Whilst working on this, I encountered an issue where running the pumps whilst connected to WiFi would crash the microcontroller. After investigation, I found the cause was poor grounding and Electromagnetic Interference (EMI).
Plant watering system #
Previously, I created a plant monitor that tracked soil moisture and sent notifications when the plant needed watering. But wouldn’t it be nice if it could water the plant instead of sending a notification? This new project will do exactly that.
I’m designing the plant watering system to have support for four plants, with a soil moisture sensor and pump for each plant. The pumps will draw water from a water tank, which contains a water level sensor. I’m using an ESP32 microcontroller as the brains, as it comes with Internet connectivity and low-power deep sleeping.
I designed a circuit and then made a prototype on a breadboard, which worked as expected. Making a prototype allows me to find any issues with the circuit design before I bring out the soldering iron. Or, at least, it’s supposed to.
The problem #
I started working on the production version, soldered on to stripboard. Stripboard is a material for making circuits; it comes pre-formed with a grid of holes and parallel strips of copper traces. I use it because it’s an easy way to make semi-permanent circuits for my projects.
I decided to work on the circuit in parts, so I could test the circuit as I went. I started by soldering on the pump circuits and connecting them to the microcontroller. It is at this point that I discovered a big issue - when I ran a pump, the microcontroller would crash. This would result in the pump staying on until power was cut.
Guru Meditation Error: Core 0 panic’ed (IllegalInstruction). Exception was unhandled.
I noticed that if I disconnected the microcontroller from WiFi, the crash would no longer happen.
Investigating the issue #
Power transistor drawing too much current? #
I’m using power transistors to allow the microcontroller to turn the pumps on and off. This is required because the pumps would draw way too much current if powered directly by the microcontroller. I’m using two power supplies. The pumps are powered by a 5V USB plug, the kind commonly used to charge phones. The microcontroller is powered by a micro USB cable to my computer so that I can program and debug it.
At first, I thought that the power transistors were still drawing too much current from the microcontroller and causing the crash. The fact that the crash only happened when the WiFi was running strongly hinted at this, as WiFi requires a lot of current itself. To test this theory, I replaced the transistors with a push button. The microcontroller still crashed, showing this wasn’t the cause.
Adjusted capacitors #
After discussing the issue with a friend, I moved the capacitor closer to the pump and added another, smaller, capacitor. This didn’t fix the issue.
Severed common ground #
At this point, the only connection to the microcontroller was a ground rail. My friend now suspected that the issue might be due to a difference in voltage between the grounds of the two power supplies causing current to flow along the common ground. I severed the ground rail but the issue still happened. This was very strange as there was now no connection at all between the pump and the microcontroller?!
Last hopes #
I decided to create the stripboard again from scratch to make sure it wasn’t a soldering issue. I did this, and the problem still happened.
At this point, I suspected the circuit was either haunted or there was some kind of EM interference. I broke the ground rail closer to the ESP32 and it started working again. It turns out that the ground rail was acting like an antenna. A current was being induced by the noisy pump and caused the ESP32 to crash despite not being connected.
Achieving good grounding #
The lesson here is that stripboards have pretty terrible grounding and Electromagnetic Compatibility (EMC) properties.
Someone on the BPS Space Discord recommended a video on proper grounding in circuits. This was very interesting, I learned a lot from it and it will improve my circuit designs in the future.
While watching that video in a coffee shop, a plant fell on me from a shelf above, covering me in soil. I guess it wanted to teach me the difference between grounding and earthing.
To continue with this project, I have decided to bite the bullet and make a Printed Circuit Board (PCB) for it. I have been looking for an excuse to make a PCB for a while. PCBs allow you to get vastly better grounding, which will avoid EMI issues like this in the future.
Thanks to my friend and people on the BPS Discord for helping me with this issue.
Well, this was certainly an… educational problem to have. This problem, and the switch to making a PCB, has delayed this project by a month at least. But I will learn a lot more and gain more value from this project. I just hope my basil can survive in the meantime.