(redirected from
Main.LearnArduino)
Learning Examples | Foundations | Hacking | Links
Examples
See the foundations page for in-depth description of core concepts of the Arduino hardware and software; the hacking page for information on extending and modifying the Arduino hardware and software; and the links page for other documentation.
Here's a style guide that helps with writing examples for beginners.
Basics
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.
Digital I/O
- Blink: turn an LED on and off.
- Blink Without Delay: blinking an LED without using the delay() function.
- Button: use a pushbutton to control an LED.
- Button State Change counting the number of button pushes
- Debounce: read a pushbutton, filtering noise.
- 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.
Analog I/O
- Analog Input: use a potentiometer to control the blinking of an LED.
- Calibration: for analog sensor readings
- Fading: uses an analog output (PWM pin) to fade an LED.
- Smoothing: smooth multiple readings of an analog input.
Control Structures
- 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.
Sensors
- ADXL3xx: Read an ADXL3xx accelerometer.
- Knock: detect knocks with a piezo element.
- Memsic2125 : two-axis acceleromoter
- Ping: detecting objects with an ultrasonic range finder
Communication
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
- ASCII Table: demonstrates Arduino's advanced serial output functions.
- Dimmer: move the mouse to change the brightness of an LED.
- Graph: sending data to the computer and graphing it in Processing.
- Physical Pixel: turning on and off an LED by sending data from Processing.
- Virtual Color Mixer: sending multiple variables from Arduino to the computer and reading them in Processing.
- Serial Call Response: sending multiple vairables using a call-and-response (handshaking) method.
- Serial Call Response ASCII: sending multiple vairables using a call-and-response (handshaking) method, and ASCII-encoding the values before sending.
- Serial input how to take different actions based in characters received in the serial port.
- MIDI How to send MIDI note messages serially.
Display
Examples of basic display control
|
Libraries
Examples from the libraries that are included in the Arduino software.
EEPROM Library
LiquidCrystal Library
- 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
Servo Library
- Knob: control the shaft of a servo motor by turning a potentiometer.
- Sweep: sweeps the shaft of a servo motor back and forth.
Stepper Library
- Motor Knob: control a stepper motor with a potentiometer.
More
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.
|