Better AC sensing circuit for ADC conversion

MrChips

Joined Oct 2, 2009
34,854
Your response should be to the point.
If you don't want to respond its good sometime. If I were you, I will just avoid things that is Hard. Let's say you have 40+ years experience but it's should not be click always
When you are the one seeking help, try not to be critical of the replies you receive. If you are not happy with a member's response, use the Report button instead of criticizing the member in the open. Let the AAC moderators handle it.
 

madnordski

Joined Dec 16, 2025
10
The ADC on the board isn't great and susceptible to noise from nearby components (not so sure about the Uno but ESP32's definitely suffer from this). In your case, you might not need to be as accurate as was needed for a project I recently completed. In my case, I'm reading 0 - 20 volt A/C but the basics are the same. I found no need to sample both sides of the A/C cycle so instead of raising the sine wave, I used half-wave rectification. I also recommend clamping the input to protect your UNO. Consequently, I'm recommending (but no pushing), the following:

1. Use ADS1115 or similar for your ADC, especially if you want a more accurate readings (it will work with the Uno).
2. Instead of assuming your A/C is in range and raising the signal so that it's all positive, just use half-wave rectification (schematic below). Now you're assuming the sine wave is symmetrical, so be sure that assumption is compatible with your application.

SCHEMATIC:
https://github.com/madnordski/WebBLE-Apps/blob/main/TrackVoltageCar_schematic.png

The circuit is in-use and already paid off! By using the Track Voltage Car on my Lionel Layout I was able to tell the train was slowing down not because of the tight dog-bone curve but because of a voltage drop, resulting from the distance of this section from the transformer. I replaced the 18 gauge run with 14 gauge wire and now my train runs at a nice slow speed around the entire layout without touching the throttle. It's awesome! It was fun to build this too but if you can easily reach reach all of your track sections, use a DMM instead. It's more accurate because the electrical connection the train care makes to the track adds variability.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
The ADC on the board isn't great and susceptible to noise from nearby components (not so sure about the Uno but ESP32's definitely suffer from this). In your case, you might not need to be as accurate as was needed for a project I recently completed. In my case, I'm reading 0 - 20 volt A/C but the basics are the same. I found no need to sample both sides of the A/C cycle so instead of raising the sine wave, I used half-wave rectification. I also recommend clamping the input to protect your UNO. Consequently, I'm recommending (but no pushing), the following:

1. Use ADS1115 or similar for your ADC, especially if you want a more accurate readings (it will work with the Uno).
2. Instead of assuming your A/C is in range and raising the signal so that it's all positive, just use half-wave rectification (schematic below). Now you're assuming the sine wave is symmetrical, so be sure that assumption is compatible with your application.

SCHEMATIC:
https://github.com/madnordski/WebBLE-Apps/blob/main/TrackVoltageCar_schematic.png

The circuit is in-use and already paid off! By using the Track Voltage Car on my Lionel Layout I was able to tell the train was slowing down not because of the tight dog-bone curve but because of a voltage drop, resulting from the distance of this section from the transformer. I replaced the 18 gauge run with 14 gauge wire and now my train runs at a nice slow speed around the entire layout without touching the throttle. It's awesome! It was fun to build this too but if you can easily reach reach all of your track sections, use a DMM instead. It's more accurate because the electrical connection the train care makes to the track adds variability.
@madnordski thank you for such good suggestions. It's in the track may be. Yes, I had another circuit with only half wave rectifier. Lets try again, I have not implemented true RMS sampling code to main code. Can you find in this thread?
 

drjohsmith

Joined Dec 13, 2021
1,613
yup, Arduino ADCs are also rather noisy.
luckily , the adc can over sample a lot, and using the running low pass filter , as otheres have recomended, the noise of the adc is reduced, as well as increasing accuracy
it all depends what actual resolution the OP needs, they mentioned "8 bits" , i.e around 1v resolution in 250v.
oversampling will increse this to 10 or so bits, so around 1/4 volts resolution in 250.
to me thst sounds excesivly over complex for their application, we dont know what output voltage steps the auto transformer has ,
If transformer had 16 taps as the OP wants, Im guessing around 10v per step at most, so meassuring input to 1/4 volts accuracy seems excesive ,
but we await the op making a statment as to intent.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
for me threads with too many replies are a red flag. usually this means problem is not stated clearly and concisely. an XY problem...

