Monday, January25, 2021
Privacy Policy

Circuit Design for ESP32 Interface

Input Interfaces

Measuring 12 volt signals

There are several 12 volt signals we want to detect. The goal here is are the signals there or not. Is the pump running, is the main power switch on. We are not trying to measure the voltage, just see if they are on or off. The input voltage to the ESP32 needs to be below 3.3 volts or it will be destroyed so we need a way to interface to go from something in the 10 to 14 volt range to a logic level of high (3.3 volts) or low (ground). I did that with a switching transistor. These transistors cost 15 cents and the resistors are 5 cents so this is not an expensive circuit. The resistor R8 will supply enough current from a 12 volt signal to drive the transistor into saturation, in other words, switch on. The resistor R18 makes sure that a small glitch will not turn on the transistor. The pull up resistor R14 is only necessary for the input that is used to wake the ESP from sleep. For an input that is just being read after the unit is awake, the ESP input can be set to use an internal pull up. But these do not work with the unit sleeping so in that case an external resistor is required.

Measuring voltage

This circuit, and some of the software, is all about overcoming the limitations of the ESP32 ADC function. The most obvious limitation is that the input needs to be less than 3.3 volts. This circuit will divide the input voltage by exactly a factor of 5. That will allow measurements up to 16.5 volts. The next limitation is noise. The ADC is extremely noisy. The capacitor helps with filtering external noise but there is noise that comes from the circuit itself. Also, we are trying to measure fractions of a volt. A battery is basically dead at 12 volts and fully charged at 12.6 so the entire range of what we are trying to measure is under 4% of the measurement range. To get a valid reading I employed several strategies. Simple averaging was not going to work because the noise was not gaussian as there were random spikes that needed to be rejected. The lowest level reading takes 8 readings and tosses the highest and lowest and divides by 6. Then 100 of these readings are taken and averaged. In total I average 600 readings and ignore 200. This produces a very stable reading but it is still not very accurate.

It isn't accurate because the ADC is notoriously non linear. I took readings at various points in the region I cared about and did a third order curve fit. Finally there is a gain term as there is also variation unit to unit and I have three units so I can swap out one and program it at home. This gain term will adjust the reading so they are right at one point, which I set to be the most important point. With the linearization, they are very close over the entire range I care about.

Controlling the relay

I used more transistors to switch the relays. A simple 1,000 ohm resistor is used to limit the current into the base. The coil current is 23mA and we want about 2.3mA into the base. The 1K resistor gives 2.6mA which is fine. The transistor drives the relay coil to ground with the other end connected to the battery. The specifications on the relay allow 8.4 to 19.2 volts which is more than enough tolerance. The ESP32 only needs to supply current for 20mS so this is not a big drain on the battery. The relays I used are rated at 10Amps, more than enough. The fan has a 1 Amp fuse and the small pump a 5 Amp fuse. As I said, these are latching relays so there is an input to close the relay and one to open it and power does not need to be applied except to change the state. Lifetime on these relays operated once a day would be 500 years.


Cookie Policy:
This website uses cookies to save your settings. No personal information is saved. I do not collect statistics on your visit. You can disable cookies in your browser if you like but it is not recommended for this site. I do not sell cookies. Go to a bakery for that. In fact I do not sell anything. To disable cookies from, please refer to the Help button in your browser.
Privacy Policy:
I do not sell or share any user data or anything else for that matter. The only personal information I save is in the site log which has a line for each page view which includes the IP address your browser sends in the header as well as which page you requested. I use this to block hackers and other bad actors. I do not use this raw data to create profiles on users. I periodically delete the log files. Google supplies the ads on this site. Because I do not track who you are, I cannot customize how these ads are served. They may be personalized to improve the ad experience. If you do not want personalized ads, please adjust the settings on the Google site HERE. NOTE: The best I can determine, this site is not subject to CCPA but I am doing my best to comply anyway.
The information on this web site has not been checked for accuracy. It is for entertainment purposes only and should be independently verified before using for any other reason. There are five sources. 1) Documents and manuals from a variety of sources. These have not been checked for accuracy and in many cases have not even been read by anyone associated with I have no idea of they are useful or accurate, I leave that to the reader. 2) Articles others have written and submitted. If you have questions on these, please contact the author. 3) Articles that represent my personal opinions. These are intended to promote thought and for entertainment. These are not intended to be fact, they are my opinions. 4) Small programs that generate result presented on a web page. Like any computer program, these may and in some cases do have errors. Almost all of these also make simplifying assumptions so they are not totally accurate even if there are no errors. Please verify all results. 5) Weather information is from numerous of sources and is presented automatically. It is not checked for accuracy either by anyone at or by the source which is typically the US Government. See the NOAA web site for their disclaimer. Finally, tide and current data on this site is from 2007 and 2008 data bases, which may contain even older data. Changes in harbors due to building or dredging change tides and currents and for that reason many of the locations presented are no longer supported by newer data bases. For example, there is very little tidal current data in newer data bases so current data is likely wrong to some extent. This data is NOT FOR NAVIGATION. See the XTide disclaimer for details. In addition, tide and current are influenced by storms, river flow, and other factors beyond the ability of any predictive program.