# Tutorials

## Electronics Fundamentals: Alternating Current AC

last updated: 06/02/19

### Introduction

Song of this chapter: All songs by AC/DC ;)

Let's do a little history.

In 1887 in the United States Thomas Edison had constructed 121 DC power stations. At that time DC could not be easily converted to high voltages, needed to transport energy over longer distances. Edison promoted a system of many small, local power plants, that would power individual neighborhoods or city sections. With 110 V DC the voltage drop limited the maximum distance from the plant to the end user to 1.6 km. This limitation made power distribution in rural areas impossible.

In 1886 all Rome was electrified with AC. George Westinghouse ( entrepreneur and engineer from Pittsburgh) became aware of the new European alternating current systems in 1885 when reading an UK technical journal Engineering. He imported transformers and an AC electric generator, and began experimenting with AC networks and helped installing the first multiple-voltage AC power system. An hydroelectric generator produced 500 V AC stepped down to 100 V to light incandescent bulbs. The Westinghouse company installed more AC-lighting systems and by the end of 1887 it had 68 alternating current power stations.

The competition with Edison became the "War of the currents" with Thomas Edison spreading public perception that the high voltages used in AC distribution were unsafe.

###### "Just do (read and watch) it" AC1:
• Read the wiki about the "war of the currents" and search for a documentary on youtube.

### Why sinus and why 50Hz?

Most power plants (water, wind, coal, nuclear, gas) give us mechanical (kinetic) energy of rotation (from steam turbines, gas turbines or water turbines). With generators (dynamos or alternators) this rotational energy is converted to electrical energy. A current (moving electrons) produces a magnetic field. Bending a wire into multiple closely spaced loops to form a coil gives us an electromagnet.

On the other hand a moving wire (or a coil) in a magnetic field produces a voltage. This is called electromagnetic induction. A conductor loop (or a coil of wire) rotating in a magnetic field produces a current which changes direction with each 180° rotation, an alternating current (AC).

The inducted voltage depends on the changing of the magnetic flux `Φ` and the number of windings (`N`) of the coil, and the magnetic flux depends on the magnetic flux density `B` of the magnetic field and the effective area of the conductor loop `A` in the magnetic field and .

`u = -N·dΦ/dt     Φ = B·A`

The width `w` of the effective loop area in the magnetic field is maximum at 0°, and zero at 90°. It can be calculated with the cos of the angle `α`.

`Φ = B·w·l·cos(α)`  The changes of the magnetic flux is minimal at 0° and 180° and is biggest at 90° (negative) and 270°. The derivative of a cosine gives a sinus. That's why sinus :). The induced voltage can be calculated with:

`u = û·sin(α)` ###### "Just do (watch) it" AC2:
• Search for the video "How generator works by Khurram Tanvir" and watch it.

### Characteristics of an AC voltage

Here is the oscilloscope screen of a measured voltage in a wall socket. The oscilloscope measured three voltages, the frequency and the period. Let's take a closer look at these physical quantities. #### Peak voltage `û` and peak to peak voltage `USS`

`û` (`Us`) is the `peak voltage` (`Vp`) in Volt (V).

On the screen it is named Max. This voltage is in the European power supply system `325 V`.

The peak-to-peak voltage of an AC voltage `USS` (`Vpp`) in Volt (V) is the difference between its positive peak and its negative peak. For a sinusoidal voltage (sin(x) goes from +1 to −1) the maximum values swing between `+û` and `−û`. The peak-to-peak voltage is therefore `û−(−û) = 2û`. #### Period `T`, frequency `f` and angular frequency `ω`

`u(t) = û·sin(α(t))`

The amplitude of the voltage is changing in the rhythm of the sine between the peak values. One period is one revolution of the generator (0 - 360°). The time needed for such a revolution depends of the rotating speed of the generator. If the generator turns with 3000 revolutions per minute or 50 revolutions per second we get 50 periods per second. One sine wave of the voltage returns 50 times in one second. This is called the frequency `f` of the voltage. The time needed for one period is called periodic time `T`.

Frequency is the number of occurrences of a repeating event per unit of time. The symbol is `f` and the unit is hertz `Hz` or `s-1` (cycle per second).

The period `T` is the duration of time of one cycle in a repeating event, so the period is the reciprocal of the frequency. It's unit is the second `s`.

`f = 1/T     T = 1/f`

One revolution is equal to `360°` or `2π` radians. We can use the angular frequency `ω` to connect the time of one revolution with the angle.