and yes, this thread is precisely that... discussion is all over the place and goal posts are constantly shifting - from reading AC voltage to calculating RMS to controlling dozens of relays....

there is never mention of type of power transformer which is at the heart of the problem. there is never mention of desired output voltage tolerance etc.

btw. i may glance the thread but have no time to read everything. i need to manage my time and the same probably applies to other who volunteer their time here. hence i find suggestion to anyone, that they should read 100s of posts simply ridiculous.

one eventually finds out that entire concept is flawed. for example if any part of this system fails, entire system is useless since there is no manual override. a much simpler, cheaper and more flexible system would be self-regulating variac, possibly with a single relay to enable output when voltage is in range. if needed automatic correction can be turned off and in this case variac can be set manually.
I think you did not read the paper that I have posted. That student truly made it before. Kindly read only the thread you have posted here from the beginning.
 
Last edited:

drjohsmith

Joined Dec 13, 2021
1,613
Does your explanation make any positive thoughts about it? If you don't have time just leave it. I think you did not read the paper that I have posted. That student truely made it before. Kindly read only the thread you have posted here from the beginning.
my reply was to panic modes post,
where they were talking about adc noise , and I was highlighting the technical suggestion of bits increasing with oversampling and the filtering action of said , which might mitigate adc noise, thus saving you an external circuit , said costs, complexity and risks of using an external circuit.

you ask about a paper you posted ,
sorry a very long thread, can you remind us as to the paper please.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
luckily , the adc can over sample a lot, and using the running low pass filter , as otheres have recomended, the noise of the adc is reduced, as well as increasing accuracy
it all depends what actual resolution the OP needs, they mentioned "8 bits" , i.e around 1v resolution in 250v.
oversampling will increse this to 10 or so bits, so around 1/4 volts resolution in 250.
to me thst sounds excesivly over complex for their application, we dont know what output voltage steps the auto transformer has ,
If transformer had 16 taps as the OP wants, Im guessing around 10v per step at most, so meassuring input to 1/4 volts accuracy seems excesive ,
but we await the op making a statment as to intent.
Yes, this was also talk before. Are you confused about 8 to 10 bits? 10-bit analog-to-digital converter, which means it can represent analog signals with digital values from 0 to 1023. This range of possible values is known as its resolution, and it tells you how many distinct levels the converter can output for the given analog input range. Digital Output value Calculation for this application, ADC Resolution = Vref / (2 to the power n) − 1) .
Now you calculate it for 8 taps, lets use 8 relays.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
my reply was to panic modes post,
where they were talking about adc noise , and I was highlighting the technical suggestion of bits increasing with oversampling and the filtering action of said , which might mitigate adc noise, thus saving you an external circuit , said costs, complexity and risks of using an external circuit.

you ask about a paper you posted ,
sorry a very long thread, can you remind us as to the paper please.
see post #87
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
When you are the one seeking help, try not to be critical of the replies you receive. If you are not happy with a member's response, use the Report button instead of criticizing the member in the open. Let the AAC moderators handle it.
@MrChips, cool down please. Everybody here is young learner, we respect each other. I am sorry if anything hurts you!
 

drjohsmith

Joined Dec 13, 2021
1,613
Yes, this was also talk before. Are you confused about 8 to 10 bits? 10-bit analog-to-digital converter, which means it can represent analog signals with digital values from 0 to 1023. This range of possible values is known as its resolution, and it tells you how many distinct levels the converter can output for the given analog input range. Digital Output value Calculation for this application, ADC Resolution = Vref / (2 to the power n) − 1) .
Now you calculate it for 8 taps, lets use 8 relays.
im sorry , I cant find quiet what your asking here .
Are you teaching me about adcs and bits ?
thank you for that, in past I have designed ADC chips , so I think I get about bits, over sampling etc.
 

MrAl

Joined Jun 17, 2014
13,716
@MrAI, If you have time kindly read this full thread. See the reference code, sampling parameter is already defined.
Hi there,

Ok, I'll read though 7 pages of this thread to find a parameter that is not even the one I need to know :)

