Simple programs that demonstrate basic Arduino commands. These are included with the Arduino environment; to open them, click the Open button on the toolbar and look in the examples folder.
- BareMinimum: The bare minimum of code needed to start an Arduino sketch.
- Blink: Turn an LED on and off.
- DigitalReadSerial: Read a switch, print the state out to the Arduino Serial Monitor.
- AnalogReadSerial: Read a potentiometer, print its state out to the Arduino Serial Monitor.
- Fade: Demonstrates the use of analog output to fade an LED.
- ReadAnalogVoltage : Reads an analog input and prints the voltage to the serial monitor
- Blink Without Delay: blinking an LED without using the delay() function.
- Button: use a pushbutton to control an LED.
- Debounce: read a pushbutton, filtering noise.
- Button State Change: counting the number of button pushes.
- Input Pullup Serial: Demonstrates the use of INPUT_PULLUP with pinMode().
- Tone: play a melody with a Piezo speaker.
- Pitch follower: play a pitch on a piezo speaker depending on an analog input.
- Simple Keyboard: a three-key musical keyboard using force sensors and a piezo speaker.
- Tone4: play tones on multiple speakers sequentially using the tone() command.
- AnalogInOutSerial: Read an analog input pin, map the result, and then use that data to dim or brighten an LED.
- Analog Input: Use a potentiometer to control the blinking of an LED.
- AnalogWriteMega: Fade 12 LEDs on and off, one by one, using an Arduino Mega board.
- Calibration: Define a maximum and minimum for expected analog sensor values.
- Fading: Use an analog output (PWM pin) to fade an LED.
- Smoothing: Smooth multiple readings of an analog input.
These examples include code that allows the Arduino to talk to Processing sketches running on the computer. For more information or to download Processing, see processing.org. There are also Max/MSP patches that can communicate with each Arduino sketch as well. For more on Max/MSP see Cycling 74. For Pd patches that can communicate with these sketches, see Scott Fitzgerald's examples.
- ReadASCIIString: Parse a comma-separated string of ints to fade an LED.
- ASCII Table: Demonstrates Arduino's advanced serial output functions.
- Dimmer: Move the mouse to change the brightness of an LED.
- Graph: Send data to the computer and graph it in Processing.
- Physical Pixel: Turn a LED on and off by sending data to your Arduino from Processing or Max/MSP.
- Virtual Color Mixer: Send multiple variables from Arduino to your computer and read them in Processing or Max/MSP.
- Serial Call Response: Send multiple variables using a call-and-response (handshaking) method.
- Serial Call Response ASCII: Send multiple variables using a call-and-response (handshaking) method, and ASCII-encode the values before sending.
- SerialEvent: Demonstrates the use of SerialEvent().
- Serial input (Switch (case) Statement): How to take different actions based on characters received by the serial port.
- MIDI: Send MIDI note messages serially.
- MultiSerialMega: Use two of the serial ports available on the Arduino Mega.
- If Statement (Conditional): How to use an if statement to change output conditions based on changing input conditions.
- For Loop: Controlling multiple LEDs with a for loop and.
- Array: A variation on the For Loop example that demonstrates how to use an array.
- While Loop: How to use a while loop to calibrate a sensor while a button is being read.
- Switch Case: How to choose between a discrete number of values. Equivalent to multiple If statements. This example shows how to divide a sensor's range into a set of four bands and to take four different actions depending on which band the result is in.
- Switch Case 2: A second switch-case example, showing how to take different actions based in characters received in the serial port.
- ADXL3xx: Read an ADXL3xx accelerometer.
- Knock: Detect knocks with a piezo element.
- Memsic2125 : Two-axis acceleromoter.
- Ping: Detecting objects with an ultrasonic range finder.
Examples of basic display control
9.USB (Leonardo, Micro, and Due specific examples)
The Keyboard and Mouse examples are unique to the Leonardo, Micro and Due. They demonstrate the use of libraries that are unique to the board.
- KeyboardMessage: Sends a text string when a button is pressed.
- KeyboardLogout : Logs out the current user with key commands.
- KeyboardSerial: Reads a byte from the serial port, and sends back a keystroke.
- KeyboardReprogram : Opens a new window in the Arduino IDE and reprograms the Leonardo with a simple blink program.
Examples from the libraries that are included in the Arduino software.
Bridge Library (for the Arduino Yún)
- Bridge: Access the pins of the board with a web browser.
- Console ASCII Table: Demonstrates printing various formats to the Console.
- Console Pixel: Control an LED through the Console.
- Console Read: Parse information from the Console and repeat it back.
- Datalogger: Store sensor information on a SD card.
- File Write Script: Demonstrates how to write and execute a shell script with Process.
- HTTP Client: Create a simple client that downloads a webpage and prints it to the serial monitor.
- Process: Demonstrates how to use Process to run Linux commands.
- Shell Commands: Use Process to run shell commands.
- Temperature Web Panel: Post sensor data on a webpage when requested by a browser.
- TimeCheck: Get the time from a network time server and print it to the serial monitor.
- WiFiStatus: Runs a pre-configured script that reports back the strength of the current WiFi network.
- Xively Client : Send data from multiple sensors to Xively with strings.
- Yun Serial Terminal: Access the Linux Terminal through the serial monitor.
- MailboxReadMessage: Send text messages to the Arduino processor using REST API through a browser.
The Temboo website has a section dedicated to the reference of the Temboo library and examples contained inside the Arduino IDE. See this page for more information.
There are a number of examples for Spacebrew on the Yún included in the software. For more on Spacebrew, see the project documentation pages.
Esplora Beginner examples
Esplora Expert examples
- EsploraKart : Use the Esplora as a controller to play a kart racing game.
- EsploraTable : Print the Esplora sensor information to a table format.
- EsploraRemote : Connect the Esplora to Processing and control the outputs.
- EsploraPong : Play Pong with the Esplora using Processing.
- Make Voice Call: Get your shield to make phone calls from the Serial Monitor.
- Receive Voice Call: Check the status of the modem while getting voice calls.
- Send SMS: Use the Serial Monitor to type in SMS messages to different phone numbers.
- Receive SMS: Read SMS messages and prompt them to the Serial Monitor.
- Web Client: Download the content of a website to your Arduino board through GPRS.
- Web Server: Create a wireless web server through GPRS.
- Xively Client: Communicate to the Xively sensor backbone.
- Xively Client String: Communicate to the Xively sensor backbone.
- Hello World: Displays "hello world!" and the seconds since reset.
- Blink: Control of the block-style cursor.
- Cursor: Control of the underscore-style cursor.
- Display: Quickly blank the display without losing what's on it.
- TextDirection: Control which way text flows from the cursor.
- Scroll: Scroll text left and right.
- Serial input: Accepts serial input, displays it.
- SetCursor: Set the cursor position.
- Autoscroll: Shift text right and left.
- Logo - Tell your robot where to go through the on-board keyboard.
- Line Following - Draw a racing track and get your robot to run on it.
- Disco Bot - Turn your robot into an 8-bit jukebox and dance to the beat.
- Compass - Plan a treasure hunt with this digital compass.
- Inputs - Learn how to control the knob and the keyboard.
- Wheel Calibration - Tune the wheels to perform even better.
- Runaway Robot - Play tag with your robot using a distance sensor.
- Remote control - Reuse that old tv-remote to command the bot on distance.
- Picture browser - Want to use your own images? This is how.
- Rescue - Train your robot to look for hidden pearls in a maze.
- Hello User - Hack the robot's welcome demo and make your own.
- Calibrate Compass? - Calibrate the compass module so it rotates evenly(for old models, using Honeywell HMC 6352).
- Knob: Control the shaft of a servo motor by turning a potentiometer.
- Sweep: Sweeps the shaft of a servo motor back and forth.
Software Serial Library
- Motor Knob: Control a highly accurate stepper motor using a potentiometer.
- TFT Bitmap Logo: Read an image file from a micro-SD card and draw it at random locations.
- TFT Display Text : Read the value of a sensor and print it on the screen.
- TFT Pong: An Arduino implementation of the classic game.
- Etch a Sketch: An Arduino version of the classic Etch-a-Sketch.
- Color Picker: With three sensors, change the color of the TFT screen.
- Graph: Graph the values from a variable resistor to the TFT.
Arduino as ISP Programmer
ArduinoISP Turns your Arduino into an in-circuit programmer to re-program Atmega chips. Useful when you need to re-load the bootloader on an Arduino, if you're going from Arduino to an Atmega on a breadboard, or if you're making your own Arduino-compatible circuit on a breadboard.
For a huge list of examples from the Arduino community, see the interfacing with hardware page on the playground wiki. Also see the list of old examples.
Here's a style guide that helps with writing examples for beginners.