`ω = 2π/T     ω = 2πf`

The angular frequency `ω` is a scalar measure of rotation rate. It's unit is `radians per second` (`s-1`).

For our sine wave we get:

`u(t) = û⋅sin⁡(ωt)`

with the momentary angle `α(t) = ω⋅t`.

So, why 50 Hz? The alternating current needed a frequency high enough to avoid flickering (see following exercise in this chapter) and not too high for the rotational speed of the generators.

#### Effective voltage `U` (`Ueff`, `URMS`)

The peak voltage is not a good value to describe the effect of an AC voltage. We want an AC voltage value that has the same effect than a DC voltage (how hot gets a radiator or how bright is a lamp). This can be achieved by comparing the time averaged power `P`. Instantaneous power `p(t)` would be calculated with:

`p(t) = u(t)2/R`

A time averaged power (where the averaging is performed over any integer number of cycles and with the same effect than DC power) can be calculated using a new AC voltage value called root mean square (RMS) value `URMS` or effective value `Ueff` or simply `U`.

`P = U2/R     P = Ueff2/R     P = URMS2/R`

The effective voltage of a waveform can be calculated with the corresponding crest factor:

`Ueff = û/crest factor`

Sine wave:

`U = Ueff = û/√2 = û/1.4142`
Triangle wave:
`U = Ueff = û/√3 = û/1.732`
Square wave:
`U = Ueff = û/1 = û`

###### "Just do it" AC3:
• We want to measure the AC voltage in our socket. Because this is potentially :) dangerous, we will use a transformer to reduce the voltage and see the curve of the voltage. Read and copy the characteristics of the transformer.
• We will use our multi-meter(s) to measure the AC voltage and the frequency. What maximum frequencies the used multi-meter(s) can measure (read the manual)? What is the maximum frequency of the AC voltage the multi-meter(s) can measure?
• Measure and note the voltage(s) and frequency(ies) and compare them with the characteristic of the transformer.
• To view the voltage characteristic we will use an oscilloscope. We use a mixed-signal-oscilloscope from Rohde & Schwarz. The `RTC 1002` has 2 channels and can display signals up to 100 MHz. Our oscilloscope is able to save the oscilloscope pictures to an USB-stick. You will use this feature to document this exercise and all future exercises where the oscilloscope is needed. Document the oscilloscope picture.
• Measure the period time, frequency and amplitude (Vpp) with the cursor on your oscilloscope. Calculate the root mean square and compare with your values from the voltmeter.
• Comment your results!

### Waveform's (time varying variables)

Alternating voltages and currents can come in a number of different waveform's. With oscilloscopes we can see this changing amplitude over time. • Square waves are used for example in digital switching electronics, as timing references (clock signals) and in music synthesizers.
• Triangle waves are also found in sound synthesis and are useful for testing linear electronics like amplifiers.
• Sawtooth waves are often used in music synthesizers, in switched-mode power supplies and the sawtooth wave is used to produce vertical and horizontal deflection signals used to generate a raster on CRT-based television or monitor screens.
• PWM waves have multiple applications, as servo control, encoding, voltage regulation and power delivery.
###### "Just do it" AC4:
• Lets use our ESP32 board to produce and measure alternating voltages. The first Arduino sketch will produce the simplest waveform, a square wave. This is done with the simple blink demo program. Connect an LED to digital pin 16 and test the following program.
``````    // Just do it AC4

const byte Square_out1 = 16;
unsigned int delay_time = 100;

void setup() {
pinMode (Square_out1, OUTPUT);
}

void loop() {
digitalWrite(Square_out1, LOW);
delay(delay_time);
digitalWrite(Square_out1, HIGH);
delay(delay_time);
}
``````
• Calculate the period time `T` and the frequency `f`. Watch the signal on the oscilloscope and measure `T` and `f` with the oscilloscope.
• Save in all following exercises the oscilloscope pictures to an USB-stick and use them to properly document your tasks.
• Reduce the delay time until you can't see the blinking no more. Calculate the frequency. If you are interested in this phenomena read the wiki articles about the flicker fusion threshold and the persistence of vision.
• Our oscilloscope has the possibility to watch the frequency domain with a fast Fourier transform function FFT. Try to determine the amplitudes of the third and fifth harmonic.
• Now we replace the LED with a piezoelectric speaker. Replace the `delay()` function with the `delayMicroseconds()` function. Calculate the `delay_time`'s, so we can hear a tones of 200 Hz, 1 kHz and 10 kHz.
• Comment the two delay lines and measure the maximal frequency the ESP32 can deliver. The square is no more symmetric because the ESP32 has an operating system running in the background and that consumes time.
###### "Just do it" AC5:
• With the next sketch we create a pulse-width modulation (PWM). The frequency of the square stays the same, but the square will not stay symmetric (pulse width time + off-time = constant). To change the width of the pulse we connect the wiper of a 10 kΩ potentiometer to pin 4. The other two terminals go to 3.3 V and GND. We could use the monitor to view the potentiometer values. Test the following sketch (oscilloscope and speaker connected):
``````    // Just do it AC5

