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.
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.
The first challenge is free. The rest, the viva and the certificate are part of Pro, and everything is here to read.
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. Print millivolts from analogRead
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.
Your task
A divider, 10 kΩ over 4.7 kΩ, puts about 1.6 V on A0. The starter prints the raw ADC code.
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. Choose a divider for an ADC code of 512
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.
Formulacode = 1023 × R2 / (R1 + R2)
Worked exampleWith R1 = 3.3 kΩ and R2 = 1 kΩ: 1023 × 1 / 4.3 = 238.
On the scope or meterThe printed raw code changes as you change R2. A voltmeter on A0 reads the code times about 4.9 mV.
Your task
The sketch prints the raw code on A0. The divider’s top resistor R1 is 10 kΩ.
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. Make 2.0 V with a PWM DAC
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.
Your task
Pin 9 drives an RC low-pass filter, 10 kΩ into 10 µF, which smooths the PWM into a steady voltage.
Change the analogWrite value so the filtered voltage averages 2.0 V, within 3%.
4. Measure the ripple a PWM DAC leaves
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.