Arduino code examples you can run right now
Every sketch here is short, tested and explained line by line. Copy it into the Arduino IDE, or press one button and watch it run in the browser simulator — no board needed.
Blink an LED
Blink is the first sketch everyone writes. It switches an LED on, waits, switches it off, and repeats forever — the timing pattern almost every other Arduino project reuses.
See the codeServo sweep
A servo moves to an angle you choose and holds it there. Two sketches cover almost everything: one that jumps to set angles, and one that sweeps smoothly from 0° to 180°.
See the codeUltrasonic distance
The HC-SR04 sends a burst of sound and times the echo coming back. Divide that time by 58 and you get the distance in centimetres.
See the codeDHT11 temperature
The DHT11 measures temperature and humidity together and reports both over a single data wire. It needs the DHT sensor library, which you install once from the Arduino IDE.
See the code