const byte Square_out1 = 16;
const byte Pot_pin = 4;

unsigned int delay_time = 511;
unsigned int pulsewidth;

void setup() {
Serial.begin(115200);
pinMode (Square_out1, OUTPUT);
}

void loop() {
Serial.println(pulsewidth);
digitalWrite(Square_out1, LOW);
delayMicroseconds(delay_time - pulsewidth);
digitalWrite(Square_out1, HIGH);
delayMicroseconds(pulsewidth);
}
``````
• Write in your words the definition of duty cycle (wiki). Find the formula to calculate the duty cycle. Draw an U = f(t) diagram for a duty cycle of 30 %.
• Connect an LED instead of a speaker and test the program.
• Document (oscilloscope pictures) the voltage for a duty cycle of 10 % and of 80 %.
###### "Just do it" AC6:
• The ESP32 has two internal Digital-to-Analog Converters (DAC). We can use our ESP32 or Arduino to build a function generator that produces different wave-forms. Here is an example. Test the program:
``````    //  Just do it AC6 (DAC1 on IO25, DAC2 on IO26)

float y;
int sine;

void setup() {
for (int i=0;i<255;i++) {
y=sin(((float)i/255)*2*PI); // calculate the sine table
sine[i]=int(y*128)+128;
}
}

void loop() {
for (int i=0;i<255;i++) {
dacWrite(DAC1, sine[i]);    // write on DAC1
dacWrite(DAC2, i);          // write on DAC2
delayMicroseconds(1);
}
}
``````
• Analyze the program and document it.Read the following article about Arduino arrays. Why don't we calculate the array during the main loop?
• Oscilloscope the voltages on DAC1 and DAC2. What is the name of the second waveform?. Change `dacWrite(DAC2, i);` to `dacWrite(DAC2, 255-i);`. Comment the result.
• Without supplementary circuitry the ESP32 delivers only voltages from 0 to 3.3 V. We get no negative voltages. To test further wave-forms, we will use a two channel arbitrary waveform generator (1 µHz - 10 MHz) from PeakTech, the PeakTech 4124. Connect the function generator to a piezoelectric speaker and to the oscilloscope. Test the different wave-forms.

#### Fourier_series

As seen the most common type of AC is the sine wave.

The french mathematician Joseph Fourier discovered in 1822 that the sine wave has a very special characteristic.

Any periodic waveform can be described with a sum of sine (or/and cosine) waves.

The study of the way functions may be represented or approximated by sums of e.g sine waves is called Fourier analysis. The representation of a function as the sum of simple sine waves is called a Fourier series.

###### "Just do it" AC7:
• The following program visualizes the synthesis of a square wave by adding sinuses. As you see we add the harmonics with 3f, 5f, 7f and 9f with a reduced amplitude of 1/3, 1/5, 1/7 and 1/9. Test the program:
``````    //  Just do it AC7 (DAC1 on IO25, DAC2 on IO26)

float y;
int ymax = 80;
int i,j,sine,sine3,sine5,sine7,sine9;

void setup() {
for (int i=0;i<255;i++) {
y=sin(((float)i/255)*2*PI);
sine[i]=int(y*ymax);
}
for (int i=0;i<255;i++) {
y=sin(((float)i/255)*2*3*PI);
sine3[i]=int(y*ymax/3);
}
for (int i=0;i<255;i++) {
y=sin(((float)i/255)*2*5*PI);
sine5[i]=int(y*ymax/5);
}
for (int i=0;i<255;i++) {
y=sin(((float)i/255)*2*7*PI);
sine7[i]=int(y*ymax/7);
}
for (int i=0;i<255;i++) {
y=sin(((float)i/255)*2*9*PI);
sine9[i]=int(y*ymax/9);
}
}

