Graded ADC and DAC labs that run your sketch: print millivolts from analogRead, set a divider for a code, make a PWM DAC with an RC filter and measure ripple.
The first challenge is free. The rest, the viva and the certificate are part of Pro, and everything is here to read.
The module
What it covers, and what you can do after
On the syllabus
ADC resolution, reference and the code-to-volts conversion
Integer arithmetic for scaling without overflow
Choosing a divider for an ADC input
PWM plus an RC low-pass filter as a DAC
DAC ripple and the filter’s time constant
You will be able to
Convert an ADC code to millivolts without overflow or floating point.
Choose a divider that puts a signal where the ADC wants it.
Make a steady voltage from PWM with an RC filter.
Predict and measure the ripple a PWM DAC leaves.
Practice
Graded challenges
Values like 4.7k, 100n or 2.2u are fine. Readings are the number only, in the unit shown. Every check measures the simulation, not a bench: ideal parts within their models, no noise.
1
1. Print millivolts from analogRead
1 checked, a sketch to write
An ADC turns a voltage into a whole number. The Uno’s is 10 bits against its 5 V supply, so 0 V reads 0 and 5 V reads 1023. To get volts back you scale the code by the reference.
FormulamV = code × 5000 / 1023
Worked exampleA code of 300 is 300 × 5000 / 1023 = 1466 mV. Done in a 16-bit int, 300 × 5000 = 1 500 000 overflows; done in a long it fits.
On the scope or meterThe serial monitor prints a new line every 100 ms. The voltmeter on A0 and your printed millivolts should agree to within a few mV.
Change the sketch to print the voltage in millivolts, as a line like mv=1598, at least every 200 ms. Watch the arithmetic: 1023 × 5000 does not fit in an int.
2
2. Choose a divider for an ADC code of 512
1 to design, 1 checked, a sketch to write
A divider sets where a voltage sits in the ADC’s range. The code is the tap voltage as a fraction of 5 V, times 1023.
Choose R2, the bottom resistor, so the code is 512, within 5 counts: the middle of the ADC’s range. Build the sketch as it is and check.
3
3. Make 2.0 V with a PWM DAC
1 checked, a sketch to write
PWM switches a pin between 0 V and 5 V. A low-pass filter well below the PWM frequency keeps only the average, which is the duty cycle times 5 V. analogWrite takes 0 to 255 for 0% to 100%.
FormulaVout = 5 V × value / 255
Worked exampleFor 3.0 V you need 60% duty: 0.6 × 255 = 153.
On the scope or meterThe scope on C1 shows a nearly flat line with a small ripple on top. It takes a few time constants (RC = 100 ms here) to settle.
Change the analogWrite value so the filtered voltage averages 2.0 V, within 3%.
4
4. Measure the ripple a PWM DAC leaves
1 to measure, a sketch to write
A filter cannot remove all of the switching. The capacitor charges a little in the high time and discharges in the low time, leaving a ripple. A bigger RC smooths more but answers more slowly.