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
- LED Bar Graph: How to make an LED bar graph.
- Row Column Scanning: How to control an 8×8 matrix of LEDs.
- StringAdditionOperator: Add strings together in a variety of ways.
- StringAppendOperator: Append data to strings.
- StringCaseChanges: Change the case of a string.
- StringCharacters: Get/set the value of a specific character in a string.
- StringComparisonOperators: Compare strings alphabetically.
- StringConstructors: How to initialize string objects.
- StringIndexOf: Look for the first/last instance of a character in a string.
- StringLength & StringLengthTrim: Get and trim the length of a string.
- StringReplace: Replace individual characters in a string.
- StringStartsWithEndsWith: Check which characters/substrings a given string starts or ends with.
- StringSubstring: Look for “phrases” within a given string.
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.
- KeyboardAndMouseControl: Demonstrates the Mouse and Keyboard commands in one program.
- 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.
- ButtonMouseControl: Control cursor movement with 5 pushbuttons.
- JoystickMouseControl: Controls a computer’s cursor movement with a Joystick