Arduino for Beginners · Digital Inputs and Outputs
Mini-project: traffic light / binary counter
Digital Inputs and Outputs
Introduction
Time to combine everything from the chapter into one working circuit. First we build a traffic light: three LEDs (red, yellow, green) on three OUTPUT pins, driven by digitalWrite() in the correct phase order (red → red+yellow → green → yellow → and back), with phase duration measured first by delay() and then — for a non-blocking version that reacts to a pedestrian button — by millis(). The second part is a binary counter: four LEDs represent four bits with weights 1, 2, 4 and 8, showing numbers from 0 to 15 in the binary system, with increment on a button press (using debounce from lesson 4.3) and wrap-around 15 → 0 via modulo 16. The project ties together pinMode and digitalWrite (4.1), digitalRead with pull-up (4.2), debounce (4.3) and if/else (4.4) into one whole.