Language basics
27 steps in 9 sets of Arduino.
Arduino is C++ wearing overalls: the dialect and core library that made microcontrollers a hobby-store purchase instead of an electrical-engineering degree. A sketch is two functions — setup once, loop forever — and the vocabulary is the hardware itself: pinMode, digitalWrite, analogRead, millis. Since 2005 it has been the on-ramp for makers, artists, and students, and the prototyping bench for a great deal of professional embedded work.
This tour types the working vocabulary of a real bench: blink and Serial, named pins, pull-up buttons and edge-detected toggles, PWM fades, the analog pipeline from counts to volts with map and constrain, hysteresis, the millis patterns that replace delay, serial input and one-letter command switches, CSV telemetry for the plotter, helper functions and pin arrays, a state machine, char buffers and structs and EEPROM, interrupts, tone, and seeded randomness. The Encore is three complete devices: a traffic light, a greenhouse controller, and a Morse beacon — every seed compiles for a real Uno.
The sketch
- The sketch shapeBlink: the hello world of hardware, in two functions.
- Serial outputThe sketch's voice: begin at a baud rate, print lines.
- Named pinsconst int beats a bare pin number scattered through a sketch.
Digital I/O
- INPUT_PULLUPThe internal resistor holds the pin HIGH; a press pulls it LOW.
- Toggle on pressA state variable remembers across loop passes; ! flips it.
- PWM fadeanalogWrite dims with duty cycle: 0 is off, 255 is full.
Analog
- analogRead0 to 1023 counts, and the arithmetic that makes them volts.
- map and constrainRescale one range onto another, then clip the edges.
- HysteresisTwo thresholds keep the pump from chattering at the line.
Timing
- Blink without delaymillis never blocks: compare timestamps instead of sleeping.
- Two timersTwo jobs, two timestamps, neither waiting for the other.
- DebounceA press counts once the contacts stop bouncing.
Serial
- Serial inputavailable counts waiting bytes; read takes them one by one.
- Serial commandsOne-letter commands from the monitor drive the relays.
- CSV telemetryComma-separated lines that the serial plotter graphs directly.
Functions & state
- Helper functionsSmall named functions keep loop a one-line policy.
- Pin arraysAn array of pins turns repeated setup into a loop.
- A state machineAn enum names the states; switch runs exactly one per pass.
Data
- char buffersFixed buffers avoid String's heap churn on a 2 KB board.
- StructsOne struct rides a whole reading through the sketch.
- EEPROM1024 bytes that survive power loss.
Peripherals
- InterruptsAn ISR runs the instant the pin falls, mid-loop.
- toneDrive a piezo at a frequency; noTone silences it.
- randomSeed from a floating pin, then draw from a range.
Encore
- traffic_light.inoA junction light: enum phases, timed transitions, no delay anywhere.
- greenhouse_monitor.inoThe whole greenhouse: two hysteresis loops and a CSV report line.
- morse_beacon.inoBlink a message in Morse from an A-Z lookup table.