Accurate low voltage measurement using an ESP32 microcontroller

Thread Starter

madnordski

Joined Dec 16, 2025
10
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.
GPT_Schematic04.png
 

WBahn

Joined Mar 31, 2012
32,703
Just looking at the schematic at a glance makes me question whether there is any chance of it being useful. It looks more like something that a sixth grader that has a few schematics lying around might come up with as part of a sci-fi story (i.e., something where they just need some technobabble to impress the casual reader).

Note that both inputs of the MCP6002 are grounded. And that D3 is shorted. And that it wants you to use a 10 nnF, or 10x10^-18 F capacitor. Or that R is 1.65 v.Ω. Or that the "Hot Track" signal is completely blocked by the 3.3 V power on the other side of R_SIRES. Or a number of other things. It's garbage. Pure meaningless AI slop.

So let's take a step back and try to help you solve the problem instead of trying to interpret and patch what is effectively a random circuit.

Before we can possibly help you devise something that is good enough, we have to know what good enough means for your application.

You say, "The main challenge is making the voltage reading precise and sensitive enough that it can be used to detect dirty track segments."

Okay, so what is required for a voltage reading to be precise and sensitive enough so that it can be used to detect dirty track segments?

What is the range of voltages that the circuit might encounter?

How do dirty track segments present themselves? Since an electrical signal requires two contacts, couldn't the "dirty" part be in either of the rails, not just the "hot" rail?
 

Thread Starter

madnordski

Joined Dec 16, 2025
10
Just looking at the schematic ...
The input voltage range is 0 to 16 volts A/C. I intentionally left the typical ChatGPT mistakes like nn10 instead of 10 nF and hoped readers would focus on my questions. You verified the D2 and D3 are wrong and I figure one needs to go to ground and the other to 3.3v to work as a clamp. You raised a really good question regarding the fluctuating conductivity of the return rail. How does that impact the measurement?
 

panic mode

Joined Oct 10, 2011
4,864
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.
1765924461363.png

1765924651752.png
 

MisterBill2

Joined Jan 23, 2018
27,164
An interesting challenge here. So I start with the basic guess that the track voltage is variable and that the zero to 16 volts are used to directly control the train speed. That is important because some model RR schemes us a constant track voltage.
The next guess is that for checking the speed will be held "reasonably constant", meaning no intentional changes in the voltage.
The third guess is that the track voltage will be powering the WebBLE telemetry package somehow, so a second voltage output for that is required.
This means that the checking system needs to draw some constant current from one set of pickups while monitoring for small voltage changes. The second requirement is totally separate, which is to provide a regulated voltage for the WebBLE package.
Checking the track is fairly simple, it only requires an amplifier with a DC isolated low frequency high gain. That amplifier will feed a voltage controlled oscillator that sends a stable frequency to the telemetry section. So any rapid change in voltage indicates dirt on the tracks.
 

crutschow

Joined Mar 14, 2008
38,316
You will probably not see much change in track voltage since the voltage source is likely quite stiff (little change with current), so the best way to detect a varying track resistance would likely be to measure the track current, which should show a larger variation.
That can be done by inserting a small resistance is series with the ground return from the track, and measuring the voltage across that.
Alternately you could use a Hall-effect current sensor which requires no series resistor, although it may be a problem finding one with sufficient sensitivity.
Since you want to use a small resistance to get a low voltage drop (if using the resistor) so as not to interfere significantly with the track voltage, you will probably want to add an op amp to amplify the voltage before going to the A/D.
 
Last edited:

MisterBill2

Joined Jan 23, 2018
27,164
The TS is looking for voltage drops caused by dust on the tracks. I got that out of the first post. It happens on slot-car tracks also. It reduces the contact area, thus dropping the voltage SOME.
What make sensing the voltage drop a lot harder is that the track is powered with AC, instead of DC. From the description this is not an HO size train track, but the larger size track.The challenge will be sensing momentary fractional volt changes, that happen rapidly on an AC voltage. The checking scheme will need to draw a bit of current because without some current there will be no voltage drop caused by the resistance. Besides that, the power is rather noisey because the main load is a heavily loaded, five segment commutator, series wound, low speed motor.
The result is that the electronics package will possibly need a separate pickup arrangement, along with power filtering and regulation.
 
Last edited:

crutschow

Joined Mar 14, 2008
38,316
thus dropping the voltage SOME.
But that voltage drop is to the train motor, not the tracks.

I would think there is negligible difference to the track voltage, that's why I suggested measuring current, since if the voltage drop is enough to noticeable slow the train, then that should also cause a measurable current drop.
 

MisterBill2

Joined Jan 23, 2018
27,164
To get a voltage that is not really noisy, and not affected by the load on the drive motor,,it needs physically distant connection points.
The TS did state that it wa going to be a train car.
 

Ian0

Joined Aug 7, 2020
13,097
Dirty tracks will cause resistance in the supply to the engine and the current will fall. If the car is monitoring voltage on the track behind the train, measuring the track voltage, not the motor voltage, the falling of the current to the motor will cause the voltage on the track to rise.
 

MisterBill2

Joined Jan 23, 2018
27,164
Dirty tracks will cause resistance in the supply to the engine and the current will fall. If the car is monitoring voltage on the track behind the train, measuring the track voltage, not the motor voltage, the falling of the current to the motor will cause the voltage on the track to rise.
It is possible that such variations in the track voltage could exist, but they would vary with the distance from the voltage supply.
 

Reloadron

Joined Jan 15, 2015
7,855
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.
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
 

MisterBill2

Joined Jan 23, 2018
27,164
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.
 

MisterBill2

Joined Jan 23, 2018
27,164
My experience with variable voltage controlled AC powered electric trains is that the voltage drop on the track is not enough to change the speed. So while it might show up on a 4 1/2digit voltmeter it will not be a problem for the TS application purpose. Dust on the tracks leads to short intermittent slowdowns.
My suggestion for monitoring would be to have the sensed voltage control an audio oscillator to amplifier to small speaker string. Then any momentary change would be immediately obvious to anybody watching the trail roll along. Just a suggestion.
 

GetDeviceInfo

Joined Jun 7, 2009
2,270
A consideration might be to take some on-board power, convert to a constant current, and drive that over another set of wheels, even if it’s s following car. With that reference you would then have a variable voltage to convert.
 

MisterBill2

Joined Jan 23, 2018
27,164
I understand the problem. When the steel track plating wears off the surface gets a tiny bit rough and dust sticks. AND if you have a large layout with all of the buildings and tunnels and stuff and don't run it often then the tracks get dusty and quite challenging to clean. Mine has all been packed away in a crate since about 1965. But I recall it fondly.
A track cleaner with a motorized buffing wheel could be an interesting possibility indeed.
 
Top