Home › Lessons › Embedded (Arduino) › analogRead and PWM: a pot dims an LED

analogRead and PWM: a pot dims an LED

Embedded (Arduino) · Intermediate · about 15 minutes · part of Zen’s Electronics Design Mastery

analogRead turns 0–5 V into a number from 0 to 1023 (10 bits). analogWrite cannot make a real voltage: it switches the pin fully on and off 490 times a second, and the share of time it is on (the duty cycle, 0–255) sets the average. Only pins 3, 5, 6, 9, 10 and 11 can do it.

analogRead and PWM: a pot dims an LED: the circuit on the simulator's bench

Open this lesson in the labFree, in your browser, no account needed.

Try it on the bench

  1. Turn the pot (select it, drag Position) and watch the numbers and the LED.
  2. Change pin 9 to 8 in the sketch and upload: pin 8 has no PWM, so the LED is only fully on (128 and up) or off.
  3. Open the Serial Monitor at a different baud rate: the text turns to garbage, because both ends must agree.

Parts on the bench

In the course

Zen’s Electronics Design Mastery, module “Microcontrollers & Embedded”.

More on embedded (arduino)