Accurate low voltage measurement using an ESP32 microcontroller

Thread Starter

madnordski

Joined Dec 16, 2025
10
Thanks for the great replies! I've run some test circuits to make sure the values are safe and effective. As for reporting, I like to use WebBLE for these type of projects. Creating a track cleaning car/engine is a great next project. My questions regarding the clamp diodes and ground have been answered, so thanks all. Thanks also for the great suggestions. When all is done, I'll post pictures and code to my github page (https://github.com/madnordski) for the curious.

Sorry to all those that just skipped right to the schematic -- yes, IA is not good at creating schematics or almost any technical drawing. Believe it or not, it's hugely improved from a year ago. This time next year, it might actually be good at it.
 

Thread Starter

madnordski

Joined Dec 16, 2025
10
Measuring the voltage drop is the purpose of the project. The track voltage to power the instrumentation will need to be from a second pickup set, and be rectified and filtered and regulated. The AC track voltage will also need to go thru a "precision rectifier" to provide a DC signal for the telemetry system.
I'm doing half-wave rectification. From that, I can calculate RMS volts and peak volts, of course. I have an ESP32 with a small display so it might also be fun to reconstruct the wave and display it.
what is producing this 16VAC signal?
clamping diodes D2 and D3 are not just useless, they are wired incorrectly and in wrong place.
ADS already has internal diodes for this as shown in the datasheet. the same arrangement of clamping diodes should be at the input to MCP... and the MCP datasheet shows you how.
View attachment 360670

View attachment 360671
Thanks. I finally read that and saw the same thing.
 

Thread Starter

madnordski

Joined Dec 16, 2025
10
Is it really AC? It's half a century since I had a train set, and then it was DC, positive to make it go forwards, and negative to make it go backwards.
Yes, this is vintage post-war layout. Equipment ranges from the 1940's to 1990's, the lovely ZW A/C transformer is from the 1950's.
 

Thread Starter

madnordski

Joined Dec 16, 2025
10
OK and has been well pointed out the schematic is garbage. That said while I have never used an ESP 32 I have used quite a few ESP 8266 versions along with a ADS 1115 module. The idea being to get an accurate measurement of voltage. I will assume that you have a home network. The ADS 1115 will give you 15 bit data, even though it says 16 bit one bit is for polarity sign. Use the ADS 1115 in a differential mode. You will likely want to power your ESP and ADS 1115 modules from a battery onboard in your car. Keep in mind that between car wheels and track you may see some loss. A Google of ESP 32 and ADS 1115 should yield plenty of circuits for measuring AC voltage using an ADS 1115 and ESP 32 or ESP 8266. You will also find plenty of code samples for your ESP. Again you will need a home WiFi network to link to. This link may help. Also the ADS 1115 data sheet.

Ron
I'm much more comfortable writing code than I am with circuits. I like using WebBLE for such projects which eliminates the need for WiFi. Mostly, however, it's easy create and app-like program for you phone using WebBLE. FYI: most ESP32's these days come with both WiFi and some flavor of Bluetooth onboard.
 

Thread Starter

madnordski

Joined Dec 16, 2025
10
Measuring the voltage drop is the purpose of the project. The track voltage to power the instrumentation will need to be from a second pickup set, and be rectified and filtered and regulated. The AC track voltage will also need to go thru a "precision rectifier" to provide a DC signal for the telemetry system.
I'm going to battery power the instrumentation. The half-wave rectification is for the signal being measured (I was unclear in a different reply). FYI: on a conventional Lionel layout such as this, if you power your instrumentation from the track, you'll also need to use a super-capacitor to keep MCU from shutting down every time your train changes direction or comes to a stop. This layout is old-school with MCU powered accessories, monitoring and some control.
 

MisterBill2

Joined Jan 23, 2018
27,552
I was thinking that the setup had to be Lionel! I recall the dusty tracks problem as well. Then I got older and the train set was carefully packed up, crated, and put away. But recollections remain.
Certainly all of the narrow track, HO scale models did use DC power and polarity reversal for direction control. So they must have also used PM DC motors, or a bridge rectifier for the field current. I never investigated one of those tiny engines, because I never had one.

"American Flyer" used a two rail system, I am not sure how it controlled direction. But the two systems were totally incompatible, which was obviously to avoid serious competition. Probably it harmed both companies in the long term.
 

Futurist

Joined Apr 8, 2025
763
I'm creating a car for train layout that will read and transmit the track voltage via WebBLE. The main challenge is making the voltage reading precise and sensitive enough that it can be used to detect dirty track segments. There are number of reasons to rule out hall effect sensors that we don't need to go into here. For other reasons, a 1:1 transformer has been ruled out for isolation. My circuit design skills are primitive so I turned to ChatGPT as a way to start thinking about it. To my surprise, after several iterations, it did come up with a schematic. The approach it used was to shift the signal instead of rectifying it. The circuit also uses a more accurate A/D than the one on the esp32. The voltage range of interest is 0 to 16 volts A/C. Despite the typos, I can follow most of the schematic. Here are the two most confusing parts (for me at least). 1. I think the role of the D2 and D3 (Schockty) are supposed to be clamp circuit -- are these correctly wired? 2. Since there's no isolation, ground must be carefully considered. Here my confusion is regarding Track_Ref/Digital_Gnd -- is this just where Track Return and Gnd are connected together? You will find other misspelled and confusing things in this diagram but I think I'm okay with these.
View attachment 360668
What trains? public transport? industrial? model trains? toys? You've said far too little about the actual problem domain. Model trains are speed controlled using PWM not variable voltage.

Why is this even needed? just wipe the tracks periodically if this is a model we're talking about.
 

Thread Starter

madnordski

Joined Dec 16, 2025
10
The project has been completed and works great. It delivers voltage readings from the Lionel toy train track directly to my phone. It is especially useful for comparing voltages from different places on the track. It's already helped me identify a section of track that needs attention. Photos: 1) programming the ESP32; 2) Screenshot of the WebBLE phone App in use; 3) Actual schematic. All the code is available on my GitHub page: https://github.com/madnordski/WebBLE-Apps/tree/main (relevant files start with TrackVoltageCar...) Should we recap? A/C (0 to 20 v) -> voltage divider -> half-wave rectifier -> ADC (ADS1115) -> XIAO ESP32-C3 ===> reports over BLE to WebBLE phone App.

TrackVoltageCar_programmingSM.jpgTrackVoltageCarAppSM.jpgschematic.png
 

MisterBill2

Joined Jan 23, 2018
27,552
I had thought of another concept, having an oscillator with an amplifier and small speaker in the monitor car, with the oscillator frequency controlled by the track voltage. That would reveal the voltage variations as you watched the train travel along the track. Of course, that would require being able to see all of the track to observe where the weak spots were.
 

Thread Starter

madnordski

Joined Dec 16, 2025
10
Posting just to celebrate! The Track Voltage Car helped me identify a track section that was just too far the transformer to be served well using 18 gauge wire. I just finished replacing these runs with 14 gauge (hard work btw) and now my train runs the entire layout a one slow transformer setting without slowing down or stalling out as it did before. Awesome! This was a fun project but in the end the tool itself isn't generally useful. In my case, the section was hard to reach but if not, a DMM will give a more accurate readings. The car connects to the track using a roller and wheels and this introduces variability. Surprisingly, and perhaps for that reason, it was more informative to compare moving voltages and than stopping to sample voltage readings. And yes, if you've followed this correctly, the math confirms the observation, so yes, it's my fault for not doing the math before installing the wire. At least I did it before ordering the replacement wire! ;^)
 

MisterBill2

Joined Jan 23, 2018
27,552
Posting just to celebrate! The Track Voltage Car helped me identify a track section that was just too far the transformer to be served well using 18 gauge wire. I just finished replacing these runs with 14 gauge (hard work btw) and now my train runs the entire layout a one slow transformer setting without slowing down or stalling out as it did before. Awesome! This was a fun project but in the end the tool itself isn't generally useful. In my case, the section was hard to reach but if not, a DMM will give a more accurate readings. The car connects to the track using a roller and wheels and this introduces variability. Surprisingly, and perhaps for that reason, it was more informative to compare moving voltages and than stopping to sample voltage readings. And yes, if you've followed this correctly, the math confirms the observation, so yes, it's my fault for not doing the math before installing the wire. At least I did it before ordering the replacement wire! ;^)
OK, your track layout must be much larger than any of mine have been. I don't recall ever using wire that was larger than #18.

AND CERTAINLY you would not ever measure a voltage drop without a load drawing current from that track segment. That part is basic ohms law.

Thanks for letting us know the results of our advice. THAT is always welcome here.
 
Top