void loop() {
for (j=0;j<1000;j++) {
for (i=0;i<255;i++) {
dacWrite(DAC1, sine[i]+128);
dacWrite(DAC2, sine3[i]+128);
delayMicroseconds(1);
}
}
for (j=0;j<1000;j++) {
for (i=0;i<255;i++) {
dacWrite(DAC1, sine5[i]+128);
dacWrite(DAC2, sine7[i]+128);
delayMicroseconds(1);
}
}
for (j=0;j<1000;j++) {
for (i=0;i<255;i++) {
dacWrite(DAC1, sine[i]+sine3[i]+128);
dacWrite(DAC2, sine[i]+sine3[i]+sine5[i]+128);
delayMicroseconds(1);
}
}
for (j=0;j<1000;j++) {
for (i=0;i<255;i++) {
dacWrite(DAC1, sine[i]+sine3[i]+sine5[i]+sine7[i]+128);
dacWrite(DAC2, sine[i]+sine3[i]+sine5[i]+sine7[i]+sine9[i]+128);
delayMicroseconds(1);
}
}
}
``````
• Change the harmonics to 2f, 3f, 4f and 5f with a reduced amplitude of 1/2, 1/3, 1/4 and 1/5. Which wave-form will arise?

Let's have a closer look on the fourier series of a square wave:

`u(t) = 1.2732(sin⁡(ωt) + 1/3(sin⁡(3ωt) + 1/5(sin⁡(5ωt) + 1/7(sin⁡(7ωt) + 1/9(sin⁡(9ωt) + ...)`

We see that a square wave with a certain base frequency f can be created by adding to a sine wave with the same base frequency and an amplitude of `4/π = 1.2732` to a second sine wave with 3 times the base frequency and an amplitude of `4/3π = 1.2732/3` and a third sine wave with 3 times the base frequency and an amplitude of `4/5π = 1.2732/5` and so forth as shown in the following animated gif-picture from wikipedia. Even by adding multiple sine waves up to very high frequencies, the square wave is not perfect! There will always be little ripples (ringing artifacts) and the rise time (time to change from a low to high) will not be infinite low.

This tells us a very important lesson.

It is impossible to achieve in physical systems an ideal square wave (instantaneously changes between the high and the low state and no under- or over-shooting). This would require an infinite bandwidth, but every real system has the characteristic of a low-pass filter. To transport a digital signal, the passing frequency of the used transportation channel must be much higher than the base frequency of the signal.

If we use an oscilloscope of 20 MHz to watch a perfect digital signal of 10 MHz, we will see a sine wave!! Even with an oscilloscope of 100 MHz we will not see the real signal!

Another example: In older days :) the telephone line was limited to 3.4kHz. It was not possible to pass a digital signal directly at a reasonable frequency. So it was necessary to use a modem (modulator-demodulator). Instead of sending a digital signal four sine waves were used. The call originator used sine waves at 1070 Hz and 1270 Hz (for low and high) and the answering modem 2025 Hz and 2225 Hz. This modulation is a frequency modulation and is called Frequency-shift keying (FSK) and allowed [full-duplex](https://en.wikipedia.org/wiki/Duplex_(telecommunications) at 300 bit/s! (50 years ago). If you want to see modem with acoustic coupler watch the film war games from 1983.

Any signal that can be represented as a variable that varies in time has a corresponding frequency spectrum. On the following picture we see the frequency spectrum of three different waveform's: #### Electromagnetic spectrum (wiki)

Class Short Frequency Wavelength
Gamma rays γ 300 EHz

30 EHz
1 pm

10 pm

Hard X-rays HX
300 EHz
1 pm
Soft X-rays SX 300 PHz 1 nm
Extreme ultraviolet EUV 30 PHz

3 PHz
10 nm

100 nm
------------------------- ------------------------ ----- --------- ---------

Near ultraviolet NUV 3 PHz

300 THz
100 nm

1 µm
Near infrared NIR
30 THz

10 µm
Mid infrared MIR
3 THz

100 µm
Far infrared FIR
300 GHz

1 mm
------------------------- ------------------------ ----- --------- ---------
Extremely high frequency EHF 300 GHz

30 GHz
1 mm

1 cm

Microwaves
Super high frequency SHF
3 GHz

1 dm
Ultra high frequency UHF
300 MHz

1 m
Very High frequency VHF
30 MHz

10 m
------------------------- ------------------------ ----- --------- ---------
High frequency HF 30 MHz

3 MHz
10 m

100 m

Medium frequency MF
300 kHz

1 km
Low frequency LF
30 kHz

10 km
Very low frequency VLF
3 kHz

100 km
------------------------- ------------------------ ----- --------- ---------
Ultra low frequency ULF 3 kHz

300 Hz
100 km

1 Mm
Super low frequency SLF
30 Hz

10 Mm
Extremly low frequency ELF
3 Hz

100 Mm

### Dangerous current

In the war of currents Edison used the danger of currents to argue against AC voltage. A pamphlet claimed DC had not caused a single death, and included newspaper stories of accidental electrocutions caused by alternating current. Westinghouse on the other side pointed out in letters to various newspapers the number of fires caused by DC equipment.

If you touch the electric wire around a meadow, you touch a voltage of 2000 V - 5000 V. Why does this high voltage does not kill you on the spot?

It's not the voltage that kills (voltage can hurt without direct damage), but the height of the current and the duration the current passes the heart. The current of the meadow wire is limited to 100 mA - 300 mA and the duration to 20 ms - 100 ms.

#### Effects of electrical current in the human body

The IEC publication 60479-1 defines four zones of current-magnitude /time-duration. In each of these four zones the physiological effects are described. Source: Graphic by Cmglee under Creative Commons Attribution-ShareAlike 3.0 Unported license(CC BY-SA 3.0).

Time/current zones for AC 15 Hz to 100 Hz for hand to feet pathway

Zones Boundaries   Physiological effects
AC-1 Up to 0.5 mA Perception possible but usually no ‘startled’ reaction
AC-2
0.5 mA up to
green curve
Perception and involuntary muscular contractions likely but usually
no harmful electrical physiological effects
AC-3

Green curve up
to red curve

Strong involuntary muscular contractions. Difficulty in breathing.
Reversible disturbances of heart function. Immobilization may occur.
Effects increasing with current magnitude.
Usually no organic damage to be expected
AC-4
1)

