AC/DC Converter - What's happening with the voltage?

Thread Starter

Joe Martin

Joined Jan 6, 2017
13
I'm trying to power my board from a 120Vac power supply. The project box has to be small and there are 120Vac relays inside the box, so having an external ac/dc power supply doesn't fit my use case. I purchased a PSK-S5B-T ac/dc adapter. because I'm inexperienced and my research has told me making my own power circuit is a good way to burn down my house. The datasheet for this can be found at https://www.cui.com/product/resource/psk-s5b-t.pdf.

I was running into power issues. I tested the DC side of the ac/dc adapter with a relatively inexpensive multimeter and it showed 4.99v (which is well within tolerance for my board.) I created a simple circuit using an Arduino UNO analog pin to test the voltage (see attached schematic.) I couldn't find a part for the PSK-S5B-T so it's represented by a transformer symbol. The A0 pin reads all over the place from 1023 to 0. If I average the voltage readings over a few seconds, I get ~0. I've googled and read and experimented for over a week now, but I'm stuck. I tried a bridge rectifier, but this didn't solve the issue either. Can someone point me in the right direction?
 

Attachments

dl324

Joined Mar 30, 2015
16,839
Welcome to AAC!

Please post a picture of your schematic and/or tell us what schematic editor you're using.

It might also help if you posted the relevant portion of your code.
 

LesJones

Joined Jan 8, 2017
4,174
What do expect if you use a transformer instead of a DC power supply ? If the transformer output was 5 volts RMS then reading an instantaneous voltage a some random point on the waveform could be anything between + 7.07 and - 7.07 volts. The average of the readings over a full cycle will be zero.

Les.
 

AlbertHall

Joined Jun 4, 2014
12,344
Is the arduino being powered by the AC/DC converter or does it have a separate supply?
It would be a good idea to feed the A0 arduino pin from a potential divider from the converter to be sure that the A0 pin does not have a voltage higher than the arduino itself. Two equal value resistors will give a nominal 2.5V. Resistor value not critical - 1k to 22k would do.
 

Thread Starter

Joe Martin

Joined Jan 6, 2017
13
Welcome to AAC!

Please post a picture of your schematic and/or tell us what schematic editor you're using.

It might also help if you posted the relevant portion of your code.
Thanks, dl324! The schematic was made in Eagle. I'm new to the software, so I'm not sure if there is any other file dependencies that the sch file needs. I've included a screenshot below to be sure.

upload_2019-7-30_8-24-48.png

This is the code I used for finding the average voltage on A0.

void setup() {
Serial.begin(9600);
}

void loop() {
unsigned long start_time = millis();
unsigned long count = 0;
unsigned long rawValue = 0;
while((millis()-start_time) < 3000)
{
rawValue += analogRead(A0);
count++;
}
double avgValue = (double)rawValue / (double)count;
double avgV = avgValue / 1024.0 * 5.0;
Serial.println(avgV);
}​
 

Thread Starter

Joe Martin

Joined Jan 6, 2017
13
What do expect if you use a transformer instead of a DC power supply ? If the transformer output was 5 volts RMS then reading an instantaneous voltage a some random point on the waveform could be anything between + 7.07 and - 7.07 volts. The average of the readings over a full cycle will be zero.

Les.
Hi Les, I'm sorry for the confusing schematic, but I couldn't find a symbol/part for a PSK-S5B-T so I used a transformer. On the datasheet it's listed as an ac-dc power supply. I tried to explain in the original post, but I see how the schematic would be confusing given my question. I would like to analyze the signal over time as I do have concerns that the DC output is unstable, but I don't have access to an oscilloscope.
 

Thread Starter

Joe Martin

Joined Jan 6, 2017
13
Is the arduino being powered by the AC/DC converter or does it have a separate supply?
It would be a good idea to feed the A0 arduino pin from a potential divider from the converter to be sure that the A0 pin does not have a voltage higher than the arduino itself. Two equal value resistors will give a nominal 2.5V. Resistor value not critical - 1k to 22k would do.
The arduino is powered off of the USB from my PC. Thanks, I'll give that a shot as soon as I can and let you know the results.
 

dl324

Joined Mar 30, 2015
16,839
There are so many Eagle versions out there, you should specify which version you're using. I use a very old version (4.13r1) because I don't like the user interface on the newer versions.

You can copy your code from the Arduino IDE with code tags. That would look something like this:

Code:
void setup() {
  Serial.begin(9600);
}

unsigned long start_time, count, rawValue;
double argValue, argV;

void loop() {
  start_time = millis();
  count = 0;
  rawValue = 0;
  while((millis()-start_time) < 3000) {
    rawValue += analogRead(A0);
    count++;
  }
  avgValue = (double)rawValue / (double)count;
  avgV = avgValue / 1024.0 * 5.0;
  Serial.println(avgV);
}
I moved the variable declarations out of loop() for readability.
 

Thread Starter

Joe Martin