What I really need to know is the minimum sampling interval. That tells us what we can do and not do. If it was 60 seconds we have more options than if it was 60 milliseconds.
Also, the ADC resolution in bits, like 8 bits, 10 bits, 12 bits, etc.

Do you know how to average in uC code?
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
im sorry , I cant find quiet what your asking here .
Are you teaching me about adcs and bits ?
thank you for that, in past I have designed ADC chips , so I think I get about bits, over sampling etc.
I don't have much qualifications to teach you. May be you were thinking about 1V ADC , and I explained in 5V resolution OK, you are then ASIC expert . If I use 16 relays then 8 or 10 bits are not enough you mean ? Some one said to use low pass filter in code.
 

Thread Starter

Hasan2019

Joined Sep 5, 2019
199
Hi there,

Ok, I'll read though 7 pages of this thread to find a parameter that is not even the one I need to know :)

What I really need to know is the minimum sampling interval. That tells us what we can do and not do. If it was 60 seconds we have more options than if it was 60 milliseconds.
Also, the ADC resolution in bits, like 8 bits, 10 bits, 12 bits, etc.

Do you know how to average in uC code?
Does Arduino Uno occupied with 100 bits resolutions?
 

drjohsmith

Joined Dec 13, 2021
1,613
I don't have much qualifications to teach you. May be you were thinking about 1V ADC , and I explained in 5V resolution OK, you are then ASIC expert . If I use 16 relays then 8 or 10 bits are not enough you mean ? Some one said to use low pass filter in code.
I think I get you.
look at the output first. you have 250 volts AC.
what are the steps you have on the auto transformer ?
if you have say 10 volts between taps on the output , then the most you need is to resolve the input to say 5v.
The number of relays is irrelivant,

if you only need to detect within 5v , then the number of levels you need in the ADC is 250 / 5, i.e 50 levels.
a 6 bit ADC would give you the resolution you need , with spare.

hence the reason a few of us have been asking, but not getting answeres to

a) what are the voltage steps on the auto transforner you want to use ? this sets the ADC resolution needed.

b) how often do you wish to switch the relays ?
this sets do you need relays or solid state solution

get on back to this please with clear answeres .
 

drjohsmith

Joined Dec 13, 2021
1,613
Does Arduino Uno occupied with 100 bits resolutions?
what do you mean by 100 bit resolution ?
do you mean the adc ?
100 bit resplution is 7 bits adc.
check, but most arduino has a 8 bit ADC ,
this is oversampled the input, adding an extra bit for each 4 times over sampling.
so your 50 Hz is sampled at 16 times, then you gain two extra bits .
 

panic mode

Joined Oct 10, 2011
5,012
I think you did not read the paper that I have posted.
actually i did... but i should not have to - why would anyone bother reading 87 posts to finally get to important tidbit. this should have been mentioned in posts 1-3.

That student truly made it before.
i have no doubt. device is rather simple. the biggest problem was winding that custom transformer. i have done that twice in my life and that was enough for me. so i would rather use variac - you get smooth transition just by rotating knob. and a servo can do that.

Kindly read only the thread you have posted here from the beginning.
lol....not this again... :D

what is it that you are trying to do? if you want to build it - circuit is shown.

the thread name suggests that you are looking for "better AC sensing" but part that is not clear is - better how. speed? resolution? noise? linearity? what version of Arduino UNO you have? i have several, R4 has 14-bit ADCs if i remember correctly.

if you have 16 relays, 4 bits are enough.

voltage sensing in original circuit was this. what is it that you need to improve?
1768414417374.png
 

Ian0

Joined Aug 7, 2020
13,158
I think you did not read the paper that I have posted. That student truly made it before. Kindly read only the thread you have posted here from the beginning.
Looks like a bit of a hobbyist project disguised as a scientific paper. What’s this nonsense about the processor calibrating the voltage divider? And removing the harmonics from DC with a capacitor? It seems like he has seen the term “buck boost” transformer before but doesn’t quite know what it does, so decides not to use it even though it would be advantageous in this system.
But the main point is that there is no rms measurement whatsoever. It is just scaled from the peak. Waveform distortion will not be detected.
 
Top