Robots Atlas>ROBOTS ATLAS

Arduino for Beginners · Analog Signals: ADC and PWM

Mini project: a light-reactive night lamp (analog input → PWM output)

Analog Signals: ADC and PWM

Introduction

Time to combine everything from this chapter into one working circuit: a photoresistor (analog input) controls LED brightness (PWM output). The signal flows from the LDR in a voltage divider, through pin A0 and analogRead(), through map() and constrain() processing, all the way to analogWrite() on a PWM pin. You will learn the inverse-proportion logic (darker = brighter), threshold calibration for a specific room, the difference between a threshold variant (if) and a smooth variant (PWM), plus hysteresis and reading averaging as a cure for flicker. You will build the complete sketch skeleton: setup() (Serial, pinMode) and loop() (read -> map -> constrain -> analogWrite -> delay). In this lesson we assume a circuit where the LDR sits between 5V and A0, and a 10 kOhm resistor between A0 and GND — so dark = low reading, bright = high reading.