Joined Jan 6, 2017
13
Thanks, Dennis. I'm accustomed to markdown, I didn't see the Code formatting under + originally. That looks much cleaner. I'm using Eagle version 9.4.2. Is it backward compatible? For now, I'll be sure to post screenshots as well.
 

dl324

Joined Mar 30, 2015
16,839
I didn't see the Code formatting under + originally. That looks much cleaner.
You select "Copy for Forum":
upload_2019-7-30_9-7-40.png
I'm using Eagle version 9.4.2.
The news version I have installed is 7.5.0. I stopped entertaining newer versions when they started requiring an account.
Is it backward compatible?
Not in my experience.
For now, I'll be sure to post screenshots as well.
One suggestion. Print to black and white PDF and take a snapshot from that. Color coded schematics seem silly to some (myself included).
 

LesJones

Joined Jan 8, 2017
4,174
Hi Joe,
I was assuming that the schematic software was also a simulator so I thought that the random readings and the average of the readings being zero was the result of it doing the simulation for a transformer.

Les.
 

Thread Starter

Joe Martin

Joined Jan 6, 2017
13
@LesJones Eagle does do simulations. I know how to create a part, but haven't learned how to create a part to work with a simulation. I'll look into that. The random reading results were live results taken from the Arduino pin.
 

Thread Starter

Joe Martin

Joined Jan 6, 2017
13
@AlbertHall I tried the voltage divider with two 1k resistors. I also added a pull down resistor with 20k because I was getting a lot of noise on A0 before the ac/dc adapter was even plugged in. I'm still not getting understandable results. I'm including the code which writes the raw measurement every 1000 cycles and then outputs the avg after 3 seconds; the output for one 3 second interval; and an updated schematic.

Code
Code:
void setup() {
  Serial.begin(9600);
}

void loop() {
  unsigned long start_time = millis();
  unsigned long count = 0;
  unsigned long rawValue = 0;
  while((millis()-start_time) < 3000)
  {
  if (count % 1000 == 0)
  {
  Serial.println(String(analogRead(A0) / 1024.0 * 5.0, 2));
  }
  rawValue += analogRead(A0);
  count++;
  }
  double avgValue = (double)rawValue / (double)count;
  double avgV = avgValue / 1024.0 * 5.0;
  Serial.println(String(avgV, 2) + " avg");
}
Output
11:04:56.519 -> 0.00
11:04:56.652 -> 0.00
11:04:56.818 -> 0.00
11:04:56.984 -> 0.08
11:04:57.117 -> 0.00
11:04:57.283 -> 0.02
11:04:57.416 -> 0.00
11:04:57.582 -> 0.00
11:04:57.715 -> 0.00
11:04:57.881 -> 0.00
11:04:58.047 -> 0.14
11:04:58.180 -> 0.00
11:04:58.346 -> 0.20
11:04:58.479 -> 0.14
11:04:58.645 -> 0.00
11:04:58.811 -> 0.00
11:04:58.944 -> 0.00
11:04:59.110 -> 0.08
11:04:59.243 -> 0.00
11:04:59.409 -> 0.00
11:04:59.509 -> 0.03 avg
upload_2019-8-3_11-23-13.png
 

djsfantasi

Joined Apr 11, 2010
9,156
LesJones gave to the answer in post #3.

One cycle of 60Hz 129VAC signal takes 17ms. In that time your while() loop will execute thousands of times. It will read the voltage all along the sine curve, some positive; some negative. At a minimum, you should loop for an integer multiple of 17ms

In theory the limit of the sum of all of the + & - voltages, is zero. If you got anything else, I’d be suspect.

In practice, you’re feeding a negative voltage to the Arduino pin half the time. Arduino’s don’t like that...

I’d rectify the AC. You’d get 0.637 of the peak value if you measured this way. You could filter the rectified AC but you’re going to get further away from the actual value. The peak value could be calculated by measuring the measured average value by 1.59 (the inverse of 0.637)

However, which technique you use depends ultimately on what in reality you’re trying to measure and the amount of accuracy required. Using the transformer, you’re measuring 120V ±24V. Is this good enough?
 

Thread Starter

Joe Martin

Joined Jan 6, 2017
13
@AlbertHall I believe you but I'm trying to understand why R2 needs to go back to ground on the Arduino. I thought the (-) of the ac/dc adapter would complete that circuit. Why doesn't it?

@djsfantasi My understanding from the datasheet is that this product should convert the signal to DC. I thought that meant there would not be negative voltage and that the signal would be (at least to a good degree), rectified. What am I misunderstanding? In regards to what it's for, the end goal is to power an ESP-01 at 3.3V with a max draw of 300mA. I'm using a LD1117V33C (800mA) voltage regulator to step down to the appropriate vcc. That said, while I was trying to build that circuit, I realized I didn't understand what was going on with my power supply. So, this question really is just to understand what is going on so I have a better understanding moving forward.

Thank you both for your help!
 
Top