Above red curve

Patho-physiological effects may occur such as cardiac arrest,
breathing arrest, and burns or other cellular damage.
Probability of ventricular fibrillation increasing with current magnitude
and time
AC-4.1 Probability of ventricular fibrillation increasing up to about 5 %
AC-4.2 Probability of ventricular fibrillation up to about 50 %
AC-4.3 Probability of ventricular fibrillation above 50 %

1)
For duration's of current flow below 200 ms, ventricular fibrillation is only initiated within the vulnerable period if the relevant thresholds are surpassed. As regards ventricular fibrillation, this figure relates to the effects of current which flows in the path left hand to feet. For other current paths, the heart current factor has to be considered.

As we see above, the differences between AC and DC are not huge.

Simplified we could state that for a short time (less than 200 ms) a human can stand 50 mA (AC or DC).

Ohm's law states that the current drawn depends on the resistance of the body. Every person has his own resistance as a lot of different factors are involved (e.g. like for wires as resistors, the resistance of an arm or leg depends on it' length and diameter). Men tend to have lower resistance than women (thicker arms and legs). A rough value for the internal resistance of the human body is 300 Ω - 1000 Ω. The path that electricity takes through the body is also important (e.g. the resistance from hand to foot is bigger than the distance from thumb to ring-finger on the same hand).
But the main resistance comes from the skin, witch is a poor conductor if it's not wet or burnt/blistered. The resistance from dry skin is between 1000 Ω - 100000 Ω.

The total resistance is:

`RBody = RSkin+RBint+RSkout` For simplification we will memorize that the total resistance of the human body is 1000 Ω.

###### "Just do (calculate) it" AC8:
• Try to measure your resistance with the ohmmeter. Try also with wet hands. Do you think this measurements may be dangerous for you?
• Calculate the maximum voltage you can touch without being in danger, if your resistance is 1000 Ω.

It is the current that kills, but anyway we can state:

Voltages above 50 V AC and above 120 V DC are dangerous!
For children and animals voltages above 25 V AC and above 60 V DC are dangerous!
Voltages under 25 V AC and under 60 V DC schould be used, they are not dangerous!

###### "Just do (research) it" AC9:
• Currents above 200 mA, will produce severe burns and unconsciousness. Research the first aid actions that have to be taken in the case of an electric shock.

#### Other dangers

A current through a wire causes heat, and so a third of all fires is caused by short circuits or overheating of electric equipment. Other dangers of electricity are the high forces generated through magnetism at high currents, or flash burns of the eyes flash arcs caused in short circuits. A current through a fluid can also produce toxic or explosive gases.