Arduino

Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

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.

Examples
Simple programs that demonstrate the use of the Arduino board. These are included with the Arduino environment; to open them, click the Open button on the toolbar and look in the examples folder. (If you're looking for an older example, check the Arduino 0007 tutorials page.) 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. Debounce: read a pushbutton, filtering noise. Loop: controlling multiple LEDs with a loop and an array. Analog I/O Analog Input: use a potentiometer to control the blinking of an LED. Fading: uses an analog output (PWM pin) to fade an LED. Knock: detect knocks with a piezo element. Smoothing: smooth multiple readings of an analog input. 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. 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. EEPROM Library

Other Examples
These are more complex examples for using particular electronic components or accomplishing specific tasks. The code is included on the page. Miscellaneous TwoSwitchesOnePin: Read two switches with one I/O pin Read a Tilt Sensor Controlling an LED circle with a joystick 3 LED color mixer with 3 potentiometers

Timing & Millis
Stopwatch Complex Sensors Read an ADXL3xx accelerometer Read an Accelerometer Read an Ultrasonic Range Finder (ultrasound sensor) Reading the qprox qt401 linear touch sensor Sound Play Melodies with a Piezo Speaker Play Tones from the Serial Connection MIDI Output (from ITP physcomp labs) and from Spooky Arduino Interfacing w/ Hardware Multiply the Amount of Outputs with an LED Driver Interfacing an LCD display with 8 bits LCD interface library Driving a DC Motor with an L293 (from ITP physcomp labs). Driving a Unipolar Stepper Motor Build your own DMX Master device Implement a software serial connection RS-232 computer interface Interface with a serial EEPROM using SPI Control a digital potentiometer using SPI Multiple digital outs with a 595 Shift Register X10 output control devices over AC powerlines using X10

EEPROM Clear: clear the bytes in the EEPROM. EEPROM Read: read the EEPROM and send its values to the computer. EEPROM Write: stores values from an analog input to the EEPROM. Stepper Library Motor Knob: control a stepper motor with a potentiometer.

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

Foundations
This page contains explanations of some of the elements of the Arduino hardware and software and the concepts behind them. Page Discussion

Basics
Sketch: The various components of a sketch and how they work.

Microcontrollers
Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs. Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. PWM: How the analogWrite() function simulates an analog output using pulse-width modulation. Memory: The various types of memory available on the Arduino board.

Arduino Firmware
Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches.

Programming Technique
Variables: How to define and use variables. Port Manipulation: Manipulating ports directly for faster manipulation of multiple pins

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

Links
Arduino examples, tutorials, and documentation elsewhere on the web.

Books and Manuals

Community Documentation
Tutorials created by the Arduino community. Hosted on the publicly-editable playground wiki. Board Setup and Configuration: Information about the components and usage of Arduino hardware. Interfacing With Hardware: Code, circuits, and instructions for using various electronic components with an Arduino board. Output Input Interaction Storage Communication

Making Things Talk (by Tom Igoe): teaches you how to get your creations to communicate with one another by forming networks of smart devices that carry on conversations with you and your environment.

Interfacing with Software: how to get an Arduino board talking to software running on the computer (e.g. Processing, PD, Flash, Max/MSP). Code Library and Tutorials: Arduino functions for performing specific tasks and other programming tutorials. Electronics Techniques: tutorials on soldering and other electronics resources.

Other Examples and Tutorials
Learn electronics using Arduino: an introduction to programming, input / output, communication, etc. using Arduino. By ladyada. Lesson 0: Pre-flight check...Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics, a simple blinking light Lesson 2: Sketches, variables, procedures and hacking code Lesson 3: Breadboards, resistors and LEDs, schematics, and basic RGB color-mixing Lesson 4: The serial library and binary data - getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches, digital inputs, pull-up and pull-down resistors, if/if-else statements, debouncing and your first contract product design. Tom Igoe's Physical Computing Site: lots of information on electronics, microcontrollers, sensors, actuators, books, etc.

Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino.

Example labs from ITP Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class 1 (getting started) class 2 (input and sensors) class 3 (communication, servos, and pwm) class 4 (piezo sound & sensors, arduino+processing, stand-alone operation) Bionic Arduino: another Arduino class from TodBot, this one focusing on physical sensing and making motion. Wiring electronics reference: circuit diagrams for connecting a variety of basic electronic components. Schematics to circuits: from Wiring, a guide to transforming circuit diagrams into physical circuits. Examples from Tom Igoe Examples from Jeff Gray

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

Arduino Tutorials
Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. For instructions on getting the board and environment up and running, see the Arduino guide.

Examples
Digital Output Blinking LED Blinking an LED without using the delay() function Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) More complex dimming/color crossfader Knight Rider example Shooting star PWM all of the digital pins in a sinewave pattern Digital Input Digital Input and Output (from ITP physcomp labs) Read a Pushbutton Using a pushbutton as a switch Read a Tilt Sensor Analog Input Read a Potentiometer Interfacing a Joystick Controlling an LED circle with a joystick Read a Piezo Sensor 3 LED cross-fades with a potentiometer 3 LED color mixer with 3 potentiometers Complex Sensors Read an Accelerometer Read an Ultrasonic Range Finder (ultrasound sensor) Reading the qprox qt401 linear touch sensor Use two Arduino pins as a capacitive sensor Sound Play Melodies with a Piezo Speaker More sound ideas Play Tones from the Serial Connection MIDI Output (from ITP physcomp labs) and from Spooky Arduino

Interfacing with Other Software
Introduction to Serial Communication (from ITP physcomp labs) Arduino + Flash Arduino + Processing Arduino + PD Arduino + MaxMSP Arduino + VVVV Arduino + Director Arduino + Ruby Arduino + C

Tech Notes (from the forums or playground)
Software serial (serial on pins besides 0 and 1) L297 motor driver Hex inverter Analog multiplexer Power supplies The components on the Arduino board Arduino build process AVRISP mkII on the Mac Non-volatile memory (EEPROM) Bluetooth Zigbee LED as light sensor (en Francais) Arduino and the Asuro robot Using Arduino from the command line

Interfacing w/ Hardware Multiply the Amount of Outputs with an LED Driver Interfacing an LCD display with 8 bits LCD interface library Driving a DC Motor with an L293 (from ITP physcomp labs). Driving a Unipolar Stepper Motor Implement a software serial connection RS-232 computer interface Interface with a serial EEPROM using SPI Control a digital potentiometer using SPI Multiple digital outs with a 595 Shift Register Multiple digital inputs with a CD4021 Shift Register

Other Arduino Examples
Example labs from ITP Examples from Tom Igoe Examples from Jeff Gray

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

Examples > Digital I/O

Blink
In most programming languages, the first program you write prints "hello world" to the screen. Since an Arduino board doesn't have a screen, we blink an LED instead. The boards are designed to make it easy to blink an LED using digital pin 13. Some (like the Diecimila and LilyPad) have the LED built-in to the board. On most others (like the Mini and BT), there is a 1 KB resistor on the pin, allowing you to connect an LED directly. (To connect an LED to another digital pin, you should use an external resistor.) LEDs have polarity, which means they will only light up if you orient the legs properly. The long leg is typically positive, and should connect to pin 13. The short leg connects to GND; the bulb of the LED will also typically have a flat edge on this side. If the LED doesn't light up, trying reversing the legs (you won't hurt the LED if you plug it in backwards for a short period of time).

Circuit

Code
The example code is very simple, credits are to be found in the comments. /* * * * * * Blinking LED -----------turns on and off a light emitting diode(LED) connected to a digital pin, in intervals of 2 seconds. Ideally we use pin 13 on the Arduino board because it has a resistor attached to it, needing only an LED

* * Created 1 June 2005 * copyleft 2005 DojoDave <http://www.0j0.org> * http://arduino.berlios.de *

* based on an orginal by H. Barragan for the Wiring i/o board */ int ledPin = 13; void setup() { pinMode(ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); } // LED connected to digital pin 13

// sets the digital pin as output

// // // //

sets the LED on waits for a second sets the LED off waits for a second

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

Examples > Digital I/O

Blink Without Delay
Sometimes you need to blink an LED (or some other time sensitive function) at the same time as something else (like watching for a button press). That means you can't use delay(), or you'd stop everything else the program while the LED blinked. Here's some code that demonstrates how to blink the LED without using delay(). It keeps track of the last time it turned the LED on or off. Then, each time through loop() it checks if a sufficient interval has passed - if it has, it turns the LED off if it was on and vice-versa.

Code

int ledPin = 13; int value = LOW; long previousMillis = 0; long interval = 1000; void setup() { pinMode(ledPin, OUTPUT); }

// // // //

LED connected to digital pin 13 previous value of the LED will store last time LED was updated interval at which to blink (milliseconds)

// sets the digital pin as output

void loop() { // here is where you'd put code that needs to be running all the time. // // // if check to see if it's time to blink the LED; that is, is the difference between the current time and last time we blinked the LED bigger than the interval at which we want to blink the LED. (millis() - previousMillis > interval) { previousMillis = millis(); // remember the last time we blinked the LED // if the if (value value = else value = LED is off turn it on and vice-versa. == LOW) HIGH; LOW;

digitalWrite(ledPin, value); } }

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

Examples > Digital I/O

Button
The pushbutton is a component that connects two points in a circuit when you press it. The example turns on an LED when you press the button. We connect three wires to the Arduino board. The first goes from one leg of the pushbutton through a pull-up resistor (here 2.2 KOhms) to the 5 volt supply. The second goes from the corresponding leg of the pushbutton to ground. The third connects to a digital i/o pin (here pin 7) which reads the button's state. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton, so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed (pressed), it makes a connection between its two legs, connecting the pin to ground, so that we read a LOW. (The pin is still connected to 5 volts, but the resistor in-between them means that the pin is "closer" to ground.) You can also wire this circuit the opposite way, with a pull-down resistor keeping the input LOW, and going HIGH when the button is pressed. If so, the behavior of the sketch will be reversed, with the LED normally on and turning off when you press the button. If you disconnect the digital i/o pin from everything, the LED may blink erratically. This is because the input is "floating" that is, it will more-or-less randomly return either HIGH or LOW. That's why you need a pull-up or pull-down resister in the circuit.

Circuit

Code
int ledPin = 13; // choose the pin for the LED int inPin = 2; // choose the input pin (for a pushbutton) int val = 0; // variable for reading the pin status void setup() { pinMode(ledPin, OUTPUT);

// declare LED as output

pinMode(inPin, INPUT); }

// declare pushbutton as input

void loop(){ val = digitalRead(inPin); // if (val == HIGH) { // digitalWrite(ledPin, LOW); } else { digitalWrite(ledPin, HIGH); } }

read input value check if the input is HIGH (button released) // turn LED OFF // turn LED ON

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

Examples > Digital I/O

Debounce
This example demonstrates the use of a pushbutton as a switch: each time you press the button, the LED (or whatever) is turned on (if it's off) or off (if on). It also debounces the input, without which pressing the button once would appear to the code as multiple presses. Makes use of the millis() function to keep track of the time when the button is pressed.

Circuit
A push-button on pin 7 and an LED on pin 13.

Code
int inPin = 7; int outPin = 13; int state = HIGH; int reading; int previous = LOW; // the number of the input pin // the number of the output pin // the current state of the output pin // the current reading from the input pin // the previous reading from the input pin

// the follow variables are long's because the time, measured in miliseconds, // will quickly become a bigger number than can be stored in an int. long time = 0; // the last time the output pin was toggled long debounce = 200; // the debounce time, increase if the output flickers void setup() { pinMode(inPin, INPUT); pinMode(outPin, OUTPUT); } void loop()

{ reading = digitalRead(inPin); // if we just pressed the button (i.e. the input went from LOW to HIGH), // and we've waited long enough since the last press to ignore any noise... if (reading == HIGH && previous == LOW && millis() - time > debounce) { // ... invert the output if (state == HIGH) state = LOW; else state = HIGH; // ... and remember when the last button press was time = millis(); } digitalWrite(outPin, state); previous = reading; }

Edit Page | Page History | Printable View | All Recent Site Changes

i < num pins. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. This example makes use of 6 LEDs connected to the pins 2 . but in fewer lines. 4..HIGH/LOW) and delay(time) . // the number of pins (i. The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way. for (i = 0. 3. Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O board.1 . it would be interesting to use the Knight Rider as a metaphor. i++) // the array elements are numbered from 0 to num pins . the length of the array) void setup() { int i.e. the slower the timing. int pins[] = { 2. one by one using only digitalWrite(pinNum. The first code example will make the LEDs blink in a sequence. Circuit Code int timer = 100. // an array of pin numbers int num_pins = 6. // The higher the number. 5.7 on the board using 220 Ohm resistors. 7 }. The second example shows how to use a for(.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Digital I/O Loop We also call this example "Knight Rider" in memory to a TV-series from the 80's where the famous David Hasselhoff had an AI machine driving his Pontiac.) construction to perform the very same thing. 6.

// set each pin as an output for (i = 0.. digitalWrite(pins[i]. LOW). } for (i = num_pins . delay(timer). delay(timer). i < num_pins. HIGH). digitalWrite(pins[i]. // turning it on. } } Edit Page | Page History | Printable View | All Recent Site Changes .. // and turning it off. i++) { // loop through each pin. OUTPUT). } void loop() { int i. LOW). digitalWrite(pins[i]. // pausing.1.pinMode(pins[i]. i--) { digitalWrite(pins[i]. i >= 0. HIGH).

analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin. By turning the shaft of the potentiometer. we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. */ int potPin = 2. and we read 0. The second goes from 5 volts to the other outer pin of the potentiometer. that value controls the rate at which an LED blinks.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Analog I/O Analog Input A potentiometer is a simple knob that provides a variable resistance. The first goes to ground from one of the outer pins of the potentiometer. In the easiest case we connect * a potentiometer to analog pin 2. giving us a different analog input. int ledPin = 13. there are 0 volts going to the pin.org> * * Turns on and off a light emitting diode(LED) connected to digital * pin 13. In this example. there are 5 volts going to the pin and we read 1023. In between. The amount of time the LED will be on and off depends on * the value obtained by analogRead(). When the shaft is turned all the way in one direction. which we can read into the Arduino board as an analog value. Circuit Code /* * AnalogInput * by DojoDave <http://www. This changes the relative "closeness" of that pin to 5 volts and ground. We connect three wires to the Arduino board. // select the input pin for the potentiometer // select the pin for the LED . When the shaft is turned all the way in the other direction.0j0. The third goes from analog input 2 to the middle pin of the potentiometer.

int val = 0. digitalWrite(ledPin. } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin). digitalWrite(ledPin. HIGH). OUTPUT). delay(val). LOW). // variable to store the value coming from the sensor void setup() { pinMode(ledPin. } // // // // // read turn stop turn stop the the the the the value from the sensor ledPin on program for some time ledPin off program for some time Edit Page | Page History | Printable View | All Recent Site Changes . delay(val).

value <= 255. void setup() { // nothing for setup } void loop() { for(value = 0 . value >=0. // waits for 30 milli seconds to see the dimming effect } for(value = 255. int ledpin = 9.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Analog I/O Fading Demonstrates the use of analog output (PWM) to fade an LED. // sets the value (range from 0 to 255) delay(30). value+=5) // fade in (from min to max) { analogWrite(ledpin. Code int value = 0. Circuit An LED connected to digital pin 9. value-=5) // fade out (from max to min) { analogWrite(ledpin. } } // variable to keep the actual value // light connected to digital pin 9 Edit Page | Page History | Printable View | All Recent Site Changes . value). value). delay(30).

We connect the black one to ground and the red one to the input. In order to see this text you can use the Arduino serial monitor. Sometimes it is possible to acquire Piezo elements without a plastic housing. and not just a plain HIGH or LOW.0j0. The other thing to remember is that Piezos have polarity.analog to digital converter. These converters read a voltage value and transform it into a value encoded digitally. it will send the string "Knock!" back to the computer over the serial port. * . In the case of the Arduino boards. what will allow us to use it as a knock sensor. that supports the functionality of reading a value between 0 and 5volts. while 1024 represents 5volts at the input of one of the six analog pins.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Analog I/O Knock Here we use a Piezo element to detect sound. The code example will capture the knock and if it is stronger than a certain threshold. In our example we are plugging the Piezo on the analog input pin number 0. in the example we have plugged it directly in the female connectors. we transform the voltage into a value in the range 0. then they will just look like a metallic disc and are easier to use as input sensors.org> * * Program using a Piezo element as if it was a knock sensor. Example of connection of a Piezo to analog pin 0 with a resistor /* Knock Sensor * by DojoDave <http://www. We also have to connect a resistor in the range of the Megaohms in parallel to the Piezo element.. 0 represents 0volts. A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones.1024. commercial devices are usually having a red and a black wires indicating how to plug it to the board. We are taking advantage of the processors capability to read analog signals through its ADC .

OUTPUT). Serial. to toggle the light threshold value to decide when the detected sound is a knock or not void setup() { pinMode(ledPin. * and toggles the LED on pin 13.arduino. statePin).* We have to basically listen to an analog pin and detect * if the signal goes over a certain threshold. } } // read the sensor and store it in the variable "val" // // // // toggle the status of the ledPin (this trick doesn't use time cycles) turn the led on or off send the string "Knock!" back to the computer.cc/en/Tutorial/Knock */ int ledPin = 13. if (val >= THRESHOLD) { statePin = !statePin. byte val = 0. int THRESHOLD = 100. // use the serial port } void loop() { val = analogRead(knockSensor). int knockSensor = 0. // // // // // led connected to control pin 13 the knock sensor will be plugged at analog pin 0 variable to store the value read from the sensor pin variable used to store the last LED status. // declare the ledPin as as OUTPUT Serial. int statePin = LOW. digitalWrite(ledPin. delay(10).println("Knock!").begin(9600). * * http://www. It writes * "knock" to the serial port if the Threshold is crossed. followed by newline short delay to avoid overloading the serial port Edit Page | Page History | Printable View | All Recent Site Changes .

Demonstrates the use of arrays.. i++) readings[i] = 0. but the slower the output will // respond to the input. calculating a running average and printing it to the computer. if (index >= NUMREADINGS) index = 0. total += readings[index]. for (int i = 0. // // // // the the the the readings from the analog input index of the current reading running total average int inputPin = 0. void setup() { Serial. Serial. // the more the readings will be smoothed. // . average = 0. readings[index] = analogRead(inputPin).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Analog I/O Smoothing Reads repeatedly from an analog input. } // initialize serial communication with computer // initialize all the readings to 0 // // // // subtract the last reading read from the sensor add the reading to the total advance to the next index // if we're at the end of the array.wrap around to the beginning // calculate the average // send it to the computer (as ASCII digits) Edit Page | Page History | Printable View | All Recent Site Changes . Circuit Potentiometer on analog input pin 0. #define NUMREADINGS 10 int int int int readings[NUMREADINGS]. } void loop() { total -= readings[index]. total = 0. index = 0.. Using a #define rather than a normal variable lets // use this value to determine the size of the readings array. Code // Define the number of samples to keep track of.. The higher the number.. index = (index + 1). i < NUMREADINGS.println(average). average = total / NUMREADINGS.begin(9600).

com> void setup() { Serial. bin: ").print(number. Serial. and binary. hexadecimal. hex: "). Serial. octal. Serial.print(". Serial.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Communication ASCII Table Demonstrates the advanced serial printing functions by generating a table of characters and their ASCII values in decimal. BIN). // prints title with ending line break Serial. Serial.zambetti. Circuit None.print(number..print(". oct: "). // first visible character '!' is #33 void loop() { Serial. // prints value unaltered.print(". BYTE). but the Arduino has to be connected to the computer. HEX).print(number). // wait for the long string to be sent delay(100). Serial. Code // ASCII Table // by Nicholas Zambetti <http://www. Serial. DEC).print(number. dec: "). } } . first will be '!' // prints value as string in decimal (base 10) // this also works // prints value as string in hexadecimal (base 16) // prints value as string in octal (base 8) // prints value as string in binary (base 2) // also prints ending line break // if printed last visible character '~' #126 .print(number. if(number == 126) { // loop forever while(true) { continue.begin(9600).println("ASCII Table ~ Character Map")..print(".println(number. OCT). // Serial. Serial. } int number = 33.

dec: 35. oct: 43. dec: 40. dec: 37. // allow some time for the Serial data to be sent } Output ASCII Table !. oct: 44. oct: 46. oct: 50.. oct: 42. hex: 25. hex: 28. bin: bin: bin: bin: bin: bin: bin: bin: 100001 100010 100011 100100 100101 100110 100111 101000 Edit Page | Page History | Printable View | All Recent Site Changes . oct: 47. oct: 45. &. // to the next character delay(100).number++. '. dec: 33.. hex: 22. dec: 38. hex: 27. . ". (. dec: 36. hex: 24. hex: 23. dec: 34. oct: 41. hex: 26. dec: 39. %. $. ~ Character Map hex: 21. #.

in this case to control the brightness of an LED.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Communication Dimmer Demonstrates the sending data from the computer to the Arduino board. OUTPUT). } } Processing Code // Dimmer . Arduino reads these bytes and uses them to set the brightness of the LED.read().available()) { // read the most recent byte (which will be from 0 to 255) val = Serial. pinMode(ledPin. Serial port. println(Serial. // check if data has been sent from the computer if (Serial. void setup() { // begin the serial communication Serial. } void loop() { byte val. Change this to . void setup() { size(256. each of which ranges from 0 to 255. println("Available serial ports:"). The data is sent in individual bytes.*. // set the brightness of the LED analogWrite(ledPin. Circuit An LED connected to pin 9 (with appropriate resistor). Mellis import processing. 150).begin(9600).sends bytes over a serial port // by David A. // Uses the first port in this list (number 0). val).serial.list()). Code int ledPin = 9.

write(mouseX). 9600). The last the communication. //port = new Serial(this. 0.list()[0]. port = new Serial(this. Arduino board. It to Serial.begin() in your 9600). // If you know the name of the port used by the Arduino board.g. you // can specify it directly like this. line(i. i < 256. "COM1". } void draw() { // draw a gradient from black to white for (int i = 0. } // write the current X-position of the mouse to the serial port as // a single byte port. Serial.// select the port corresponding to your // parameter (e. 9600) is the speed of // has to correspond to the value passed // Arduino sketch. i++) { stroke(i). 150). } Edit Page | Page History | Printable View | All Recent Site Changes . i.

com">Josh Nimoy</a>. Flash. String buff = "". .println(analogRead(0)). int[] values = new int[64]. or it can be read by Processing (see code below). You can use the Arduino serial monitor to view the sent data. delay(20). println("Available serial ports:"). Circuit An analog input connected to analog input pin 0. Serial port. println(Serial. We call this "serial" communication because the connection appears to both the Arduino and the computer as an old-fashioned serial port.serial. etc. based on Analog In by <a href="http://itp. } void loop() { Serial. import processing. even though it may actually use a USB cable.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Communication Graph A simple example of communication from the Arduino board to the computer: the value of an analog input is printed. Code void setup() { Serial.jtnimoy. void setup() { size(512. int NEWLINE = 10. } Processing Code // // // // // // // // Graph by David A. Max/MSP. PD. Mellis Demonstrates reading data from the Arduino board by graphing the values received.list()).begin(9600). // Store the last 64 values received so we can graph them.*. 256).

// Graph the stored values by drawing a lines between them. i < 63. The last // parameter (e. Change this to // select the port corresponding to your Arduino board. // If you know the name of the port used by the Arduino board. "COM1". } else { // The end of each line is marked by two characters.available() > 0) serialEvent(port. 255 . values[63] = val. for (int i = 0. } } Edit Page | Page History | Printable View | All Recent Site Changes . Serial. a carriage // return and a newline. } void draw() { background(53). // Add the received value to the array. It // has to correspond to the value passed to Serial. //port = new Serial(this. 9600) is the speed of the communication. } void serialEvent(int serial) { if (serial != NEWLINE) { // Store all the characters on the line.begin() in your // Arduino sketch. for (int i = 0. buff. i++) values[i] = values[i + 1].// Uses the first port in this list (number 0). // Clear the value of "buff" buff = "". i < 63. 255 . // Parse the String into an integer. We divide by 4 because // analog inputs go from 0 to 1023 while colors in Processing // only go from 0 to 255. int val = Integer.values[i + 1]).length()-1). 9600).parseInt(buff)/4. buff += char(serial). // Shift over the existing values to make room for the new one.read()).substring(0. i++) line(i * 8.values[i]. you // can specify it directly like this. (i + 1) * 8. while (port. buff = buff. // but we still need to strip off the carriage return. port = new Serial(this.list()[0]. We're here because we've gotten a newline. 9600).g. stroke(255).

void setup() { Serial. The data can be sent from the Arduino serial monitor. } } } Processing Code // mouseover serial // by BARRAGAN <http://people.it/h.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Communication Physical Pixel An example of using the Arduino board to receive data from the computer. LOW). PD. HIGH). if (val == 'H') { digitalWrite(outputPin.*. // created 13 May 2004 import processing.interaction-ivrea. void setup() . Code int outputPin = 13. pinMode(outputPin. Serial port.serial. } void loop() { if (Serial. or Max/MSP. int val.barragan> // Demonstrates how to send data to the Arduino I/O board. } if (val == 'L') { digitalWrite(outputPin. OUTPUT). or another program like Processing (see code below). and turns off the LED when it receives the character 'L'. In this case. in order to // turn ON a light if the mouse is over a rectangle and turn it off // if the mouse is not.available()) { val = Serial. Flash (via a serial-net proxy). the Arduino boards turns on an LED when it receives the character 'H'.read(). Circuit An LED on pin 13.begin(9600).

} rect(50. if(mouseOverRect()) { fill(#BBBBB0). The first port in the list is // port #0 and the third port in the list is port #2. } void draw() { background(#222222). println(Serial. 100).write('L'). // List all the available serial ports in the output pane.list()). port. noStroke().write('H'). // Open the port that the Arduino board is connected to (in this case #0) // Make sure to open the port at the same speed Arduino is using (9600bps) port = new Serial(this. // You will need to choose the port that the Arduino board is // connected to from this list. } // function to test if mouse is over square boolean mouseOverRect() { return ((mouseX >= 50)&&(mouseX <= 150)&&(mouseY >= 50)&(mouseY <= 150)).list()[0]. frameRate(10). } else { fill(#666660).{ size(200. port. 9600). 50. 200). 100. } // if mouse is over square // change color // send an 'H' to indicate mouse is over square // change color // send an 'L' otherwise // draw square Edit Page | Page History | Printable View | All Recent Site Changes . Serial.

. the readings from three potentiometers are used to set the red. 1.println(analogRead(redPin)). Serial. Serial. void setup() { Serial. String buff = "". Serial. gval = 0.serial. int bluePin = 2.println(analogRead(greenPin)). int rval = 0.*.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Communication Virtual Color Mixer Demonstrates one technique for sending multiple values from the Arduino board to the computer.jtnimoy. * * Created 8 February 2003 * Updated 2 April 2005 */ import processing. int greenPin = 1.println(analogRead(bluePin)). Circuit Potentiometers connected to analog input pins 0. } void loop() { Serial.begin(9600). Code int redPin = 0. Serial.print("G"). Mellis * * Created 2 December 2006 * * based on Analog In * by <a href="http://itp. bval = 0. and 2. and blue components of the background color of a Processing sketch. delay(100).print("R"). In this case. Serial. green.print("B"). } Processing Code /** * Color Mixer * by David A.com">Josh Nimoy</a>.

9600). else if (c == 'B') bval = Integer. //port = new Serial(this. // Remove it from the string buff = buff. buff. 9600).parseInt(buff). "COM1". // Print a list in case COM1 doesn't work out println("Available serial ports:"). Serial. // Uses the first available port port = new Serial(this. } void draw() { while (port. } } Edit Page | Page History | Printable View | All Recent Site Changes .int NEWLINE = 10. // Clear the value of "buff" buff = "". Serial port.list()).available() > 0) { serialEvent(port. else if (c == 'G') gval = Integer. If the // value "serial" is equal to the value for a new line. } void serialEvent(int serial) { // If the variable "serial" is not equal to the value for // a new line.charAt(0). } else { // The first character tells us which color this value is for char c = buff. // Parse the String into an integer if (c == 'R') rval = Integer. if(serial != NEWLINE) { buff += char(serial). // Discard the carriage return at the end of the buffer buff = buff. // save the value of the buffer into the variable "val". bval).list()[0]. void setup() { size(200. add the value to the variable "buff".substring(0.read()). println(Serial. 200). } background(rval.length()-1).parseInt(buff).substring(1).parseInt(buff). gval.

* * Schematic Diagram ( can't belive I drew this funky ascii schematic ) * * * +5 V * | * \ * / * \ 10K * / * \ * | * / switch 1 or 1/2 of center-off toggle or slide switch * / * | * digital pin ________+_____________/\/\/\____________ ground * | * | 200K to 1M (not critical) * / * / switch 2 or 1/2 of center-off toggle or slide switch * | * | * _____ * ___ ground * _ * */ . One downside of the scheme (there always has to be a downside doesn't there?) is that one can't tell if both buttons are pushed at the same time. The idea is that an external 200K resistor to ground will cause an input pin to report LOW when the internal (20K) pullup resistor is turned off. They are accessible from software by using the digitalWrite() function. incidentally. is to prevent a short circuit if a pesky user pushes both buttons at once. it will overwhelm the external 200K resistor and the pin will report HIGH. /* * Read_Two_Switches_On_One_Pin * Read two pushbutton switches or one center-off toggle switch with one Arduino pin * Paul Badger 2008 * From an idea in EDN (Electronic Design News) * * Exploits the pullup resistors available on each I/O and analog pin * The idea is that the 200K resistor to ground will cause the input pin to report LOW when the * (20K) pullup resistor is turned off.+5 volts in the Arduino's case) built into the Atmega chip upon which Freeduino's are based. The job of the 10K series resistor. but when the pullup resistor is turned on. * it will overwhelm the 200K resistor and the pin will report HIGH. In this case the scheme just reports that sw2 is pushed. when the pin is set to an input. This sketch exploits the pullup resistors under software control. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive. When the internal pullup resistor is turned on however.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Read Two Switches With One I/O Pin There are handy 20K pullup resistors (resistors connected internally between Arduino I/O pins and VCC .

} // both states HIGH . } else if ( stateA == 0 && stateB == 0 ){ sw1 = 0. Serial. delay(100).#define swPin 2 int stateA. int sw1. HIGH).or center-off toggle in middle // pad some spaces to format print output Edit Page | Page History | Printable View | All Recent Site Changes . } Serial. } void loop() { digitalWrite(swPin. sw2.note: no semicolon after #define // variables to store pin states // variables to represent switch states // make sure the puillup resistors are off // turn on the puillup resistors if ( stateA == 1 && stateB == 1 ){ sw1 = 1. stateB = digitalRead(swPin). stateB.switch 2 must be pushed // stateA HIGH and stateB LOW // no switches pushed . stateA = digitalRead(swPin). void setup() { Serial.switch 1 must be pushed // both states LOW . digitalWrite(swPin.begin(9600). LOW). position sw2 = 0. Serial.println(sw2). } else{ sw1 = 0.print(sw1). sw2 = 0.print(" "). // pin for input . sw2 = 1.

but you'll need to make sure that the inputPin variable in the code matches the digital pin you're using on the Arduino board. The prototyping board has been populated with a 1K resitor to make the pull-up and the sensor itself. The hardware was mounted and photographed by Anders Gran. We have chosen the tilt sensor from Assemtech. It contains a metallic ball inside that will commute the two pins of the device from on to off and viceversa if the sensor reaches a certain angle. Edit Page | Page History | Printable View | All Recent Site Changes . the software comes from the basic Arduino examples. Circuit Picture of a protoboard supporting the tilt sensor. which datasheet can be found here. We use a pull-up resistor (thus use active-low to activate the pins) and connect the sensor to a digital input pin that we will read when needed. This type of sensor is the environmental-friendly version of a mercuryswitch. by Anders Gran Code Use the Digital > Button example to read the tilt-sensor. However it is only the equivalent to a pushbutton activated through a different physical mechanism. The code example is exactly as the one we would use for a pushbutton but substituting this one with the tilt sensor.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Tilt Sensor The tilt sensor is a component that can detect the tilting of an object.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Controlling a circle of LEDs with a Joystick The whole circuit: Detail of the LED wiring .

Then. (See figure below). To each piece will correspond an LED. As you can see looking to the joystick is that the space in which he moves is a circle. the program always lights up the LED corresponding to the pie in which the joystick is. when the joystick gives us a coordinate. it will necesarilly belong to one of the pies. The only thing we need now to understand is that we have divided our Pie in 8 pieces. This circle will be from now on our 'Pie' (see bottom right of the first image).Detail of the arduino wiring How this works As you know from the Interfacing a Joystick tutorial. the joystick gives a coordinate (x. This way.y) back to arduino. .

// Array of 8 leds mounted in ledVerde = 13. // slider variable connecetd to analog coordX = 0.9 }.4.5. // variable to read the value from the a circle the leds pin 0 pin 1 analog pin 0 analog pin 1 . // variable to read the value from the coordY = 0.3.y) * * Finally it ligths up the LED which is placed in the * detected zone * * @authors: Cristina Hoffmann and Gustavo Jose Valera * @hardware: Cristina Hofmann and Gustavo Jose Valera * @context: Arduino Workshop at medialamadrid */ // Declaration of Variables int int int int int int int ledPins [] = { 2.8. // Time you should wait for turning on joyPin1 = 0.6.y) * * The program then calculates to which of the 8 * possible zones belogns the coordinate (x. // slider variable connecetd to analog joyPin2 = 1. espera = 40.Code /* Controle_LEDcirle_with_joystik * -----------* This program controles a cirle of 8 LEDs through a joystick * * First it reads two analog pins that are connected * to a joystick made of two potentiometers * * This input is interpreted as a coordinate (x.7.

int x2. cy int calculateZone (int x. previousZone = 0. } else // fourth cuadrant { if (alpha > -1) return 6.y. int y1. int y. pinMode (ledVerde. centerY = 500. // slope of the segment betweent the point and the center if (x > cx) { if (y > cy) // first cuadrant { if (alpha > 1) // The slope is > 1. } } // function that calculates the slope of the line that passes through the points // x1. OUTPUT). int y2) { return ((y1-y2) / (x1-x2)). } // function that calculates in which of the 8 possible zones is the coordinate x y. for (i=0. } } else { if (y < cy) // third cuadrant { if (alpha > 1) return 4. actualZone = 0. OUTPUT). else return 7. i< 8. // Otherwise the point is in the lower part of the first quadrant } else // second cuadrant { if (alpha > -1) return 2. } } } . int cx. else return 1. given the center cx. i++) { pinMode(ledPins[i]. thus higher part of the first quadrant return 0. y1 and x2. // we measured the value for the center of the joystick // Asignment of the pins void setup() { int i. else return 5. else return 3. cx. beginSerial(9600). y2 int calculateSlope(int x1. int cy) { int alpha = calculateSlope(x.cy).int int int int centerX = 500.

serialWrite(32). } @idea: Cristina Hoffmann and Gustavo Jose Valera @code: Cristina Hoffmann and Gustavo Jose Valera @pictures and graphics: Cristina Hoffmann @date: 20051008 . serialWrite('Z'). serialWrite(10). // print space printInteger(actualZone). centerY). // We calculate in which x actualZone = calculateZone(coordX. you can erase this if you want // reads the value of the variable resistors coordX = analogRead(joyPin1). // print space printInteger(coordY). serialWrite(32). //This is not necesary for a standalone version serialWrite('C'). // we print int the terminal. digitalWrite (ledPins[actualZone]. serialWrite(32). LOW). don't delete it! previousZone = actualZone. serialWrite(13). coordY = analogRead(joyPin2). // But this is necesary so. serialWrite(10). coordY. the cartesian value of the coordinate. // print space printInteger(coordX). and the zone where it belongs.void loop() { digitalWrite(ledVerde. HIGH). // flag to know we entered the loop.Madrid . // delay (500). centerX. HIGH). serialWrite(13).Spain Edit Page | Page History | Printable View | All Recent Site Changes . if (actualZone != previousZone) digitalWrite (ledPins[previousZone].

) * * Put 220 Ohm resistors in line with pots. * * When you mix a color you like. // Set to 1 to turn on debugging output void setup() { pinMode(aOut. // Values int aVal = 0. Green. // sets the digital pins as output . to prevent small changes in // pot values from triggering false reporting // FLAGS int PRINT = 1. Red + Blue + White would let you mix shades of red. and 2 1. as it uses Serial. to prevent circuit from * grounding out when the pots are at zero */ // Analog int aIn = int bIn = int cIn = // Digital int aOut = int bOut = int cOut = pin settings 0. and Blue. * The mix values that create that color will be reported via serial out. or placed in a paper coffee cup with a cut-out bottom and * a white plastic lid). // Sensitivity theshold. the colors will mix together.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » /* * "Coffee-cup" Color Mixer: * Code for mixing and reporting PWM-mediated color * Assumes Arduino 0004 or higher. // Delay between most recent pot adjustment and output int checkSum = 0. 10 and 11 10. * * Standard colors for light mixing are Red. green. // Loop counter int wait = (1000). stop adjusting the pots. // LEDs connected to digital pins 9. or blue-green. // Variables to store the input from the potentiometers // Variables for comparing values between loops int i = 0. int bVal = 0. * blue. OUTPUT). // Set to 1 to output values int DEBUG = 1. // (Connect power to 5V and ground to analog ground) 2. 1. and are directed at diffusing surface (stuck in a * a Ping-Pong ball. and purple (though no yellow. // Potentiometers connected to analog pins 0. though you can mix * with any three colors. pin settings 9. // (Connect cathodes to digital ground) 11. int sens = 3. int cVal = 0. orange. // Aggregate pot values int prevCheckSum = 0.begin()-style communication * * Control 3 LEDs with 3 potentiometers * If the LEDs are different colors.

PRINT = 0.. // Count loop // Open serial communication for reporting aVal = analogRead(aIn) / 4. OUTPUT).print(checkSum). Serial.print(bVal). bVal = analogRead(bIn) / 4.print("<=>"). { Serial. Serial..pinMode(bOut. } void loop() { i += 1.print("A: ").prevCheckSum) > sens ) // If old and new values differ // above sensitivity threshold { if (PRINT) // .println(cVal).print(aVal).then print the values.. Serial.print("C: ").begin(9600). Serial. // .print("\tPrint: ").. // Re-set the flag } prevCheckSum = checkSum.. analogWrite(aOut. // Update the values if (DEBUG) // If we want debugging output as well. Serial... { checkSum = aVal+bVal+cVal. aVal).. { Serial.print("B: "). } } else { PRINT = 1. Serial. } } } Edit Page | Page History | Printable View | All Recent Site Changes . analogWrite(cOut. Serial. if ( abs(checkSum . Serial. pinMode(cOut.add up the 3 values. // . Serial.print("\t").println(PRINT). Serial. analogWrite(bOut. Serial..and if the PRINT flag is set. bVal). cVal). // read input pins. convert to 0-255 scale // Send new values to LEDs if (i % wait == 0) // If enough time has passed.print("\t")..print(prevCheckSum). cVal = analogRead(cIn) / 4.. OUTPUT).. Serial.

HIGH). long interval = 100. pullup resistors. long previousMillis = 0. int fractional. INPUT). // sets the digital pin as output // not really necessary. ground. // LED connected to digital pin 13 // button on pin 4 // // // // // // // // // previous value of the LED variable to store button state variable to store last button state condition for blinking . // store the start time // turn on blinking while timing . pins default to INPUT anyway // turn on pullup resistors. Wire button so that press shorts pin to // read the button state and store if (buttonState == LOW && lastButtonState == HIGH && blinking == false){ // check for a high to low transition // if true then found a new button press while clock is not running . int buttonState. printing fractions * * Physical setup: momentary switch connected to pin 4. OUTPUT). int lastButtonState. digitalWrite(buttonPin. other side connected to ground * LED with series resistor between pin 13 and ground */ #define ledPin 13 #define buttonPin 4 int value = LOW.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Stopwatch A sketch that demonstrates how to do two (or more) things at once by using millis(). blinking = true. long startTime . * making two things happen at once.change to suit variable to store last time LED was updated start time for stop watch elapsed time for stop watch variable used to store fractional part of time void setup() { Serial.begin(9600).start the clock startTime = millis(). /* StopWatch * Paul Badger 2008 * Demonstrates using millis(). int blinking. pinMode(ledPin. pinMode(buttonPin.timer is timing blink interval . long elapsedTime . } void loop() { // check for button press buttonState = digitalRead(buttonPin).

compare next time } // // // // // divide by 1000 to convert to seconds . that is. of time Serial. } } } // remember the last time we blinked the LED // turn off LED when not blinking Edit Page | Page History | Printable View | All Recent Site Changes .print( (int)(elapsedTime / 1000L) ). to else if (buttonState == LOW && lastButtonState == HIGH && blinking == true){ // check for a high to low transition // if true then found a new button press while clock is running . if ( (millis() . Fix this as a coding exercise.stop the clock and report elapsedTime = millis() .println(fractional). fractional = (int)(elapsedTime % 1000L). digitalWrite(ledPin. if (value == LOW) value = HIGH. compare next time } // short delay to debounce switch // store buttonState in lastButtonState.delay(5). value). } else{ digitalWrite(ledPin. LOW).startTime.then // print decimal point // use modulo operator to get fractional part // print fractional part of time // store buttonState in lastButtonState. blinking = false. else value = LOW. all done timing // store buttonState in lastButtonState. is the difference between the current time and last time we blinked the LED bigger than the interval at which we want to blink the LED. } else{ lastButtonState = buttonState. lastButtonState = buttonState. to blink routine . // if the LED is off turn it on and vice-versa. lastButtonState = buttonState. cast to an int to print Serial.previousMillis > interval) ) { if (blinking == true){ previousMillis = millis()."). Serial. compare next time // store elapsed time // turn off blinking. to // routine to report elapsed time .print(".blink the LED while timing check to see if it's time to blink the LED.this breaks when delays are in single or double digits.

The ADXL3xx outputs the acceleration on each axis as an analog voltage between 0 and 5 volts. // // // // // analog analog x-axis y-axis z-axis input pin 4 input pin 5 of the accelerometer (only on 3-axis models) . ADXL321. ADXL320. which is read by an analog input on the Arduino. Pinout for the above configuration: Breakout Board Pin Self-Test Z-Axis Y-Axis X-Axis Ground VDD 1 2 3 4 5 Arduino Analog Input Pin 0 Or. xpin = 3. powerpin = 19. The pins used are designed to be easily compatible with the breakout boards from Sparkfun. ADXL322.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Analog I/O ADXL3xx Accelerometer Reads an Analog Devices ADXL3xx series (e. Circuit An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino. zpin = 1. if you're using just the accelerometer: ADXL3xx Pin Self-Test Arduino Pin ZOut YOut XOut Ground VDD 5V None (unconnected) Analog Input 1 Analog Input 2 Analog Input 3 GND Code int int int int int groundpin = 18. ADXL330) accelerometer and communicates the acceleration to the computer.g. ypin = 2.

LOW).g.void setup() { Serial. digitalWrite(powerPin. With the axis horizontal (i. digitalWrite(groundPin. pinMode(groundPin. you can remove these lines.e. pinMode(powerPin.begin(9600). Serial. OUTPUT). If you use the normal 5V and // GND pins on the Arduino. the ADXL302 5g one). but values at other angles will be different for a different accelerometer (e. Angle -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 Acceleration 662 660 654 642 628 610 589 563 537 510 485 455 433 408 390 374 363 357 355 Edit Page | Page History | Printable View | All Recent Site Changes . } Data Here are some accelerometer readings collected by the positioning the y-axis of an ADXL322 2g accelerometer at various angles from ground.println(). Serial. parallel to ground or 0°). Serial. delay(1000). This makes it possible to directly connect the // breakout board to the Arduino.print(" "). // Provide ground and power by using the analog inputs as normal // digital pins. Serial. Serial. } void loop() { Serial. HIGH).print(" "). OUTPUT).print(analogRead(zpin)).print(analogRead(ypin)). but will vary based on the sensitivity of the device. the accelerometer reading should be around 512.print(analogRead(xpin)). Values should be the same for the other axes.

Malmo University . only the two axis pins are plugged to the board. while the the temperature should be taken as an analog input. at the University of Zaragoza. who is Arduino's accelerometer technology researcher. picture by Anders Gran * * * * * * * * * * * /* Accelerometer Sensor -------------------Reads an 2-D accelerometer attached to a couple of digital inputs and sends their values over the serial port.org copyleft 2005 K3 . The board is connected minimally. The acceleration pins send the signals back to the computer in the form of pulses which width represents the acceleration. The pins dedicated to measure acceleration can be connected directly to digital inputs to the Arduino board. Spain. When making very accurate measurements. leaving the temperature pin open. Protoboard with an Accelerometer. while the software was created by Marcos Yarza.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Memsic 2125 Accelerometer The Memsic 2125 is a dual axis accelerometer sensor from Parallax able of measuring up to a 2g acceleration.Sweden @author: Marcos Yarza . The example shown here was mounted by Anders Gran. makes the monitor LED blink once sent http://www.0j0. the sensor counts with a temperature pin that can be used to compensate possible errors.

} . } timer = count * 18. pinMode(xaccPin. char sign = ' '. int count = 0. int yaccPin = 6. INPUT). } while(value == LOW) { // Loop until pin reads a high value = digitalRead(axe). int timer = 0. // Sets the baud rate to 9600 pinMode(ledPin. pinMode(yaccPin. } /* (int) Operate Acceleration * function to calculate acceleration * returns an integer */ int operateAcceleration(int time1) { return abs(8 * (time1 / 10 . INPUT). } /* (void) readAccelerometer * procedure to read the sensor. int xaccPin = 7. } if (timer < 5000){ sign = '-'. OUTPUT). value = digitalRead(axe).* @hardware: Marcos Yarza * @project: SMEE . count = 0. } while(value == HIGH) { // Loop until pin reads a low and count value = digitalRead(axe). //Represent acceleration over serial port if (axe == 7){ printByte('X'). //calculate the teme in miliseconds //operate sign if (timer > 5000){ sign = '+'. int accel = 0. void setup() { beginSerial(9600).Experiential Vehicles * @sponsor: Experiments in Art and Technology Sweden. 1:1 Scale */ int ledPin = 13. while(value == HIGH) { // Loop until pin reads a low value = digitalRead(axe).500)). count = count + 1. int value = 0. } //determine the value accel = operateAcceleration(timer). calculate * acceleration and represent the value */ void readAcceleration(int axe){ timer = 0.

The board chosen for this small circuit is just a piece of prototyping board. } printByte(sign). printByte(' '). } void loop() { readAcceleration(xaccPin).else { printByte('Y'). Edit Page | Page History | Printable View | All Recent Site Changes . printInteger(accel). HIGH). Yarza The following example is an adaptation of the previous one. LOW). delay(300). Here the code is exactly the same as before (changing the input pins to be 2 and 3). Marcos Yarza added two 220Ohm resistors to the pins coming out of the accelerometer. but the installation on the board allows to embed the whole circutry in a much smaller housing. //reads and represents acceleration Y digitalWrite(ledPin. by M. //reads and represents acceleration X readAcceleration(yaccPin). digitalWrite(ledPin. } Accelerometer mounted on prototyping board.

xlab.se | http://www. // Ultrasound signal pin . while the third one is used both as input and output. The width of that pulse will determine the distance to the object. The sensor counts with 3 pins. Once the tone is received back. while the software was created by David Cuartielles. First we have to send a pulse that will make the sensor send an ultrasound tone and wait for an echo.0 /* Ultrasound Sensor *-----------------* * Reads values (00014-01199) from an ultrasound sensor (3m sensor) * and writes the values to the serialport. the sensor will send a pulse over the same pin as earlier.org * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp * */ int ultraSoundSignal = 7.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » PING range finder The PING range finder is an ultrasound sensor from Parallax able of detecting objects up to a 3 mts distance. two are dedicated to power and ground. The example shown here was mounted by Marcus Hannerstig.0j0. The pin dedicated to make the readings has to be shifting configuration from input to output according to the PING specification sheet. The board is connected as explained using only wires coming from an old computer. Ultrasound sensor connected to an Arduino USB v1. * * http://www.

val = 0. INPUT). } // Sets the baud rate to 9600 // Sets the digital pin as output void loop() { timecount = 0. // Append signal value to val while(val == LOW) { // Loop until pin reads a high value val = digitalRead(ultraSoundSignal). // LED connected to digital pin 13 void setup() { beginSerial(9600). serialWrite(13). // Append echo pulse time to ultrasoundValue serialWrite('A'). } while(val == HIGH) { // Loop until pin reads a high value val = digitalRead(ultraSoundSignal).int int int int val = 0. delayMicroseconds(5). // Count echo pulse time } /* Writing out values to the serial port * ------------------------------------------------------------------*/ ultrasoundValue = timecount. timecount = 0. /* Lite up LED if any value is passed by the echo pulse * ------------------------------------------------------------------*/ if(timecount > 0){ digitalWrite(ledPin. HIGH). pinMode(ledPin. // Send high pulse for 5 microseconds LOW). // Send low pulse for 2 microseconds HIGH). pinMode(ultraSoundSignal. timecount = timecount +1. // Example identifier for the sensor printInteger(ultrasoundValue). LOW). delayMicroseconds(2). // Switch signalpin to output /* Send low-high-low pulse to activate the trigger pulse of the sensor * ------------------------------------------------------------------*/ digitalWrite(ultraSoundSignal. // Holdoff /* Listening for echo pulse * ------------------------------------------------------------------*/ pinMode(ultraSoundSignal. // Wait digitalWrite(ultraSoundSignal. ultrasoundValue = 0. OUTPUT). // Switch signalpin to input val = digitalRead(ultraSoundSignal). } /* Delay of program * ------------------------------------------------------------------*/ delay(100). // Echo counter ledPin = 13. serialWrite(10). OUTPUT). // Wait digitalWrite(ultraSoundSignal. } .

Edit Page | Page History | Printable View | All Recent Site Changes .

INPUT). pinMode(qt401_prx. pinMode(qt401_det. // = 3. OUTPUT).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » qt401 sensor full tutorial coming soon /* qt401 demo * -----------* * the qt401 from qprox http://www. pinMode(qt401_clk. } // . OUTPUT).com is a linear capacitive sensor * that is able to read the position of a finger touching the sensor * the surface of the sensor is divided in 128 positions * the pin qt401_prx detects when a hand is near the sensor while * qt401_det determines when somebody is actually touching the sensor * these can be left unconnected if you are short of pins * * read the datasheet to understand the parametres passed to initialise the sensor * * Created January 2006 * Massimo Banzi http://www. digitalWrite(qt401_ss. HIGH). pinMode(qt401_di. pinMode(qt401_do. // = 4. // data ready data in (from sensor) slave select clock data out (to sensor) detect proximity byte result. void qt401_init() { // define pin directions pinMode(qt401_drd. INPUT). // = 5. OUTPUT).potemkin. // initialise pins digitalWrite(qt401_clk.qprox. INPUT). pinMode(qt401_ss. INPUT).org * * based on C code written by Nicholas Zambetti */ // define pin int qt401_drd int qt401_di int qt401_ss int qt401_clk int qt401_do int qt401_det int qt401_prx mapping = 2.HIGH). // = 7. // = 8. // = 6.

LOW). // send 1 } else{ digitalWrite(qt401_do. // now read a bit coming from the sensor if(digitalRead(qt401_di)){ data_in |= mask. digitalWrite(qt401_ss. // send 0 } // lower clock pin.LOW). byte data_in = 0.HIGH). } // give the sensor some time to think . // tick // give the sensor time to read the data delayMicroseconds(75). byte mask = 0. // bring clock back up digitalWrite(qt401_clk. //wait for 75 microseconds while(0 < i) { mask = 0x01 << --i. this tells the sensor to read the bit we just put out digitalWrite(qt401_clk. // tock // give the sensor some time to think delayMicroseconds(20). } } // // // exchange a byte with the sensor byte qt401_transfer(byte data_out) { byte i = 8. // generate bitmask for the appropriate bit MSB first // set out byte if(data_out & mask){ // choose bit digitalWrite(qt401_do. // select slave by lowering ss pin delayMicroseconds(75).LOW).HIGH).// wait for the qt401 to be ready // void qt401_waitForReady(void) { while(!digitalRead(qt401_drd)){ continue.

} void qt401_calibrate(void) { // calibrate qt401_waitForReady(). qt401_calibrate().HIGH). delay(600). } delayMicroseconds(75). } void setup() { //setup the sensor qt401_init(). beginSerial(9600). qt401_setProxThreshold(10). return qt401_transfer(0x03). // calibrate ends qt401_waitForReady(). qt401_setTouchThreshold(10). delay(600). qt401_transfer(0x01). } void qt401_setTouchThreshold(byte amount) { qt401_waitForReady(). qt401_transfer(0x02). return qt401_transfer(0x00). // give the sensor some time to think digitalWrite(qt401_ss. } . qt401_transfer(0x40 & (amount & 0x3F)).delayMicroseconds(20). } byte qt401_driftCompensate(void) { qt401_waitForReady(). // do acquisition burst return data_in. qt401_transfer(0x80 & (amount & 0x3F)). } byte qt401_readSensor(void) { qt401_waitForReady(). } void qt401_setProxThreshold(byte amount) { qt401_waitForReady().

if(0x80 & result){ result = result & 0x7f. printNewline().void loop() { if(digitalRead(qt401_det)){ result = qt401_readSensor(). printInteger(result). } } } Edit Page | Page History | Printable View | All Recent Site Changes .

while the second one will make use of the PWM functionality to control the volume through changing the Pulse Width. We connect the black one to ground and the red one to the output. The first example of the code will just send a square wave to the piezo. then they will just look like a metallic disc.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Play Melody This example makes use of a Piezo Speaker in order to play melodies. to create signature frequencies. We are taking advantage of the processors capability to produde PWM signals in order to play music. commercial devices are usually having a red and a black wires indicating how to plug it to the board. and not just a plain HIGH or LOW value. . Example of connection of a Piezo to pin 9 Example 1: Play Melody /* * * * * * * Play Melody ----------Program to play a simple melody Tones are created by quickly pulsing a speaker on and off using PWM. Sometimes it is possible to acquire Piezo elements without a plastic housing. that supports the functionality of writing a PWM signal to it. There is more information about how PWM works written by David Cuartielles here and even at K3's old course guide A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. In our example we are plugging the Piezo on the pin number 9. The other thing to remember is that Piezos have polarity.

//<-BLETCHEROUS HACK. g. Cuartielles for K3 * Refactoring and comments 2006 clay.edu * See NOTES in comments at end for possible improvements */ // TONES ========================================== // Start by defining the relationship between // note. to represent a rest #define R 0 // SETUP ============================================ // Set up speaker on a PWM pin (digital 9. then LOW * for 'pulse-width' microseconds. period. b. longer note) int melody[] = { C. 8. // Do we want debugging on serial out? 1 for yes.shirky@nyu. we pulse * the speaker HIGH for 'pulse-width' microseconds. void setup() { pinMode(speakerOut. for looping. b. // Melody length. accompanied by beats[]. // PLAY TONE ============================================== // Pulse the speaker to play a tone for a particular duration void playTone() { long elapsed time = 0. See NOTES // Initialize core variables int tone = 0. // Set serial out if we want debugging } } // MELODY and TIMING ======================================= // melody[] is an array of notes. 16. measured in microseconds. a. 8 }. 16. 10 or 11) int speakerOut = 9. * This pulsing creates a vibration of the desired frequency. R. long duration = 0. We'll use pulse-width * modulation (PWM) to create that vibration. 8. int beats[] = { 16. C. 0 for no int DEBUG = 1. g. 16. & frequency. 32. int beat = 0. . 16. // which sets each note's relative length (higher #. // Loop variable to increase Rest length int rest_count = 100. // Set length of pause between notes int pause = 1000. created by varying the period of * vibration. // Set overall tempo long tempo = 10000. 16. C }. 8. 'R'. 16. e. #define c 3830 // 261 Hz #define d 3400 // 294 Hz #define e 3038 // 329 Hz #define f 2864 // 349 Hz #define g 2550 // 392 Hz #define a 2272 // 440 Hz #define b 2028 // 493 Hz #define C 1912 // 523 Hz // Define a special note. c. int MAX_COUNT = sizeof(melody) / 2. OUTPUT). C.begin(9600).* * Each note has a frequency. * We calculate the pulse-width to be half the period. * * (cleft) 2005 D. if (DEBUG) { Serial.

i++) { tone = melody[i]. } } else { // Rest beat. beat = beats[i]. delayMicroseconds(tone / 2).' rest_count creates a loop variable to bring 'rest' beats in line with 'tone' beats of the same length.HIGH).print(tone). beat. _plus_ any overhead created by incremeting elapsed_time (could be in excess of 3K microseconds) _plus_ overhead of looping and two digitalWrites() As a result. // Keep track of how long we pulsed elapsed_time += (tone).if (tone > 0) { // if this isn't a Rest beat. if (DEBUG) { // If debugging. while the tone has // played less long than 'duration'. delayMicroseconds(tone / 2).. Serial. tone. Serial. Serial. as well as overhead from any program mods. pulse speaker HIGH and LOW while (elapsed_time < duration) { digitalWrite(speakerOut. Lies lies lies! It holds for at least 'duration' microseconds. and duration Serial. duration = beat * tempo. } } } /* * * * * * * * * * * * * * * * * NOTES The program purports to hold a tone for 'duration' microseconds. report loop. j++) { // See NOTE on rest_count delayMicroseconds(duration).print(":"). Serial. // Set up timing playTone(). i<MAX_COUNT. Serial. // A pause between notes. rest_count will be affected by chip architecture and speed.print(i).print(" "). Light fuse and get away. LOW)..println(duration). // DOWN digitalWrite(speakerOut.print(" "). Your mileage may vary. Past behavior is no guarantee of future performance. This could use a number of enhancements: ADD code to let the programmer specify how many times the melody should . } } } // LET THE WILD RUMPUS BEGIN ============================= void loop() { // Set up a counter to pull from melody[] and beats[] for (int i=0. Serial. a tone of 'duration' plays much more slowly than a rest of 'duration. j < rest_count.print(beat). loop times delay for (int j = 0. delayMicroseconds(pause).

int count2 = 0. OUTPUT). 0).arduino. for (count = 0. 1014. byte names[] = {'c'. 'd'. with volume control set using analogWrite() /* Play Melody * ----------* * Program to play melodies stored in an array. 'g'. pause. count3 <= (melody[count*2] . count++) { statePin = !statePin. 1432. byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". for (count3 = 0. 'f'. int count3 = 0. * * The calculation of the tones is made following the mathematical * operation: * * timeHigh = 1/(2 * toneFrequency) = period / 2 * * where the different tones are described as in the table: * * note frequency period PW (timeHigh) * c 261 Hz 3830 1915 * d 294 Hz 3400 1700 * e 329 Hz 3038 1519 * f 349 Hz 2864 1432 * g 392 Hz 2550 1275 * a 440 Hz 2272 1136 * b 493 Hz 2028 1014 * C 523 Hz 1912 956 * * (cleft) 2005 D. digitalWrite(ledPin. } void loop() { analogWrite(speakerOut.48) * 30. 'a'. and rest_count to #define statements * RE-WRITE to include volume. 'e'. // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0. 1136. 'b'. Cuartielles for K3 */ int ledPin = 13. int MAX_COUNT = 24. 1700. count3++) { . 1275. 956}.) * ADD code to create a tone offset (higer or lower) through pot etc * REPLACE random melody with opening bars to 'Smoke on the Water' */ Second version.cc/en/Tutorial/PlayMelody * ADD code to make the tempo settable by pot or other input device * ADD code to take tempo or volume settable by serial communication * (Requires 0005 or higher. as with the second program at * http://www.* loop before stopping * ADD another octave * MOVE tempo. using analogWrite. 1519. statePin). void setup() { pinMode(ledPin. 'C'}. count < MAX_COUNT. int speakerOut = 9. int tones[] = {1915. int statePin = LOW. it requires to know * about timing issues and about how to play tones.

delayMicroseconds(500). delayMicroseconds(tones[count2]).count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. analogWrite(speakerOut. } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut. delayMicroseconds(tones[count2]). 0).count2<8.for (count2=0.500). 0). } } } } } Edit Page | Page History | Printable View | All Recent Site Changes .

It is possible to daisy chain this chip increasing the total amount of LEDs by 8 each time.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » LED Driver This example makes use of an LED Driver in order to control an almost endless amount of LEDs with only 4 pins. We use the 4794 from Philips. There is more information about this microchip that you will find in its datasheet. stored in "dato" on a set of 8 LEDs * * (copyleft) 2005 K3. if dato is 255 all the LEDs will light up. only the first LED will light up. Malmo University * @author: David Cuartielles. int strob = 8. E. The code example you will see here is taking a value stored in the variable dato and showing it as a decoded binary number. if dato is 1. Marcos Yarza * @project: made for SMEE . Marcus Hannerstig * @hardware: David Cuartielles. Example of connection of a 4794 /* Shift Out Data * -------------* * Shows a byte.g. An LED Driver has a shift register embedded that will take data in serial format and transfer it to parallel.Experiential Vehicles */ int data = 9. .

} void PulseClock(void) { digitalWrite(clock.int int int int clock = 10. HIGH). count < 8. pinMode(strob. delay(100). digitalWrite(clock. //serialWrite((dato & 01) + 48). dato & 01). pinMode(oe. HIGH). serialWrite(13). } PulseClock(). pinMode(clock. HIGH). serialWrite(10). LOW). digitalWrite(oe. count = 0. digitalWrite(strob. if (count == 7){ digitalWrite(oe. delayMicroseconds(20). oe = 11. dato = 0. void setup() { beginSerial(9600). OUTPUT). digitalWrite(clock. OUTPUT). dato>>=1. digitalWrite(strob. OUTPUT). delay(100). OUTPUT). for (count = 0. } delayMicroseconds(20). count++) { digitalWrite(data. } void loop() { dato = 5. LOW). LOW). pinMode(data. } // waits for a moment Edit Page | Page History | Printable View | All Recent Site Changes . LOW). delayMicroseconds(50).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » LCD Display . The backdrop of this example is that we are using almost all the available pins on Arduino board in order to drive the display. LCD displays are most of the times driven using an industrial standard established by Hitachi. DB0.. the user can choose to use 4 or 8 pins to send data. Picture of a protoboard supporting the display and a potentiometer /* * * * * * * * * * * * * LCD Hola -------This is the first example in how to use an LCD screen configured with data transfers over 8 bits. but can easily display data on the display There are the following pins to be considered: . Therefore we will use a potentiometer to regulate the contrast.DB7. Enable (11 in total) the pinout for LCD displays is standard and there is plenty . The example uses all the digital pins on the Arduino board. RW. In our case we have an LCD display with backlight and contrast control. but we have decided to show it this way for simplicity.DI.8 bits This example shows the most basic action to be done with a LCD display: to show a welcome message. According to it there is a group of pins dedicated to sending data and locations of that data on the screen. On top of that three more pins are needed to synchronize the communication towards the display.

LOW). delayMicroseconds(1). 5x7 font display shift . delayMicroseconds(1). 5x7 font lines. LcdCommandWrite(0x06). value >>= 1. // function set: // 8-bit interface. LcdCommandWrite(0x30). HIGH). 10}. 6.HIGH). // pause 1 ms according to datasheet } void LcdDataWrite(int value) { // poll all the pins int i = 0.LOW). // initiatize lcd after a short pause // needed by the LCDs controller LcdCommandWrite(0x30). i <= DI. // send a pulse to enable digitalWrite(Enable.LOW). for (i=DB[0]. delayMicroseconds(1). 4.LOW). i <= DI. i++) { pinMode(i. value >>= 1. DB[] = {3. no delay(20).OUTPUT). for (i=Enable. 5x7 font lines. i <= DB[7]. // pause 1 ms according to datasheet } void setup (void) { int i = 0. // function set: // 8-bit interface. 7.value & 01). 5. 1 display delay(50). 8. delayMicroseconds(1). LcdCommandWrite(0x30). 9. digitalWrite(DI. for (i=DB[0]. void LcdCommandWrite(int value) { // poll all the pins int i = 0. i++) { digitalWrite(i. digitalWrite(RW. } delay(100). Enable = 2. RW = 11. 1 display delay(64). lines.* of documentation to be found on the internet.HIGH). } digitalWrite(Enable. // entry mode set: // increment automatically. * * (cleft) 2005 DojoDave for K3 * */ int int int int DI = 12. delayMicroseconds(1). // send a pulse to enable digitalWrite(Enable.value & 01). // pause 1 ms according to datasheet digitalWrite(Enable. 1 display delay(20). i++) { digitalWrite(i. delayMicroseconds(1).LOW). digitalWrite(Enable. } digitalWrite(Enable. // function set: // 8-bit interface.

LcdDataWrite('r'). } // display control: // turn display on. LcdDataWrite('o'). LcdDataWrite('o'). cursor on. delay(20). no blinking // clear display. // Write the welcome message LcdDataWrite('H'). delay(20).LcdCommandWrite(0x0E). cursor on. LcdDataWrite('a'). LcdCommandWrite(0x01). LcdDataWrite(' '). delay(500). no blinking void loop (void) { LcdCommandWrite(0x02). LcdDataWrite('l'). LcdDataWrite('l'). LcdDataWrite('C'). LcdDataWrite('c'). LcdDataWrite('a'). } Edit Page | Page History | Printable View | All Recent Site Changes . delay(100). set cursor position to zero // display control: // turn display on. // set cursor position to zero delay(10). LcdDataWrite('a'). LcdDataWrite('a'). LcdCommandWrite(0x80).

Insert the LCD header into the breadboard and connect power and ground on the breadboard to power and ground from the microcontroller. and to send commands directly to the HD44780 chip. Unzip the files and place the whole LiquidCrystal folder inside your arduino-0004\lib\targets\libraries folder. to clear the screen. Start the Arduino program and check to make sure LiquidCrystal is now available as an option in the Sketch menu under "Import Library". Prepare the breadboard Solder a header to the LCD board if one is not present already. to print characters and strings.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Arduino Liquid Crystal Library LCD Interface In this tutorial you will control a Liquid Crystal Display (LCD) using the Arduino LiquidCrystal library. such as those available from Sparkfun. use the 5V and any of the ground connections. . Functions are provided to initialize the screen.optional. This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions. Materials needed: Solderless breadboard Hookup wire Arduino Microcontoller Module Potentiometer Liquid Crystal Display (LCD) with HD44780 chip interface Light emitting Diode (LED) . On the Arduino module. It currently implements 8-bit control and one line display of 5x7 characters. for debugging Install the Library For a basic explanation of how libraries work in Arduino read the library page. The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset. Download the LiquidCrystal library here.

you don't want to get your pins reversed! The pinout is as follows: Arduino 2 3 4 5 6 7 8 9 10 11 12 LCD Enable Data Bit 0 (DB0) (DB1) (DB2) (DB3) (DB4) (DB5) (DB6) (DB7) Read/Write (RW) Register Select (RS) Connect a potentiometer a a voltage divider between 5V. It is a lot of wires. Ground. so keep them as short and tidy as possible. Look at the datasheet for your LCD board to figure out which pins are where. and the contrast adjustment pin on your LCD. . Make sure to take note of whether the pin view is from the front or back side of the LCD board.Connect wires from the breadboard to the arduino input sockets.

Too far in the other direction everything will fade from the display. The first program we are going to try is simply for calibration and debugging. compile and upload to the Arduino.Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground. Copy the following code into your sketch. Program the Arduino First start by opening a new sketch in Arduino and saving it. If you turn the potentiometer too far in one direction black blocks will appear. . There should be a small spot in the middle where the cursor appears crisp and dark. //create a LiquidCrystal object to control an LCD void setup(void){ lcd.h> should pop up at the top of your sketch. and choose "LiquidCrystal". //repeat forever } If all went as planned both the LCD and the LED should turn on.init(). //initialize the LCD digitalWrite(13. #include <LiquidCrystal.h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). The phrase #include <LiquidCrystal. scroll down to "import library". Now go to the Sketch menu. Now you can use the potentiometer to adjust the contrast on the LCD until you can clearly see a cursor at the beginning of the first line. //turn on an LED for debugging } void loop(void){ delay(1000).HIGH).

//initialize the LCD digitalWrite(13. #include <LiquidCrystal.//delay 1000 ms to view change } //repeat forever This time you should see the letters a b and c appear and clear from the display in an endless loop. //clear the display delay(1000).print('a'). //send individual letters to the LCD lcd.print('b'). //delay 1000 ms to view change lcd. lcd. .Now let's try something a little more interesting.clear().print('c').h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). //create a LiquidCrystal object to control an LCD void setup(void){ lcd.init().HIGH). delay(1000). Compile and upload the following code to the Arduino. //turn on an LED for debugging } void loop(void){ lcd.

printIn(string1).h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). pass it to printIn(). LCD interface library and tutorial by Heather Dewey-Hagborg Edit Page | Page History | Printable View | All Recent Site Changes . //initialize the LCD digitalWrite(13. To interface an LCD directly in Arduino code see this example. //turn on an LED for debugging } void loop(void){ lcd. //delay 1000 ms to view change } //repeat forever Finally. Here is an example: #include <LiquidCrystal. you should know there is a lot of functionality in the HD44780 chip interface that is not drawn out into Arduino functions. //clear the display delay(1000). //initialize the LCD digitalWrite(13.init().init().HIGH). //variable to store the string "Hello!" void setup(void){ lcd. //send the string to the LCD delay(1000). For example.This is all great fun. #include <LiquidCrystal.clear(). but who really wants to type out each letter of a message indivually? Enter the printIn() function.HIGH). //send the string to the LCD delay(1000). //create a LiquidCrystal object to control an LCD char string1[] = "Hello!". //turn on an LED for debugging } void loop(void){ lcd. //variable to store the string "Hello!" void setup(void){ lcd.commandWrite(2). If you are feeling ambitious glance over the datasheet and try out some of the direct commands using the commandWrite() function. //delay 1000 ms to view change lcd.printIn(string1). //delay 1000 ms to view change lcd. commandWrite(2) tells the board to move the cursor back to starting position. and now we have ourselves a proper hello world program. //bring the cursor to the starting position delay(1000). //delay 1000 ms to view change } //repeat forever This code makes the cursor jump back and forth between the end of the message an the home position.h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). Simply initialize a string. //create a LiquidCrystal object to control an LCD char string1[] = "Hello!".

8 degrees per step and 96 ohms per winding. and controlling both from a potentiometer.uiowa. It is aiming those that have no knowledge in how to control stepper motors. Picture of a protoboard supporting the ULN2003A and a potentiometer Example 1: Simple example /* * * * * * * * * Stepper Copal ------------Program to drive a stepper motor coming from a 5'25 disk drive according to the documentation I found.]" [http://www.edu/~jones/step/example.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Unipolar Stepper Motor This page shows two examples on how to drive a unipolar stepper motor. this stepper: "[.] motor made by Copal Electronics. with 1. The second example is coded in a more complex way. This chip has a bunch of transistors embedded in a single housing.. The one we use has 6 connectors of which one is power (VCC) and the other four are used to drive the motor sending synchronous signals.. in both directions. It allows the connection of devices and components that need much higher current than the ones that the ATMEGA8 from our Arduino board can offer. and a ULN2003A driver. These motors can be found in old floppy drives and are easy to control.. The first example is the basic code to make the motor spin in one direction.html] ..cs. with center taps brought out to separate leads [. but allows to make the motor spin at different speeds. The prototyping board has been populated with a 10K potentiomenter that we connect to an analog input.

void loop() { digitalWrite(motorPin1. digitalWrite(motorPin4. 500. LOW).. LOW).de * * @author: David Cuartielles * @date: 20 Oct. with 1. digitalWrite(motorPin3. with center taps brought out to separate leads [.orange and black: coil 1 * . delay(delayTime).* It is a unipolar stepper motor with 5 wires: * * .red: power connector. I have it at 5V and works fine * . digitalWrite(motorPin4. this stepper: "[. } HIGH). 2005 */ int int int int int motorPin1 motorPin2 motorPin3 motorPin4 delayTime = = = = = 8. LOW). LOW). void setup() { pinMode(motorPin1.8 degrees per step and 96 ohms per winding.0j0. OUTPUT). delay(delayTime). digitalWrite(motorPin3. HIGH). digitalWrite(motorPin2.org | http://arduino. digitalWrite(motorPin1. LOW). pinMode(motorPin2.. LOW). HIGH). digitalWrite(motorPin1.uiowa.edu/~jones/step/example. 10. LOW). LOW). digitalWrite(motorPin3. 9. } OUTPUT). digitalWrite(motorPin2.html] It is a unipolar stepper motor with 5 wires: .cs. LOW). OUTPUT). digitalWrite(motorPin4. 11..]" [http://www. pinMode(motorPin4. delay(delayTime). OUTPUT). delay(delayTime)..brown and yellow: coil 2 * * (cleft) 2005 DojoDave for K3 * http://www. LOW). HIGH). digitalWrite(motorPin3. digitalWrite(motorPin2.berlios. digitalWrite(motorPin2. digitalWrite(motorPin4. digitalWrite(motorPin1. Example 2: Stepper Unipolar Advanced /* * * * * * * * * * * Stepper Unipolar Advanced ------------------------Program to drive a stepper motor coming from a 5'25 disk drive according to the documentation I found. LOW).] motor made by Copal Electronics. pinMode(motorPin3. LOW).

1024 * val / 512 + 1. } void loop() { val = analogRead(0).org | http://arduino. } else if (val < 480) { // move faster the lower the value from the potentiometer delayTime = 1024 * val / 512 + 1. count++) { pinMode(motorPins[count]. void setup() { for (count = 0. } delay(delayTime). 10. OUTPUT). count2>>count&0x01).0j0. moveForward(). moveBackward(). 9. count >= 0. } delay(delayTime). count >= 0. count < 4. count2 = 0. count = 0.orange and black: coil 1 * . } count2>>=1. we have been looking into quite a lot of documentation. for (count = 3.* .berlios. count--) { digitalWrite(motorPins[count]. for (count = 3.count]. if (val > 540) { // move faster the higher the value from the potentiometer delayTime = 2048 . I have it at 5V and works fine * . val = 0. } } void moveForward() { if ((count2 == 0) || (count2 == 1)) { count2 = 16.red: power connector. The following links may be useful for you to visit in order to understand the theory underlying behind stepper motors: . } count2>>=1. delayTime = 500. count2>>count&0x01).de * * @author: David Cuartielles * @date: 20 Oct. 2005 */ int int int int int motorPins[] = {8. 11}. } else { delayTime = 1024. count--) { digitalWrite(motorPins[3 .brown and yellow: coil 2 * * (cleft) 2005 DojoDave for K3 * http://www. } } References In order to work out this example. } void moveBackward() { if ((count2 == 0) || (count2 == 1)) { count2 = 16.

basic explanation about steppers .good PDF with basic information .here .here .here Edit Page | Page History | Printable View | All Recent Site Changes .information about the motor we are using ..

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » DMX Master Device Please see this updated tutorial on the playground. Edit Page | Page History | Printable View | All Recent Site Changes .

Materials needed: Device to communicate with Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . Connect ground on the breadboard to ground from the microcontroller. This should be used when multiple serial connections are necessary. The software serial connection can run at 4800 baud or 9600 baud reliably. Sends a byte long integer value out the software serial connection Example: byte TXval = 'h'. . byte TXval2 = 126. Device specific tutorials are on the Tutorial Page. SWprint(). Read on if you'd like to know how that library works. A tutorial on communicating with a computer is here. Make any other connections necessary for your device. For a good explanation of serial communication see Wikipedia. see the SoftwareSerial library included with Arduino 0007 and later. Functions Available: SWread(). If only one serial connection is necessary the hardware serial port should be used. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. Returns a byte long integer value from the software serial connection Example: byte RXval.optional. Definitions Needed: #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 These definitions set the delays necessary for 9600 baud and 4800 baud software serial operation. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Arduino Software Serial Interface Note: If you just want to use a software serial interface. Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. NOT a specific device tutorial. SWprint(TXval). SWprint(TXval2). for debugging Prepare the breadboard Insert the device you want to communicate with in the breadboard. In this tutorial you will learn how to implement Asynchronous serial communication on the Arduino in software to communicate with other serial devices. RXval = SWread(). This is a general purpose software tutorial.

h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 Here we set up our pre-processor directives. The #define bit9600Delay 84 line causes the . so you don't need to do anything other than type the #include line in order to use it. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. In this example we will use pin 7 for transmitting and pin 6 for receiving. We will walk through the code in small sections. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. #include <ctype. Program the Arduino Now we will write the code to enable serial data communication. They start with a "#" and do not end with semi-colons. Pre-processor directives are processed before the actual compilation begins. These are pre-processor directives that define the delays for different baudrates. First we include the file ctype. but any of the digital pins should work.Decide which pins you want to use for transmitting and receiving.h in our application. This library is part of the Arduino install. Next we establish our baudrate delay definitions. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop.

// send 0 } delayMicroseconds(bit9600Delay).LOW). byte rx = 6.HIGH). val |= digitalRead(rx) << offset. //startbit digitalWrite(tx. mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx. } //wait for stop bit + extra delayMicroseconds(bit9600Delay). delayMicroseconds(bit9600Delay). First the transmit line is pulled low to signal a start bit. Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip. // send 1 } else{ digitalWrite(tx. SWprint(10). turn on our debugging LED and print a debugging message to confirm all is working as planned.compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". void SWprint(int data) { byte mask. while (digitalRead(rx)). int SWread() { byte val = 0. offset < 8. delayMicroseconds(bit9600Delay). void setup() { pinMode(rx.HIGH).LOW). } //stop bit digitalWrite(tx. //carriage return } Here we initialize the lines.INPUT). For each bit we transmit we hold the line high or low for the specified delay. //turn on debugging LED SWprint('h').OUTPUT). } This is the SWprint function. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. for (int offset = 0. Here we set our transmit (tx) and recieve (rx) pins. To use 4800 simply replace the variable bit9600Delay with bit4800Delay . pinMode(tx. This will wait for a byte to arrive on the recieve pin and then return it to the allocated variable. In this example we are using a 9600 baudrate.HIGH). byte tx = 7. //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay). delayMicroseconds(bit9600Delay). return val. HIGH). digitalWrite(13. Change the pin numbers to suit your application. byte SWval. Finally we pull the line high again to signal a stop bit. mask>0. . for (mask = 0x01. We also allocate a variable to store our recieved data in. } } This is the SWread function. digitalWrite(tx. offset++) { delayMicroseconds(bit9600Delay). SWval . //debugging hello SWprint('i'). We can pass inidvidual characters or numbers to the SWprint function.

void loop() { SWval = SWread().LOW). //carriage return } void SWprint(int data) { byte mask. // send 1 } else{ digitalWrite(tx. change them to uppercase and send them back. SWprint(toupper(SWval)). In this program we simply wait for characters to arrive. } Finally we implement our main program loop. bluetooth. for (mask = 0x01. delayMicroseconds(bit9600Delay). Then we iterate through a bit mask and shift 1s or 0s into our output byte based on what we recieve. delayMicroseconds(bit9600Delay). byte SWval. LCDs.HIGH). SWprint(10). For easy copy and pasting the full program text of this tutorial is below: //Created August 15 2006 //Heather Dewey-Hagborg //http://www. etc. //startbit digitalWrite(tx.arduino.cc #include <ctype. byte tx = 7.h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 byte rx = 6. HIGH). digitalWrite(tx. //turn on debugging LED SWprint('h'). We check after a half bit delay to make sure the line is still low and we didn't just recieve line noise. mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx.OUTPUT).HIGH). For lots of fun serial devices check out the Sparkfun online catalog. mask>0. wi-fi. void setup() { pinMode(rx. This is always a good program to run when you want to make sure a serial connection is working properly. pinMode(tx.First we wait for the recieve line to be pulled low. They have lots of easy to use serial modules for GPS. } //stop bit digitalWrite(tx. Finally we allow a pause for the stop bit and then return the value. // send 0 } delayMicroseconds(bit9600Delay).LOW). } int SWread() { . digitalWrite(13.INPUT). //debugging hello SWprint('i').HIGH).

delayMicroseconds(bit9600Delay). //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay). return val.byte val = 0. offset++) { delayMicroseconds(bit9600Delay). } } void loop() { SWval = SWread(). SWprint(toupper(SWval)). } //wait for stop bit + extra delayMicroseconds(bit9600Delay). val |= digitalRead(rx) << offset. } code and tutorial by Heather Dewey-Hagborg Edit Page | Page History | Printable View | All Recent Site Changes . offset < 8. for (int offset = 0. while (digitalRead(rx)).

Zterm on Mac) Serial-Breadboard cable MAX3323 chip (or similar) 4 1uf capacitors Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . A general purpose software serial tutorial can be found here. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 .Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » RS-232 In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino.optional. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Materials needed: Computer with a terminal program installed (ie. HyperTerminal or RealTerm on the PC.11 to 5V. . If you are using an LED connect it between pin 13 and ground. for debugging Prepare the breadboard Insert the MAX3323 chip in the breadboard.

GND wires are black Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground). Connect your RX pin (6) to MAX3323 pin 9 (R1OUT). . In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting.+5v wires are red. Connect your TX pin (7) to MAX3323 pin 10 (T1IN). +5v wires are red. GND wires are black Connect a 1uF capacitor across pins 1 and 3. another across pins 4 and 5. and the last between pin 6 and ground. another between pin 1 and ground.

+5v wires are red. you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard.TX wire Green. pick up a female DB9 connector from radioshack. one for TX. GND wires are black Cables (DB9 Serial Connector Pin Diagram) If you do not have one already. Pick three different colors of wire. To do this. Solder your TX wire to pin 2 of the DB9 connector. . RX wire to pin 3 and Ground to pin 5. and one for ground. RX wire Blue. one for RX.

Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Connect the ground line from your computer to ground on the breadboard. . Heatshrink the wire connections to avoid accidental shorts. Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port. Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT).

LOW). mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx. digitalWrite(tx. //turn on debugging LED SWprint('h').cc #include <ctype.arduino. GND wires are black Program the Arduino Now we will write the code to enable serial data communication.h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 byte rx = 6. byte tx = 7. digitalWrite(13. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. void setup() { pinMode(rx. SWprint(10).INPUT). mask>0. +5v wires are red. // send 1 } else{ .TX wires Green. //carriage return } void SWprint(int data) { byte mask.HIGH).HIGH). for (mask = 0x01. Upload the following code into the Arduino microcontroller module: //Created August 23 2006 //Heather Dewey-Hagborg //http://www. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port.HIGH). //startbit digitalWrite(tx. pinMode(tx. delayMicroseconds(bit9600Delay). //debugging hello SWprint('i').OUTPUT). RX wires Blue. byte SWval.

while (digitalRead(rx)). Now. 8 data bits. delayMicroseconds(bit9600Delay). Here is a shot of what it should look like in Hyperterminal. no parity. You should see the letter you typed return to you in uppercase. // send 0 } delayMicroseconds(bit9600Delay). 1 stop bit. no hardware flow control. } } void loop() { SWval = SWread(). offset++) { delayMicroseconds(bit9600Delay). //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay). } //wait for stop bit + extra delayMicroseconds(bit9600Delay). return val. SWprint(toupper(SWval)). } Open up your serial terminal program and set it to 9600 baud. The word "hi" should appear in the terminal window followed by an advancement to the next line. delayMicroseconds(bit9600Delay). } int SWread() { byte val = 0. . offset < 8.digitalWrite(tx. Press the reset button on the arduino board. for (int offset = 0.LOW). the free pre-installed windows terminal application. try typing a lowercase character into the terminal window. HIGH). } //stop bit digitalWrite(tx. val |= digitalRead(rx) << offset.

code and tutorial by Heather Dewey-Hagborg. photos by Thomas Dexter Edit Page | Page History | Printable View | All Recent Site Changes .If this works. You can now use your new serial/computer connection to print debugging statements from your code. congratulations! Your serial connection is working as planned. and to send commands to your microcontroller.

It can also be used for communication between two microcontrollers.Sets the data clock to be idle when high if set to 1. Data registers simply hold bytes. each of which control a particular SPI setting. data and status. and whether the clock is idle when high or low.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Interfacing a Serial EEPROM Using SPI In this tutorial you will learn how to interface with an AT25HP512 Atmel serial EEPROM using the Serial Peripheral Interface (SPI) protocol. so follow this tutorial only if you need more space than it provides. and the steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. idle when low if set to 0 CPHA . These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal. slave mode when 0 CPOL . Note that the chip on the Arduino board contains an internal EEPROM. The SPI control register (SPCR) has 8 bits. Master Out Slave In (MOSI) . For example. such as speed or polarity.The Master line for sending data to the peripherals.The Slave line for sending data to the master. SPCR | 7 | 6 | SPIE | SPE | 5 | 4 | 3 | 2 | 1 | 0 | | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 | SPIE . the seventh bit of the SPI status register (SPSR) gets set to 1 when a value is shifted in or out of the SPI. Usually each bit in a control register effects a particular setting.Sets the Arduino in master mode when 1.Enables the SPI when 1 DORD .Enables the SPI interrupt when 1 SPE . Materials Needed: AT25HP512 Serial EEPROM chip (or similar) Hookup wire Arduino Microcontroller Module Introduction to the Serial Peripheral Interface Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by Microcontrollers for communicating with one or more peripheral devices quickly over short distances. Master In Slave Out (MISO) . This means you have to pay special attention to the datasheet when writing your interface code. and the data which has just been shifted in the MISO line.allocated on each device which the master can use to enable and disable specific devices and avoid false transmissions due to line noise. Serial Clock (SCK) .The clock pulses which synchronize data transmission generated by the master. Status registers change their state based on various microcontroller conditions. Typically there are three lines common to all the devices. control.Sends data least Significant Bit First when 1. Generally speaking there are three modes of transmission numbered 0 . A register is just a byte of microcontroller memory that can be read from or written to. and Slave Select pin . Control registers code control settings for various microcontroller functionalities. EEPROM chips such as this are very useful for data storage. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. Registers generally serve three purposes. rising edge when 0 . All SPI settings are determined by the Arduino SPI Control Register (SPCR). The difficult part about SPI is that the standard is loose and each device implements it a little differently.Samples data on the falling edge of the data clock when 1.3. most Significant Bit first when 0 MSTR . the SPI data register (SPDR) holds the byte which is about to be shifted out the MOSI line. For example.

Instructions are sent as 8 bit operational codes (opcodes) and are shifted in on the rising edge of the data clock. 00 is fastest (4MHz) 11 is slowest (250KHz) This means that to write code for a new SPI device you need to note several things and set the SPCR accordingly: Is data shifted in MSB or LSB first? Is the data clock idle when high or low? Are samples on the rising or falling edge of clock pulses? What speed is the SPI running at? Once you have your SPI Control Register set correctly you just need to figure out how long you need to pause between instructions and you are ready to go. Prepare the Breadboard Insert the AT25HP512 chip into the breadboard. . runs at up to 10MHz at 5v and can run at slower speeds down to 1. but it can be read 1-128 bytes at a time. but we won't be covering those in this tutorial.8v. Connect EEPROM pins 3. Introduction to Serial EEPROM The AT25HP512 is a 65. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller.536 byte serial EEPROM. It's memory is organized as 512 pages of 128 bytes each. so a 10ms pause should follow each EEPROM write routine. let's take a look at the details of the EEPROM chip. It can only be written 128 bytes at a time. Now that you have a feel for how SPI works. 7 and 8 to 5v and pin 4 to ground. The device also offers various degerees of write protection and a hold pin. It takes the EEPROM about 10 milliseconds to write a page (128 bytes) of data. The device is enabled by pulling the Chip Select (CS) pin low.Sets the SPI speed.SPR1 and SPR0 . It supports SPI modes 0 and 3.

In the main loop it reads that data back out. Then we define our opcodes for the EEPROM. SS wire is white. The first step is setting up our pre-processor directives. EEPROM pin 5 to Arduino pin 11 (Master Out Slave In . They start with a "#" and do not end with semi-colons.MOSI). one byte at a time and prints that byte out the built in serial port.MISO). SCK wire is green Program the Arduino Now we will write the code to enable SPI communication between the EEPROM and the Arduino. MISO wire is yellow.SS). GND wires are black Connect EEPROM pin 1 to Arduino pin 10 (Slave Select . and EEPROM pin 6 to Arduino pin 13 (Serial Clock . Pre-processor directives are processed before the actual compilation begins. We define the pins we will be using for our SPI connection. DATAOUT.SCK). or one page of the EEPROM with data.+5v wires are red. EEPROM pin 2 to Arduino pin 12 (Master In Slave Out . We will walk through the code in small sections. SPICLOCK and SLAVESELECT. Opcodes are control commands: #define #define #define #define DATAOUT 11//MOSI DATAIN 12//MISO SPICLOCK 13//sck SLAVESELECT 10//ss //opcodes . DATAIN. MOSI wire is blue. In the setup routine this program fills 128 bytes.

int address=0.OUTPUT). In the control register each bit sets a different functionality. The EEPROM MUST be write enabled before every write instruction. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). First we initialize our serial connection. //fill eeprom w/ buffer digitalWrite(SLAVESELECT. the fourth bit sets the data clock idle when it is low. //write instruction address=0. Here we fill our data array with numbers and send a write enable instruction to the EEPROM.HIGH). //send MSByte address first . After setting our control register up we read the SPI status register (SPSR) and data register (SPDR) in to the junk clr variable to clear out any spurious data from past runs: // SPCR = 01010000 //interrupt disabled. spi_transfer(WREN). digitalWrite(SLAVESELECT. Most Significant Bit first. OUTPUT). The eighth bit disables the SPI interrupt. the fifth bit puts the Arduino in Master mode. pinMode(DATAIN.HIGH).OUTPUT). delay(10). Finally we pull the SLAVESELECT line high again to release it: //fill buffer with data fill_buffer(). This deselects the device and avoids any false transmission messages due to line noise: void setup() { Serial.msb 1st. pinMode(SLAVESELECT. //sample on leading edge of clk. spi_transfer((char)(address>>8)). Note char buffer [128].LOW). Now we pull the SLAVESELECT line low to select the device again after a brief delay.spi enabled. To send the instruction we pull the SLAVESELECT line low.clk low when idle. byte eeprom_input_data=0. digitalWrite(SLAVESELECT.begin(9600). pinMode(SPICLOCK.#define #define #define #define #define #define WREN WRDI RDSR WRSR READ WRITE 6 4 5 1 3 2 Here we allocate the global variables we will be using later in the program.LOW). //data buffer char buffer [128]. spi_transfer(WRITE). pinMode(DATAOUT. clr=SPSR. We send the 16 bit address to begin writing at in two bytes. this is a 128 byte array we will be using to store the data for the EEPROM write: byte eeprom_output_data. We send a WRITE instruction to tell the EEPROM we will be sending data to record into memory. Next we send our 128 bytes of data from our buffer array.master. byte clr. the seventh bit enables the SPI. . //write enable digitalWrite(SLAVESELECT. one byte after another without pause. //disable device Now we set the SPI Control register (SPCR) to the binary value 01010000. the third bit sets the SPI to sample data on the rising edge of the data clock. and then send the instruction using the spi_transfer function. the sixth bit chooses transmission with the most significant bit going first. Finally we set the SLAVESELECT pin high to release the device and pause to allow the EEPROM to write the data: delay(10). INPUT).system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR). set our input and output pin modes and set the SLAVESELECT line high to start. enabling the device. clr=SPDR. Note that we use the WREN opcode we defined at the beginning of the program.

digitalWrite(SLAVESELECT. When the address increments to 128 we turn it back to 0 because we have only filled 128 addresses in the EEPROM with data: void loop() { eeprom_output_data = read_eeprom(address).print('i'. delay(500).HIGH). We end the setup function by sending the word "hi" plus a line feed out the built in serial port for debugging purposes.BYTE). Serial.BYTE). // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait for the end of the transmission { }. //write data byte } digitalWrite(SLAVESELECT.BYTE). Serial.DEC). Serial. address++. thus starting the SPI transmission. and return the data. up to 128 times for a full page of data: byte read_eeprom(int EEPROM_address) { //READ EEPROM int data. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. // return the received byte } The read_eeprom function allows us to read data back out of the EEPROM. SPIF. } } The spi_transfer function loads the output data into the data transmission register. It then returns any data that has been shifted in to the data register by the EEPROM: char spi_transfer(volatile char data) { SPDR = data. .BYTE).I++) { buffer[I]=I.print(eeprom_output_data.print('h'. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. This function could easily be changed to fill the array with data relevant to your application: void fill_buffer() { for (int I=0. //send LSByte address //write 128 bytes for (int I=0.127 for each index in the array.spi_transfer((char)(address)). First we set the SLAVESELECT line low to enable the device.LOW). } In our main loop we just read one byte at a time from the EEPROM and print it out the serial port. Each time through the loop we increment the eeprom address to read.I<128. followed by the 16-bit address we wish to read from. This way if our data comes out looking funny later on we can tell it isn't just the serial port acting up: Serial. An explanation of bit masks can be found here. We add a line feed and a pause for readability.print('\n'. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out.I<128. return SPDR. //release chip //wait for eeprom to finish writing delay(3000).print('\n'.I++) { spi_transfer(buffer[I]). Most Significant Bit first.//debug delay(1000). Serial. //pause for readability } The fill_buffer function simply fills our data array with numbers 0 . Then we transmit a READ instruction.

// Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }.I++) { buffer[I]=I.master.clk low when idle. pinMode(DATAOUT. pinMode(SLAVESELECT.system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR).HIGH). . signal end transfer return data.spi enabled. //send LSByte address data = spi_transfer(0xFF). void fill_buffer() { for (int I=0. int address=0. clr=SPDR. //disable device // SPCR = 01010000 //interrupt disabled. //fill buffer with data fill_buffer(). clr=SPSR. return SPDR.msb 1st. } } char spi_transfer(volatile char data) { SPDR = data. byte eeprom_input_data=0. INPUT). pinMode(DATAIN. //transmit read opcode spi_transfer((char)(EEPROM_address>>8)). byte clr. // return the received byte } void setup() { Serial. OUTPUT). //sample on leading edge of clk.spi_transfer(READ). delay(10). } For easy copy and pasting the full program text of this tutorial is below: #define #define #define #define DATAOUT 11//MOSI DATAIN 12//MISO SPICLOCK 13//sck SLAVESELECT 10//ss //opcodes #define WREN #define WRDI #define RDSR #define WRSR #define READ #define WRITE 6 4 5 1 3 2 byte eeprom_output_data. //send MSByte address first spi_transfer((char)(EEPROM_address)).OUTPUT).begin(9600).HIGH). //release chip. pinMode(SPICLOCK. digitalWrite(SLAVESELECT.OUTPUT).I<128. //get data byte digitalWrite(SLAVESELECT. //data buffer char buffer [128].

Serial. //get data byte digitalWrite(SLAVESELECT. //send MSByte address first spi_transfer((char)(EEPROM_address)). //write data byte } digitalWrite(SLAVESELECT.HIGH).BYTE).LOW). spi_transfer(WREN). spi_transfer(WRITE).I++) { spi_transfer(buffer[I]). //transmit read opcode spi_transfer((char)(EEPROM_address>>8)).BYTE). delay(10).print('i'.print('\n'. Serial. digitalWrite(SLAVESELECT.print(eeprom_output_data. //write instruction address=0.I<128. spi_transfer((char)(address>>8)). Serial. signal end transfer return data. if (address == 128) address = 0. //write enable digitalWrite(SLAVESELECT.BYTE).HIGH).print('h'.LOW). //release chip.DEC). Serial. photos by Thomas Dexter Edit Page | Page History | Printable View | All Recent Site Changes . delay(500). //release chip //wait for eeprom to finish writing delay(3000).HIGH). //pause for readability } code and tutorial by Heather Dewey-Hagborg. //send LSByte address //write 128 bytes for (int I=0. //send MSByte address first spi_transfer((char)(address)). Serial.//debug delay(1000). } byte read_eeprom(int EEPROM_address) { //READ EEPROM int data. spi_transfer(READ). address++.//fill eeprom w/ buffer digitalWrite(SLAVESELECT. } void loop() { eeprom_output_data = read_eeprom(address).LOW).BYTE).print('\n'. //send LSByte address data = spi_transfer(0xFF). digitalWrite(SLAVESELECT.

audio signal conditioning and tone generation. Materials Needed: AD5206 Digital Potentiometer Arduino Microcontroller Module 6 Light Emitting Diodes (LEDs) Hookup Wire Introduction to the AD5206 Digital Potentiometer . The steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. In this example we will use a six channel digital potentiometer to control the brightness of six LEDs. For an explanation of SPI see the SPI EEPROM tutorial. Digital potentiometers are useful when you need to vary the resistance in a ciruit electronically rather than by hand. Example applications include LED dimming.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Controlling a Digital Potentiometer Using SPI In this tutorial you will learn how to control the AD5206 digital potentiometer using Serial Peripheral Interface (SPI).

ie. The AD5206 is digitally controlled using SPI. The individual variable resistor pins are labeled Ax. B1 and W1. Data is shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. . There are three pins on the chip for each of the six internal variable resistors. Instructions are sent as 11 bit operational codes (opcodes) with the three most significant bits (11-9) defining the address of which potentiometer to adjust and the eight least significant bits (8-1) defining what value to set that potentiometer to from 0-255. pulling another side pin (pin A) low and taking the variable voltage output of the center pin (Wiper). This means it has six variable resistors (potentiometers) built in for individual electronic control. so we don't need to worry about pre-scaling to slow down the transmission. and they can be interfaced with just as you would use a mechanical potentiometer. For example. Bx and Wx. The device is enabled by pulling the Chip Select (CS) pin low. in this tutorial we will be using each variable resistor as a voltage divider by pulling one side pin (pin B) high.The AD5206 is a 6 channel digital potentiometer. The data clock is idle when low. and the interface runs much faster than the Arduino. A1.

and 22 to ground.MOSI).SS). 4. 6. Finally. 13. 14. 10. AD5206 pin 7 to Arduino pin 11 (Master Out Slave In . . Connect AD5206 pins 3. and AD5206 pin 8 to Arduino pin 13 (Serial Clock . 20 and 23) and ground so that the long pin of the LED connects to the wiper and the short pin. 15. 19. 21 and 24 to 5v and pins 1. 17. 18. 16. We are connecting all the A pins to ground and all of the B pins to 5v to create 6 voltage dividers. Connect AD5206 pin 5 to Arduino pin 10 (Slave Select . 11.SCK). connect an LED between each Wiper pin (AD5206 pins 2. 12. or flat side of the LED connects to ground.Prepare the Breadboard Insert the AD5206 chip into the breadboard. 9. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller.

HIGH). . but part of builtin SPI SPICLOCK 13//sck SLAVESELECT 10//ss Next we allocate variables to store resistance values and address values for the potentiometers: byte pot=0. digitalWrite(SLAVESELECT. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). byte resistance=0. The eighth bit disables the SPI interrupt. pinMode(SLAVESELECT. the third bit sets the SPI to sample data on the rising edge of the data clock. This program will sequentially pulse each LED on and then fade it out gradually. clr=SPSR. //disable device Now we set the SPI Control register (SPCR) to the binary value 01010000. Although we are not reading any data back out of the AD5206 in this program. This is accomplished in the main loop of the program by individually changing the resistance of each potentiometer from full off to full on over its full range of 255 steps. pinMode(DATAOUT. the fifth bit puts the Arduino in Master mode. DATAOUT. After setting our control register up we read the SPI status register (SPSR) and data register (SPDR) in to the junk clr variable to clear out any spurious data from past runs: SPCR = (1<<SPE)|(1<<MSTR). We define the pins we will be using for our SPI connection. pinMode(SPICLOCK. the seventh bit enables the SPI. First we set our input and output pin modes and set the SLAVESELECT line high to start. pin 12 is attached to the builtin SPI so it is best not to use it for other programming functions to avoid any possible errors: #define #define #define #define DATAOUT 11//MOSI DATAIN 12//MISO . This deselects the device and avoids any false transmission messages due to line noise: void setup() { byte clr. In the control register each bit sets a different functionality.not used. INPUT). SPICLOCK and SLAVESELECT. pinMode(DATAIN. the fourth bit sets the data clock idle when it is low. clr=SPDR. the sixth bit chooses transmission with the most significant bit going first. We will walk through the code in small sections.OUTPUT).Program the Arduino Now we will write the code to enable SPI control of the AD5206. DATAIN. OUTPUT).OUTPUT).

i<6. if (resistance==255) { pot++. byte write_pot(int address. spi_transfer(value). It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask.i++) { write_pot(i. We set the SLAVESELECT line low to enable the device. but part of builtin SPI SPICLOCK 13//sck SLAVESELECT 10//ss . SPIF. return SPDR. digitalWrite(SLAVESELECT. } } In our main loop we iterate through each resistance value (0-255) for each potentiometer address (0-5). //2 byte opcode spi_transfer(address). thus starting the SPI transmission. int value) { digitalWrite(SLAVESELECT. delay(10).delay(10). resistance++. } if (pot==6) { pot=0. //release chip. // return the received byte } The write_pot function allows us to control the individual potentiometers. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. We pause for 10 milliseconds each iteration to make the steps visible.not used.resistance).LOW). Then we transfer the address byte followed by the resistance value byte. } } The spi_transfer function loads the output data into the data transmission register. Finally. It then returns any data that has been shifted in to the data register by the EEPROM: char spi_transfer(volatile char data) { SPDR = data. An explanation of bit masks can be found here. signal end transfer } LED video For easy copy and pasting the full program text of this tutorial is below: #define #define #define #define DATAOUT 11//MOSI DATAIN 12//MISO .HIGH). We conclude the setup function by setting all the potentiometers to full on resistance states thereby turning the LEDs off: for (i=0. we set the SLAVSELECT line high again to release the chip and signal the end of our data transfer. This causes the LEDs to sequentially flash on brightly and then fade out slowly: void loop() { write_pot(pot.255).

// return the received byte } void setup() { byte i.OUTPUT).255). spi_transfer(value). } } code. digitalWrite(SLAVESELECT. digitalWrite(SLAVESELECT. delay(10). char spi_transfer(volatile char data) { SPDR = data.clk low when idle. pinMode(DATAOUT. clr=SPSR. return SPDR. //release chip. } } byte write_pot(int address. INPUT). //disable device // SPCR = 01010000 //interrupt disabled. if (resistance==255) { pot++. } if (pot==6) { pot=0. signal end transfer } void loop() { write_pot(pot.OUTPUT).system clock/4 (fastest) SPCR = (1<<SPE)|(1<<MSTR). //sample on leading edge of clk. delay(10). for (i=0. tutorial and photos by Heather Dewey-Hagborg Edit Page | Page History | Printable View | All Recent Site Changes . resistance++. int value) { digitalWrite(SLAVESELECT.master.LOW). clr=SPDR. OUTPUT).resistance). pinMode(SLAVESELECT.spi enabled.HIGH).i<6. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }.msb 1st.byte pot=0. pinMode(SPICLOCK. byte resistance=0. pinMode(DATAIN.i++) { write_pot(i.HIGH). byte clr. //2 byte opcode spi_transfer(address).

.

” In other words.begin() function which relies on the sender and the receiver to be set independently to an agreed upon specified data rate. The datasheet refers to the 74HC595 as an “8-bit serial-in. active low Shift register clock pin Storage register clock pin (latch pin) Output enable. The “serial output” part of this component comes from its extra pin which can pass the serial information received from the microcontroller out again unchanged. “3 states” refers to the fact that you can set the output pins as either high. The STP16C596 for example will drive 16 LED's and eliminates the series resistors with built-in constant current sources. you can’t set pins to their high impedance state individually. that you delineate between bits. the clock pin. active low Serial data input Positive supply voltage Example 1: One Shift Register The first step is to extend your Arduino with one shift register. there are many. It's by pulsing second pin. Vss Serial Out Master Reclear. (Users may also wish to search for other driver chips with "595" or "596" in their part numbers. Neither example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit.” i. This example is based on the 74HC595. serial or parallel-out shift register with output latches.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Serial to Parallel Shifting-Out with a 74HC595 Started by Carlyn Maw and Tom Igoe Nov.” Unlike the HIGH and LOW states. This is the “parallel output” part. Here is a table explaining the pin-outs adapted from the Phillip's datasheet. You can link multiple registers together to extend your output even more. 3-state.) How this all works is through something called “synchronous serial communication. You can learn to do that from the second example.e. This is in contrast to using the “asynchronous serial communication” of the Serial. having all the pins do what you want them to do all at once. 06 Shifting Out & the 595 chip At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. You can only set the whole chip together. . This is a pretty specialized thing to do -. Once the whole byte is transmitted to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins.Think of an LED array that might need to be controlled by completely different microcontrollers depending on a specific mode setting built into your project. 15 PIN 8 PIN 9 PIN 10 PIN 11 PIN 12 PIN 13 PIN 14 PIN 16 Q0 – Q7 GND Q7’ MR SH_CP ST_CP OE DS Vcc Output Pins Ground. PINS 1-7. This means you can transmit 16 bits in a row (2 bytes) and the first 8 will flow through the first register into the second register and be expressed there. low or “high impedance.

but this way will work and leave you with more open pins. . Connect to Arduino DS (pin 14) to Ardunio DigitalPin 11 (blue wire) SH_CP (pin 11) to to Ardunio DigitalPin 12 (yellow wire) ST_CP (pin 12) to Ardunio DigitalPin 8 (green wire) From now on those will be refered to as the dataPin.1µf capacitor on the latchPin. if you have some flicker when the latch pin pulses you can use a capacitor to even it out. the clockPin and the latchPin respectively. Vcc (pin 16) to 5V OE (pin 13) to ground MR (pin 10) to 5V This set up makes all of the output pins active and addressable all the time. 2. Turning it on Make the following connections: GND (pin 8) to ground. The one flaw of this set up is that you end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. You can get around this by controlling the MR and OE pins from your Arduino board too. Notice the 0.The Circuit 1.

Circuit Diagram . If you have one of those it means you will have to flip the direction of the LEDs. Using the shift register to supply power like this is called sourcing current. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded. Add 8 LEDs. putting the anodes directly to power and the cathodes (ground pins) to the shift register outputs. they can only do what is called sinking current. and the anode (long pin) of each LED to its respective shift register output pin. You should check the your specific datasheet if you aren’t using a 595 series chip. In this case you should connect the cathode (short pin) of each LED to a common ground.3. Some shift registers can't source current.

lighting the LEDs.The Code Here are three code examples.2 – One by One . Code Sample 1. the shift register reads the state of the data pin.1 – Hello World Code Sample 1. When the clockPin goes from low to high. As the data gets shifted in it is saved in an internal memory register. The third cycles through an array. When the latchPin goes from low to high the sent data gets moved from the shift registers aforementioned memory register into the output pins. The second program lights one LED at a time. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. 595 Logic Table 595 Timing Diagram The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. The logic table is what tells you that basically everything important happens on an up beat.

3 – from Defined Array Example 2 In this example you’ll add a second shift register. The blue wire is going from the serial out pin (pin 9) of the first shift register to the serial data input (pin 14) of the second register. 2. Starting from the previous example. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires). doubling the number of output pins you have while still using the same number of pins from the Arduino. Add a second shift register. Connect the 2 registers.Code Sample 1. you should put a second shift register on the board. It should have the same leads to power and ground. The Circuit 1. .

Add a second set of LEDs. In this case I added green ones so when reading the code it is clear which byte is going to which set of LEDs .3.

Circuit Diagram .

1 – Dual Binary Counters There is only one extra line of code compared to the first code sample from Example 1.2 – 2 Byte One By One Comparing this code to the similar code from Example 1 you see that a little bit more has had to change. Code Sample 2. you might want to try the samples from the first example with this circuit set up just to see what happens.Dual Defined Arrays . The second byte will then show up on the red LEDs.3 . the one directly attached to the Arduino. to pass the first byte sent through to the second register. Also. This forces the first shift register. once for the green LEDs and once for the red ones. If you are curious. lighting the green LEDs. Code Sample 2.The Code Here again are three code samples. It sends out a second byte. The blinkAll() function has been changed to the blinkAll_2Bytes() function to reflect the fact that now there are 16 LEDs to control. Code Sample 2. Here they need to be moved back into the main loop to accommodate needing to run each subfunction twice in a row. in version 1 the pulsings of the latchPin were situated inside the subfunctions lightShiftPinA and lightShiftPinB().

clockPin. and shiftOut(dataPin. dataRED).2. 2. a dataGREEN.3 also takes advantage of the new blinkAll_2bytes() function. sample 2. dataGREEN). becomes dataRED = dataArrayRED[j]. Edit Page | Page History | Printable View | All Recent Site Changes . shiftOut(dataPin.Like sample 2. clockPin. dataArrayGREEN defined up front. dataGREEN = dataArrayGREEN[j]. becomes shiftOut(dataPin. data). This means that line data = dataArray[j].3 is only that instead of just a single variable called “data” and a single array called “dataArray” you have to have a dataRED.3's big difference from sample 1. dataArrayRED. clockPin.

and the TW523 two-way X10 controller. Then wire the pins as follows: Download: X10.x10. You can find X10 controllers and devices at http://www. Then re-start the Arduino application. When you restart. int numRepeats) .g. Serial. printing the version is a useful debugging tool when you get an error from a given function. Since there will be more functions added. sending a bit every time the AC power crosses zero volts. e.com. // Turns on all lights in house code A version(void) . and more.write(A. UNIT_1 through UNIT_16: unit code values .g.get the library version. unzip it and copy the resulting folder.println(myHouse. x10 myHouse = x10(9. get a phone cable with an RJ-11 connector.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » X10 Library This library enables you to send and receive X10 commands from an Arduino module. 10). // initializes X10 on pins 9 (zero crossing pin) and 10 (data pin) void write(byte houseCode. They are as follows: A through F: house code values. As of version 0.version()). X10 is a synchronous serial protocol that travels over AC power lines. converting the 5V output of the Arduino into AC signals on the zero crossing.com. It's used in home automation. and cut one end off.g. here's what you can do: x10(int strLength) . called TextString.zip To use. To connect an Arduino to one of these modules. byte numberCode. ALL_LIGHTS_ON. into the lib/targets/libraries directory of your arduino application folder. e. http://www.smarthome. you'll see a few warning messages in the debugger pane at the bottom of the program. myHouse. 1).Send an X10 message.2. This library has been tested using the PL513 one-way X10 controller. Perhaps you're using an earlier version that doesn't feature the version you need! e. You can ignore them. Both of these are essentially X10 modems. // prints the version of the library There are a number of constants added to make X10 easier.initialize an instance of the X10 library on two digital pins.

see this technote If anyone's interested in helping to develop this library further.ALL_UNITS_OFF ALL_LIGHTS_ON ON OFF DIM BRIGHT ALL_LIGHTS_OFF EXTENDED_CODE HAIL_REQUEST HAIL_ACKNOWLEDGE PRE_SET_DIM EXTENDED_DATA STATUS_ON STATUS_OFF STATUS_REQUEST For a full explanation of X10 and these codes. please contact me at tom.com Edit Page | Page History | Printable View | All Recent Site Changes .igoe at gmail.

HIGH). } void loop() { } See also EEPROM Read example EEPROM Write example EEPROM library reference Edit Page | Page History | Printable View | All Recent Site Changes . 0). // turn the LED on when we're done digitalWrite(13.h> void setup() { // write a 0 to all 512 bytes of the EEPROM for (int i = 0.write(i. Code #include <EEPROM.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > EEPROM Library EEPROM Clear Sets all of the bytes of the EEPROM to 0. i < 512. i++) EEPROM.

println().read(address).print("\t"). Code #include <EEPROM. wrap around to address 0 if (address == 512) address = 0. } See also EEPROM Clear example EEPROM Write example EEPROM library reference Edit Page | Page History | Printable View | All Recent Site Changes . // advance to the next address of the EEPROM address = address + 1. Serial.h> // start reading from the first byte (address 0) of the EEPROM int address = 0. // there are only 512 bytes of EEPROM. Serial. so if we're // on address 512. void setup() { Serial. delay(500). byte value.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > EEPROM Library EEPROM Read Reads the value of each byte of the EEPROM and prints it to the computer. } void loop() { // read a byte from the current address of the EEPROM value = EEPROM. Serial. Serial.print(value. DEC). from 0 to 511.print(address).begin(9600).

// these values will remain there when the board is // turned off.e. EEPROM. delay(100). addr = addr + 1. there are 512 bytes in // the EEPROM. // advance to the next address. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch. val). if (addr == 512) addr = 0. which byte // we're going to write to next) int addr = 0. int val = analogRead(0) / 4. void setup() { } void loop() { // need to divide by 4 because analog inputs range from // 0 to 1023 and each byte of the EEPROM can only hold a // value from 0 to 255. } See also EEPROM Clear example EEPROM Read example EEPROM library reference Edit Page | Page History | Printable View | All Recent Site Changes .write(addr.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > EEPROM Library EEPROM Write Stores values read from analog input 0 into the EEPROM. // write the value to the appropriate byte of the EEPROM.h> // the current address in the EEPROM (i. Code #include <EEPROM. so go back to 0 when we hit 512.

using one of the circuits on the linked pages. Code #include <Stepper.setSpeed(30). // the previous reading from the analog input int previous = 0. 9. specifying // the number of steps of the motor and the pins it's // attached to Stepper stepper(STEPS. 10. // move a number of steps equal to the change in the // sensor reading stepper. // remember the previous value of the sensor previous = val.previous).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Stepper Library Motor Knob Description A stepper motor follows the turns of a potentiometer (or other sensor) on analog input 0. and 11. void setup() { // set the speed of the motor to 30 RPMs stepper. 9. The unipolar or bipolar stepper is controlled with pins 8. } void loop() { // get the sensor value int val = analogRead(0).step(val . 8. } See also Stepper library reference Edit Page | Page History | Printable View | All Recent Site Changes . 11).h> // change this to the number of steps on your motor #define STEPS 100 // create an instance of the stepper class. 10.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Restore May 21. 2008. 2008. Restore May 21. at 09:43 PM by David A. Mellis Changed lines 2-3 from: Arduino Examples to: Examples Restore July 02. and the links page for other documentation. 2008. Mellis Deleted lines 42-45: Matrix Library Hello Matrix?: blinks a smiley face on the LED matrix. 2008. 2008. at 03:11 PM by David A. Restore May 21. the hacking page for information on extending and modifying the Arduino hardware and software.HomePage History Hide minor edits . Mellis Changed lines 4-5 from: See the foundations page for in-depth description of core concepts of the Arduino hardware and software. at 09:44 PM by David A. at 09:25 PM by David A. and the links page for other documentation.Show changes to markup July 02. to: See the foundations page for in-depth description of core concepts of the Arduino hardware and software. Mellis Added line 63: Read an ADXL3xx accelerometer Restore May 21. 2008. Mellis Added lines 43-46: Matrix Library Hello Matrix?: blinks a smiley face on the LED matrix. Mellis Added lines 43-46: Stepper Library Motor Knob: control a stepper motor with a potentiometer. Mellis .Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. Restore July 02. Added lines 37-42: . at 09:36 PM by David A. 2008. at 03:11 PM by David A. at 02:07 PM by David A.adding EEPROM examples.

2008.moving the resources to the links page. 2008. see the Arduino Getting Started. Restore April 29. at 09:22 PM by David A. Added line 15: BlinkWithoutDelay: blinking an LED without using the delay() function. Restore May 21. Changed lines 2-5 from: Arduino Tutorials Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. For instructions on getting the board and environment up and running. Mellis . at 06:55 PM by David A. EEPROM Write: stores values from an analog input to the EEPROM. The code is included in the tutorial. Deleted lines 43-44: Added lines 49-51: Timing & Millis Stopwatch Deleted lines 75-125: . Mellis Changed line 15 from: BlinkWithoutDelay: blinking an LED without using the delay() function. to: Blink Without Delay: blinking an LED without using the delay() function. EEPROM Read: read the EEPROM and send its values to the computer.EEPROM Library EEPROM Clear: clear the bytes in the EEPROM. and the links page for other documentation. Changed lines 37-42 from: Timing & Millis Blinking an LED without using the delay() function Stopwatch (:if false:) TimeSinceStart: (:ifend:) to: (:cell width=50%:) Changed lines 41-42 from: These are more complex examples for using particular electronic components or accomplishing specific tasks. The code is included on the page. to: Arduino Examples See the foundations page for in-depth description of core concepts of the Arduino hardware and software. to: These are more complex examples for using particular electronic components or accomplishing specific tasks.

circuits. pull-up and pull-down resistors. this one focusing on physical sensing and making motion. and Other Resources Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino. at 05:59 PM by Paul Badger Changed line 39 from: to: . procedures and hacking code Lesson 3: Breadboards.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. Electronics Techniques: tutorials on soldering and other electronics resources. arduino+processing. Manuals. servos. 2008. using Arduino. debouncing and your first contract product design. Hosted on the publicly-editable playground wiki. Output Input Interaction Storage Communication Interfacing with Software: how to get an Arduino board talking to software running on the computer (e. at 10:29 PM by David A. Examples from Tom Igoe Examples from Jeff Gray Restore April 23.g. and basic RGB color-mixing Lesson 4: The serial library and binary data . a simple blinking light Lesson 2: Sketches. Curricula. Max/MSP). By ladyada. and pwm) (piezo sound & sensors. and instructions for using various electronic components with an Arduino board. communication. Lesson 0: Pre-flight check. variables. digital inputs. etc. Interfacing With Hardware: Code. 2008. schematics. Tutorials Tutorials created by the Arduino community. Mellis Changed line 6 from: (:table width=90% border=0 cellpadding=5 cellspacing=0:) to: (:table width=100% border=0 cellpadding=5 cellspacing=0:) Restore April 22. stand-alone operation) Bionic Arduino: another Arduino class from TodBot. if/if-else statements..Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. input / output. Code Library and Tutorials: Arduino functions for performing specific tasks and other programming tutorials. Board Setup and Configuration: Information about the components and usage of Arduino hardware. Learn electronics using Arduino: an introduction to programming.(:cell width=50%:) Foundations See the foundations page for explanations of the concepts involved in the Arduino hardware and software. Example labs from ITP Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class class class class 1 2 3 4 (getting started) (input and sensors) (communication. Flash.. PD. Processing. resistors and LEDs.

2008. Mellis . Mellis Changed line 43 from: * TwoSwitchesOnePin: Read two switches with one I/O pin to: TwoSwitchesOnePin: Read two switches with one I/O pin Restore April 08. at 07:41 PM by Paul Badger Changed lines 18-19 from: to: TwoSwitchesOnePin: Read two switches with one I/O pin Restore March 09. at 08:22 PM by David A. Restore March 07. Mellis Changed lines 73-78 from: Foundations has moved here Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. to: See the foundations page for explanations of the concepts involved in the Arduino hardware and software. 2008. at 05:56 PM by Paul Badger Added lines 40-41: TimeSinceStart: Restore April 18. 2008. at 07:22 AM by Paul Badger Added lines 36-39: Timing & Millis Blinking an LED without using the delay() function Stopwatch Changed line 46 from: Blinking an LED without using the delay() function to: Restore April 08. Changed lines 18-19 from: TwoSwitchesOnePin: Read two switches with one I/O pin to: Added line 43: * TwoSwitchesOnePin: Read two switches with one I/O pin Restore April 08. 2008.(:if false:) Changed line 41 from: to: (:ifend:) Restore April 22. 2008.moving TwoSwitchesOnePin to "other examples" since it's not (yet) in the distribution. 2008. at 08:23 PM by David A. 2008. at 07:20 PM by David A. at 09:26 PM by Paul Badger Changed lines 73-75 from: to: .

. Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs. at 09:09 PM by Paul Badger Added lines 80-81: Foundations Restore February 15. Mellis Changed lines 72-73 from: Tutorials to: Foundations Changed lines 108-109 from: More Tutorials to: Tutorials Restore February 13. see the Arduino guide. Interrupts?: Code that interrupts other code under certain conditions. Foundations (:if false:) PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. Debugging?: Figuring out what's wrong with your hardware or software and how to fix it. Arrays?: How to store multiple values of the same type. Midi. at 06:00 PM by David A. Communication?: An overview of the various ways in which an Arduino board can communicate with other devices (serial. Numbers?: The various types of numbers available and how to use them. 2008. Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. For instructions on getting the board and environment up and running. etc. 2008.) Serial Communication?: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). 2008. (:ifend:) to: Restore March 07. I2C. Optimization?: What to do when your program runs too slowly. at 10:42 PM by Paul Badger Changed lines 4-5 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. SPI. at 09:24 PM by Paul Badger Changed lines 74-107 from: Memory: The various types of memory available on the Arduino board. Variables: How to define and use variables. Pointers?: Functions?: How to write and call functions.Foundations has moved here Restore March 07. 2008.

Midi. SPI. at 09:36 PM by David A. Arrays?: How to store multiple values of the same type. 2008. at 09:38 PM by David A. For instructions on getting the board and environment up and running. at 09:31 PM by David A. Mellis Added lines 100-103: Optimization?: What to do when your program runs too slowly. 2008. at 09:41 PM by David A.) Serial Communication?: How to send serial data from an Arduino board to a computer or other device. at 09:30 PM by David A. at 09:58 PM by David A. Mellis Added lines 90-99: Numbers?: The various types of numbers available and how to use them. to: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. etc. Restore February 13. Mellis Added lines 80-81: (:if false:) Added lines 84-89: Communication?: An overview of the various ways in which an Arduino board can communicate with other devices (serial. Debugging?: Figuring out what's wrong with your hardware or software and how to fix it. 2008. Mellis Added lines 80-81: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. Mellis Changed lines 86-87 from: Serial Communication?: How to send serial data from an Arduino board to a computer or other device. Interrupts?: Code that interrupts other code under certain conditions. at 10:06 PM by David A. Pointers?: Functions?: How to write and call functions. Restore February 13. 2008. Mellis Restore February 13. Mellis Changed lines 80-81 from: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. (:ifend:) Restore February 13. Restore February 13. Restore February 13. 2008. I2C. to: Serial Communication?: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). see the Arduino Getting Started. . 2008.to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. 2008. Restore February 13. Variables: How to define and use variables.

Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. at 11:31 AM by David A. 2008. 2008. Mellis .adding links to other pages: the tutorial parts of the playground. etc. 2007.linking to board setup and configuration on the playground. at 11:54 PM by David A.g. The code is included in the tutorial. Restore February 13. Mellis Added lines 74-81: Memory: The various types of memory available on the Arduino board. Changed lines 71-78 from: Other Arduino Tutorials Tutorials from the Arduino playground Example labs from ITP Spooky Arduino and more from Todbot Examples from Tom Igoe Examples from Jeff Gray to: (:cell width=50%:) Tutorials Tutorials created by the Arduino community. . Max/MSP). Added lines 76-77: Board Setup and Configuration: Information about the components and usage of Arduino hardware. Interfacing With Hardware: Code. at 09:12 PM by David A. Mellis . Restore December 19. Changed lines 36-42 from: (:cell width=50%:) Tutorials These are more complex tutorials for using particular electronic components or accomplishing specific tasks. Hosted on the publicly-editable playground wiki. Flash. Output Input Interaction Storage Communication Interfacing with Software: how to get an Arduino board talking to software running on the computer (e. todbot. circuits. and instructions for using various electronic components with an Arduino board. ladyada's tutorials. Processing. More Tutorials Restore January 11. to: Other Examples These are more complex examples for using particular electronic components or accomplishing specific tasks. at 09:22 PM by David A. Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs.Restore February 13. Mellis Added lines 80-81: Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. The code is included in the tutorial. PD. 2008.

and basic RGB color-mixing Lesson 4: The serial library and binary data . at 05:04 PM by David A.adding debounce example. These are included with the Arduino environment. (If you're looking for an older example. schematics. check the Arduino 0007 tutorials page. and pwm) (piezo sound & sensors. servos. Examples from Tom Igoe Examples from Jeff Gray Restore December 13. Mellis Changed lines 10-11 from: Simple programs that demonstrate the use of the Arduino board. if/if-else statements. Restore August 28. arduino+processing. using Arduino. Added line 16: Debounce: read a pushbutton. procedures and hacking code Lesson 3: Breadboards. at 11:14 PM by David A. Lesson 0: Pre-flight check. Example labs from ITP Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class class class class 1 2 3 4 (getting started) (input and sensors) (communication. see processing. etc. pull-up and pull-down resistors. These are included with the Arduino environment. to open them. debouncing and your first contract product design. By ladyada.. For more information or to download Processing. this one focusing on physical sensing and making motion. Manuals. communication. stand-alone operation) Bionic Arduino: another Arduino class from TodBot. at 11:15 PM by Tom Igoe Changed lines 71-72 from: to: X10 output control devices over AC powerlines using X10 Restore June 15.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. 2007. click the Open button on the toolbar and look in the examples folder. Mellis . at 08:57 AM by David A. 2007. a simple blinking light Lesson 2: Sketches. to open . at 11:08 PM by David A. Mellis . 2007. 2007. Electronics Techniques: tutorials on soldering and other electronics resources.. variables. Restore June 12.removing link to obsolete joystick example.org.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. Learn electronics using Arduino: an introduction to programming. and Other Resources Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino. resistors and LEDs. filtering noise. input / output.adding link to Processing (for the communication examples) Added lines 27-28: These examples include code that allows the Arduino to talk to Processing sketches running on the computer. Mellis . digital inputs. 2007. Curricula. Deleted line 43: Interfacing a Joystick Restore June 11.Code Library and Tutorials: Arduino functions for performing specific tasks and other programming tutorials. to: Simple programs that demonstrate the use of the Arduino board.

updating to 0008 examples Changed lines 10-11 from: Digital Output Blinking LED to: Simple programs that demonstrate the use of the Arduino board. (If you're looking for an older example. 2007. at 11:10 PM by David A. click the Open button on the toolbar and look in the examples folder. Restore June 11. to open them. to open them. Miscellaneous Deleted lines 42-51: Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) More complex dimming/color crossfader Knight Rider example Shooting star PWM all of the digital pins in a sinewave pattern Digital Input Digital Input and Output (from ITP physcomp labs) . 2007. to: Simple programs that demonstrate the use of the Arduino board. Digital I/O Blink: turn an LED on and off. Fading: uses an analog output (PWM pin) to fade an LED. (:cell width=50%:) Tutorials These are more complex tutorials for using particular electronic components or accomplishing specific tasks. Virtual Color Mixer: sending multiple variables from Arduino to the computer and reading them in Processing. Button: use a pushbutton to control an LED. Knock: detect knocks with a piezo element. Mellis . click the Open button on the toolbar and look in the examples folder. click the Open button on the toolbar and look in the examples folder. Graph: sending data to the computer and graphing it in Processing. Loop: controlling multiple LEDs with a loop and an array. Smoothing: smooth multiple readings of an analog input. Physical Pixel: turning on and off an LED by sending data from Processing. click the Open button on the toolbar and look in the examples folder. The code is included in the tutorial. check the Arduino 0007 tutorials page. Mellis Changed lines 10-11 from: Simple programs that demonstrate the use of the Arduino board. These are included with the Arduino environment. These are included with the Arduino environment. These are included with the Arduino environment. to open them.them. Dimmer: move the mouse to change the brightness of an LED. Communication ASCII Table: demonstrates Arduino's advanced serial output functions. Analog I/O Analog Input: use a potentiometer to control the blinking of an LED. check the Arduino 0007 tutorials page. (If you're looking for an older example. at 11:13 PM by David A.) Restore June 11.

Read a Pushbutton Using a pushbutton as a switch Deleted lines 43-45: Analog Input Read a Potentiometer Deleted lines 45-46: Read a Piezo Sensor 3 LED cross-fades with a potentiometer Changed lines 52-53 from: Use two Arduino pins as a capacitive sensor to: Deleted line 54: More sound ideas Added line 64: Build your own DMX Master device Changed lines 70-72 from: Multiple digital inputs with a CD4021 Shift Register Other Arduino Examples to: Other Arduino Tutorials Tutorials from the Arduino playground Added line 75: Spooky Arduino and more from Todbot Deleted lines 78-105: (:cell width=50%:) Interfacing with Other Software Introduction to Serial Communication (from ITP physcomp labs) Arduino + Flash Arduino + Processing Arduino + PD Arduino + MaxMSP Arduino + VVVV Arduino + Director Arduino + Ruby Arduino + C Tech Notes (from the forums or playground) Software serial (serial on pins besides 0 and 1) L297 motor driver Hex inverter Analog multiplexer Power supplies The components on the Arduino board Arduino build process AVRISP mkII on the Mac Non-volatile memory (EEPROM) Bluetooth Zigbee .

2007.LED as light sensor (en Francais) Arduino and the Asuro robot Using Arduino from the command line Restore May 11. at 07:07 PM by Paul Badger Changed lines 36-37 from: http://www.cc/cgi-bin/yabb2/YaBB. 2007. at 03:40 PM by Clay Shirky Changed lines 13-14 from: Dimming 3 LEDs with Pulse-Width Modulation (PWM) to: Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) More complex dimming/color crossfader Restore February 08.arduino. 2007. 2007. at 07:04 PM by Paul Badger Changed lines 36-37 from: to: http://www. at 02:52 PM by Carlyn Maw Changed lines 52-54 from: Multiple digital ins with a CD4021 Shift Register to: Restore .cc/cgi-bin/yabb2/YaBB.cc/cgi-bin/yabb2/YaBB.pl?num=1171076259 Use a couple of Arduino pins as a capacitive sensor Restore May 10.cc/cgi-bin/yabb2/YaBB. at 07:05 PM by Paul Badger Changed lines 36-37 from: http://www. at 06:59 PM by Paul Badger Added line 39: More sound ideas Restore April 24.arduino.arduino. at 06:06 AM by Paul Badger Changed lines 17-18 from: to: PWM all of the digital pins in a sinewave pattern Restore May 10. at 12:02 PM by Carlyn Maw Changed lines 52-53 from: to: Multiple digital inputs with a CD4021 Shift Register Restore February 06.pl?num=1171076259 |Use a couple of Arduino pins as a capacitive sensor]] Restore May 10. 2007.pl?num=1171076259 |Use a couple of Arduino pins as a capacitive sensor]] to: Use two Arduino pins as a capacitive sensor Restore May 10.arduino. 2007. 2007. 2007.pl?num=1171076259 Use a couple of Arduino pins as a capacitive sensor to: http://www.

at 03:10 PM by Carlyn Maw Changed lines 50-51 from: to: Multiple digital outs with a 595 Shift Register Restore November 06. Changed lines 69-70 from: to: Arduino + C Restore December 02. at 10:43 AM by David A. 2006. Mellis Changed lines 37-38 from: MIDI Output (from ITP physcomp labs) to: MIDI Output (from ITP physcomp labs) and from Spooky Arduino Restore November 04. Mellis Added line 20: Using a pushbutton as a switch Restore December 07. 2006. Mellis Added line 64: Arduino + MaxMSP Changed lines 67-68 from: to: Arduino + Ruby Restore November 18. at 10:49 AM by David A. Mellis Added line 1: (:title Tutorials:) Restore November 21. at 10:13 AM by David A. 2006. at 06:04 AM by David A. 2006. Mellis Changed lines 20-21 from: Controlling an LED circle with a joystick to: Added line 24: Controlling an LED circle with a joystick Restore November 09.adding link to todbot's C serial port code. Mellis Deleted line 46: Build your own DMX Master device Restore December 25. 2007. at 11:57 PM by David A. 2006. at 02:42 AM by David A. at 03:37 PM by David A. at 02:51 PM by Carlyn Maw Changed lines 52-53 from: to: Multiple digital ins with a CD4021 Shift Register Restore January 30.February 06. Mellis Deleted line 53: . 2007. Mellis . 2006. at 12:25 PM by David A. 2006. 2006.

Deleted line 54: Restore November 04. 2006. 2006. 2006. at 10:38 AM by David A. For instructions on getting the board and environment up and running. 2006. . at 12:23 PM by David A. to: Example labs from ITP Examples from Tom Igoe. Restore November 04. Mellis Changed lines 3-4 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. Restore November 04. or is there something you would like to see published in this site? Refer to the forum for further help. see the examples from Tom Igoe and those from Jeff Gray. to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. at 12:24 PM by David A. see the Arduino guide?. Examples from Jeff Gray. Mellis Added lines 51-58: Other Arduino Examples Example labs from ITP Examples from Tom Igoe Examples from Jeff Gray Deleted lines 83-89: Other Arduino Examples Example labs from ITP Examples from Tom Igoe. Restore November 04. Examples from Jeff Gray. Mellis Changed lines 50-51 from: Example labs from ITP to: Changed lines 77-78 from: Also. see the Arduino guide. For instructions on getting the board and environment up and running. at 12:24 PM by David A. Mellis Changed line 77 from: Other Arduino Sites to: Other Arduino Examples Deleted lines 79-81: Do you need extra help? Is there a sensor you would like to see characterized for Arduino.

servos. 2006. class 3 (communication. Mellis Changed lines 3-4 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. class 2 (input and sensors). Kurt Changed lines 67-68 from: todbot has some very detailed. servos. class 4 (piezo sound & sensors. Course Guides todbot has some very detailed. Deleted lines 52-67: The Arduino board This guide to the Arduino board explains the functions of the various parts of the board. For instructions on getting the board and environment up and running. at 10:47 AM by Tod E. to: todbot has some very detailed. at 10:17 AM by David A. at 10:37 AM by David A. Mellis . 2006. illustrated tutorials from his Spooky Projects course: class 1 (getting started). For instructions on getting the board and environment up and running. stand-alone operation) . and pwm). arduino+processing. hack a day has links to interesting hacks and how-to articles on various topics. at 06:54 PM by Carlyn Maw Deleted line 49: Extend your digital outs with 74HC595 shift registers Restore November 01. Video Lectures by Tom Igoe Watch Tom introduce Arduino. class 3 (communication. illustrated tutorials from his Spooky Projects course: class 1 (getting started). The libraries page explains how to use libraries in your sketches and how to make your own. and pwm). to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino.lots of content moved to the new guide.Restore November 04. class 3 (communication. see the Arduino guide?. and pwm). see the Howto. Thanks to Pollie Barden for the great videos. Make magazine has some great links in its electronics archive. stand-alone operation) Deleted lines 82-87: External Resources Instant Soup is an introduction to electronics through a series of beautifully-documented fun projects. 2006. 2006. 2006. class 4 (piezo sound & sensors. arduino+processing. class 2 (input and sensors). servos. The Arduino environment This guide to the Arduino IDE (integrated development environment) explains the functions of the various buttons and menus. at 06:06 PM by Carlyn Maw Added line 50: Extend your digital outs with 74HC595 shift registers Restore October 31. class 2 (input and sensors). illustrated tutorials from his Spooky Projects course: class 1 (getting started). Restore November 01. Restore November 04.

2006. class 3 (communication. class 2 (input and sensors). to: Arduino Tutorials Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. to: This guide to the Arduino IDE (integrated development environment) explains the functions of the various buttons and menus. 2006. servos. Restore October 08. at 12:52 PM by David A. to: Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. Added lines 66-68: Course Guides todbot has some very detailed. and pwm). The libraries page explains how to use libraries in your sketches and how to make your own. Restore October 08. Restore October 21. see the Howto?. Mellis Changed lines 3-4 from: Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. For instructions on getting the board and IDE up and running. Mellis Changed lines 67-68 from: todbot has some very detailed. illustrated tutorials from his Spooky Projects course: class 1 (getting started). class 2 (input and sensors). 2006. The libraries? page explains how to use libraries in your sketches and how to make your own. see the Howto. at 05:45 PM by David A.adding links to todbot's class notes. Mellis Changed lines 1-4 from: Learning to use Arduino Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. Restore October 08. see the Howto. at 05:46 PM by David A. For instructions on getting the board and environment up and running. For instructions on getting the board and IDE up and running. Restore October 22. Mellis . at 12:51 PM by David A. For instructions on getting the board and IDE up and running. class 2 (input and sensors). illustrated tutorials from his Spooky Projects course: class 1 (getting started). to: todbot has some very detailed.Restore October 22. at 04:25 PM by David A. Mellis Changed lines 59-62 from: This guide to the Arduino IDE? (integrated development environment) explains the functions of the various buttons and menus. 2006. Mellis Added lines 1-102: Learning to use Arduino Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do . 2006. see the Howto. 2006. illustrated tutorials from his Spooky Projects course: class 1 (getting started). at 05:38 PM by David A.

with it. For instructions on getting the board and IDE up and running. The libraries? page explains how to use libraries in your sketches and how to make your own. The Arduino environment This guide to the Arduino IDE? (integrated development environment) explains the functions of the various buttons and menus. (:table width=90% border=0 cellpadding=5 cellspacing=0:) (:cell width=50%:) Examples Digital Output Blinking LED Blinking an LED without using the delay() function Dimming 3 LEDs with Pulse-Width Modulation (PWM) Knight Rider example Shooting star Digital Input Digital Input and Output (from ITP physcomp labs) Read a Pushbutton Read a Tilt Sensor Controlling an LED circle with a joystick Analog Input Read a Potentiometer Interfacing a Joystick Read a Piezo Sensor 3 LED cross-fades with a potentiometer 3 LED color mixer with 3 potentiometers Complex Sensors Read an Accelerometer Read an Ultrasonic Range Finder (ultrasound sensor) Reading the qprox qt401 linear touch sensor Sound Play Melodies with a Piezo Speaker Play Tones from the Serial Connection MIDI Output (from ITP physcomp labs) Interfacing w/ Hardware Multiply the Amount of Outputs with an LED Driver Interfacing an LCD display with 8 bits LCD interface library Driving a DC Motor with an L293 (from ITP physcomp labs). Driving a Unipolar Stepper Motor Build your own DMX Master device Implement a software serial connection RS-232 computer interface Interface with a serial EEPROM using SPI Control a digital potentiometer using SPI Example labs from ITP (:cell width=50%:) The Arduino board This guide to the Arduino board explains the functions of the various parts of the board. see the Howto?. .

Video Lectures by Tom Igoe Watch Tom introduce Arduino. Make magazine has some great links in its electronics archive. Interfacing with Other Software Introduction to Serial Communication (from ITP physcomp labs) Arduino + Flash Arduino + Processing Arduino + PD Arduino + VVVV Arduino + Director Tech Notes (from the forums or playground) Software serial (serial on pins besides 0 and 1) L297 motor driver Hex inverter Analog multiplexer Power supplies The components on the Arduino board Arduino build process AVRISP mkII on the Mac Non-volatile memory (EEPROM) Bluetooth Zigbee LED as light sensor (en Francais) Arduino and the Asuro robot Using Arduino from the command line Other Arduino Sites Also. hack a day has links to interesting hacks and how-to articles on various topics. Thanks to Pollie Barden for the great videos. External Resources Instant Soup is an introduction to electronics through a series of beautifully-documented fun projects. see the examples from Tom Igoe and those from Jeff Gray. (:tableend:) Restore Edit Page | Page History | Printable View | All Recent Site Changes . Do you need extra help? Is there a sensor you would like to see characterized for Arduino. or is there something you would like to see published in this site? Refer to the forum for further help.

filtering noise. Loop: controlling multiple LEDs with a loop and an array. and the links page for other documentation. Reading Knock: detect knocks with a piezo element. Read an Fading: uses an analog output (PWM pin) to fade sensor) an LED. see processing. Dimmer: move the mouse to change the brightness of an LED. The code is included on the page. Virtual Color Mixer: sending multiple variables from Arduino to the computer and reading them in Processing.) Other Examples These are more complex examples for using particular electronic components or accomplishing specific tasks. (If you're looking for an older example. click the Open button on the toolbar and look in the examples folder.Arduino : Tutorial / Tutorials Learning Examples | Foundations | Hacking | Links Examples See the foundations page for in-depth description of core concepts of the Arduino hardware and software. Button: use a pushbutton to control an LED. to open them.org. Examples Simple programs that demonstrate the use of the Arduino board. Timing & Millis Stopwatch Analog I/O Complex Sensors ADXL3xx accelerometer Accelerometer Ultrasonic Range Finder (ultrasound the qprox qt401 linear touch sensor Read an Analog Input: use a potentiometer to control the Read an blinking of an LED. Communication These examples include code that allows the Arduino to talk to Processing sketches running on the computer. check the Arduino 0007 tutorials page. Miscellaneous TwoSwitchesOnePin: Read two switches with one I/O pin Read a Tilt Sensor Controlling an LED circle with a joystick 3 LED color mixer with 3 potentiometers Digital I/O Blink: turn an LED on and off. ASCII Table: demonstrates Arduino's advanced serial output functions. These are included with the Arduino environment. Blink Without Delay: blinking an LED without using the delay() function. the hacking page for information on extending and modifying the Arduino hardware and software. Physical Pixel: turning on and off an LED by sending data from Processing. Debounce: read a pushbutton. Play Melodies with a Piezo Speaker Play Tones from the Serial Connection MIDI Output (from ITP physcomp labs) and from Spooky Arduino Interfacing w/ Hardware Multiply the Amount of Outputs with an LED Driver Interfacing an LCD display with 8 bits LCD interface library Driving a DC Motor with an L293 (from ITP physcomp labs). Smoothing: smooth multiple readings of an analog Sound input. Graph: sending data to the computer and graphing it in Processing. For more information or to download Processing. Driving a Unipolar Stepper Motor Build your own DMX Master device Implement a software serial connection RS-232 computer interface Interface with a serial EEPROM using SPI .

cc/en/Tutorial/HomePage) .arduino. (Printable View of http://www. EEPROM Read: read the EEPROM and send its values to the computer. Control a digital potentiometer using SPI Multiple digital outs with a 595 Shift Register X10 output control devices over AC powerlines using X10 Stepper Library Motor Knob: control a stepper motor with a potentiometer. EEPROM Write: stores values from an analog input to the EEPROM.EEPROM Library EEPROM Clear: clear the bytes in the EEPROM.

providing more in-depth explanations of the underlying functionality and principles involved. Also. Foundations Page Edit Page | Page History | Printable View | All Recent Site Changes . This section is a work in progress. feel free to take a shot at writing it up. You can post works-in-progress to the playground and mention them on the forum. be sure to let us know if you think there's anything that we've forgotten. These pages are cross-linked with the applicable language reference. and there are many topics yet to be covered. providing a single source for people looking for a longer discussion of a particular topic. example.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Foundations Page Discussion The Foundations page is intended to supplement the material in the examples and reference. and other pages. we can always edit and improve it. Here's a rough list of ideas: PROGRAMMING conditionals loops functions numbers and arithmetic bits and bytes characters and encodings arrays strings ELECTRONICS voltage. or if you have other suggestions. Don't worry if it's not finished or polished. and resistance resistive sensors capacitors transistors power noise COMMUNICATION serial communication i2c (aka twi) bluetooth MICROCONTROLLER reset pins and ports interrupts If you see anything in the list that interests you. current.

Variables A variable is a place for storing a piece of data. and isn't required). It's a good practice to comment your sketches. Linux).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » First Sketch In the getting started guide (Windows. its value will be retrieved. however. and an initial value of 13. There's another style for short. It's being used to indicate which Arduino pin the LED is connected to. the line from the Blink sketch above declares a variable with the name ledPin . // LED connected to digital pin 13 the message "LED connected to digital pin 13" is a comment. you uploaded a sketch that blinks an LED. There's more information in the Variables tutorial. These start with // and continue to the end of the line. you could store the value read from an input into a variable. This helps other people to learn from or modify your code. * depending on your Arduino board.arduino. the type int . you'll learn how each part of that sketch works. It has a name. Often.. For example. In this case. and so on. Functions A function (otherwise known as a procedure or sub-routine ) is a named piece of code that can be used from elsewhere in a sketch. Comments The first few lines of the Blink sketch are a comment: /* * Blink * * The basic Arduino example. how it works. Mac OS X. and a value. We use pin 13 because. The advantage of using a variable is that it's easier to move the LED to a different pin: you only need to edit the one line that assigns the initial value to the variable. * then off for one second. For example.cc/en/Tutorial/Blink */ Everything between the /* and */ is ignored by the Arduino when it runs the sketch (the * at the start of each line is only there to make the comment look pretty. It's there for people reading the code: to explain what the program does. or why it's written the way it is. the person writing the program could have chosen not to bother creating the ledPin variable and instead have simply written 13 everywhere they needed to specify a pin number. here's the definition of the setup() function from the Blink example: void setup() { .. For example. and to keep the comments up-to-date when you modify the code. it has either a built-in LED * or a built-in resistor so that you need only an LED. the value of a variable will change while the sketch runs. Every time the name ledPin appears in the code. For example. In this tutorial. Sketch A sketch is the name that Arduino uses for a program. single-line comments. a type. It's the unit of code that is uploaded to and run on an Arduino board. Turns on an LED on for one second. * * http://www. in the line: int ledPin = 13.

or 0 volts. OUTPUT). Exercises 1. the line pinMode(ledPin. For example. creates a delay of one second. when the sketch starts. When configured as an input. It's a good place to do setup tasks like setting pin modes or initializing libraries. setup() and loop() There are two special functions that are a part of every Arduino sketch: setup() and loop() . HIGH). The code between the { and } is called the body of the function: what the function does. You can call a function that's already been defined (either in your sketch or as part of the Arduino language). or 5 volts. The loop() function is called over and over and is heart of most sketches. Change the code so that the LED is on for 100 milliseconds and off for 1000. For example. As an output. Writing a LOW to pin connects it to ground. 2. You need to include both functions in your sketch. These parameters are used by the pinMode() function to decide which pin and mode to set.pinMode(ledPin. pinMode(). Change the code so that the LED turns on when the sketch starts and stays on. this is discussed in a later tutorial?. The text before and after the name specify its return type and parameters: these will be explained later. See Also setup() loop() pinMode() digitalWrite() delay() Edit Page | Page History | Printable View | All Recent Site Changes . like its name. } // sets the digital pin as output The first line provides information about the function. To use it. digitalWrite(). so the line: delay(1000). set the ledPin (pin 13) to HIGH. a pin can detect the state of a sensor like a pushbutton. OUTPUT). "setup". passing it two parameters : ledPin and OUTPUT . you pass it the number of the pin to configure and the constant INPUT or OUTPUT. The digitalWrite() functions outputs a value on a pin. and delay() The pinMode() function configures a pin as either an input or an output. even if you don't need them for anything. calls the pinMode() function. The setup() is called once. There are 1000 milliseconds in a second. The delay() causes the Arduino to wait for the specified number of milliseconds before continuing on to the next line. the line: digitalWrite(ledPin. it can drive an actuator like an LED.

or motors. HIGH). and can make the pins useful for such tasks as implementing a capacitive touch sensor. or run many sensors. or damage the entire Atmega chip. Short circuits on Arduino pins. This works in the other direction as well. // set pin to input // turn on pullup resistors Note that the pullup resistors provide enough current to dimly light an LED connected to a pin that has been configured as an input. will have the pin configured as HIGH if the pin is then swtiched to an OUTPUT with pinMode(). This also means however that input pins with nothing connected to them. pinMode(pin. or attempting to run high current devices from them. This means that they can provide a substantial amount of current to other circuits. Pins configured as inputs are said to be in a high-impedance state. this is likely what is going on. This can be done by adding a pullup resistor(to +5V). and the programmer has forgotten to use pinMode() to set the pins to outputs. digitalWrite(pin. say equivalent to a series resistor of 100 Megohms in front of the pin. with 10K being a common value. Consequently a pin that is configured to have pullup resistors turned on when the pin is an INPUT. These built-in pullup resistors are accessed in the following manner. This means that it takes very little current to move the input pin from one state to another. unless maximum current draw from the pins is required for a particular application. Often this will result in a "dead" pin in the microcontroller but the remaining chip will still function adequately. will report seemingly random changes in pin state. If LED's in a project seem to be working. or capacitively coupling the state of a nearby pin for example. or with wires connected to them that are not connected to other circuits. One way of explaining this is that input pins make extremely small demands on the circuit that they are sampling. For this reason it is a good idea to connect OUTPUT pins to other devices with 470O or 1k resistors. so they don't need to be explicitly declared as inputs with pinMode(). Atmega pins can source (provide positive current) or sink (provide negative current) up to 40 mA (milliamps) of current to other devices/circuits. INPUT). Pullup Resistors Often it is useful to steer an input pin to a known state if no input is present.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Pins Pins Configured as INPUT Arduino (Atmega) pins default to inputs. but very dimly. can damage or destroy the output transistors in the pin. This is enough current to brightly light up an LED (don't forget the series resistor). and an output pin that is left in a HIGH state will have the pullup resistors set if switched to an input with pinMode(). Foundations Edit Page | Page History | Printable View | All Recent Site Changes . Note also that the pullup resistors are controlled by the same registers (internal chip memory locations) that control whether a pin is HIGH or LOW. picking up electrical noise from the environment. but not enough current to run most relays. or pulldown resistor (resistor to ground) on the input. There are also convenient 20K pullup resistors built into the Atmega chip that can be accessed from software. solenoids. for example. Pins Configured as OUTPUT Pins configured as OUTPUT with pinMode() are said to be in a low-impedance state.

so if this is the case. Details and Caveats The analogRead command will not work correctly if a pin has been previously set to an output. They are enabled by issuing a command such as digitalWrite(14. // set pullup on analog pin 0 Edit Page | Page History | Printable View | All Recent Site Changes . The converter has 10 bit resolution. The analog pins can be used identically to the digital pins. after manipulating analog pins (in digital mode). to set analog pin 0 to an output.13). While the main function of the analog pins for most Arduino users is to read analog sensors. Consequently. the code would look like this: pinMode(14. set it back to an input before using analogRead. which work identically to pullup resistors on the digital pins. Be aware however that turning on a pullup will affect the value reported by analogRead() when using some sensors if done inadvertently. digitalWrite(14. This can cause electrical noise and introduce jitter in the analog system. It may be desirable. The Atmega168 datasheet also cautions against switching digital pins in close temporal proximity to making A/D readings (analogRead) on other analog pins. the analog pins may be used for GPIO. and do not correspond to the physical pin numbers on the Atmega168 chip. and to set it HIGH. Pin mapping The Arduino pin numbers corresponding to the analog pins are 14 through 19. Note that these are Arduino pin numbers. Pullup resistors The analog pins also have pullup resistors. OUTPUT). so for example. Most users will want to use the pullup resistors only when using an analog pin in its digital mode. the analog pins also have all the functionality of general purpose input/output (GPIO) pins (the same as digital pins 0 . HIGH). A/D converter The Atmega168 contains an onboard 6 channel analog-to-digital (A/D) converter. returning integers from 0 to 1023. if a user needs more general purpose input output pins. to add a short delay before using analogRead() to read other analog pins.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Analog Pins A description of the analog input pins on an Atmega168 (Arduino chip). and all the analog pins are not in use. Similarly if the pin has been set to HIGH as an output. HIGH). while the pin is an input .

such that analogWrite(255) requests a 100% duty cycle (always on). those little lines will grow and shrink in length. a signal switched between on and off. In the graphic below. Digital control is used to create a square wave. Written by Timothy Hirzel Foundations . Once you get this example running. the green lines would measure 2 milliseconds each. or modulate. and analogWrite(127) is a 50% duty cycle (on half the time) for example. In other words. As the LED fades in and out. A call to analogWrite() is on a scale of 0 . with Arduino's PWM frequency at about 500Hz. Pulse Width Modulation. This on-off pattern can simulate voltages in between full on (5 Volts) and off (0 Volts) by changing the portion of the time the signal spends on versus the time that the signal spends off. the green lines represent a regular time period. is a technique for getting analog results with digital means. To get varying analog values. grab your arduino and shake it back and forth. or PWM. the movement blurs each LED blink into a line. To our eyes. that pulse width. Now you are seeing the pulse width. It is available in the File->Sketchbook>Examples->Analog menu of the Arduino software.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » PWM The Fading example demonstrates the use of analog output (PWM) to fade an LED. This duration or period is the inverse of the PWM frequency.255. the result is as if the signal is a steady voltage between 0 and 5v controlling the brightness of the LED. What you are doing here is essentially mapping time across the space. The duration of "on time" is called the pulse width. If you repeat this on-off pattern fast enough with an LED for example. you change.

Edit Page | Page History | Printable View | All Recent Site Changes .

you're probably running out of SRAM. There are a few things you can do to address this problem: If your sketch talks to a program running on a (desktop/laptop) computer. you can try commenting out or shortening the strings or other data structures in your sketch (without changing the code). but not run. see the EEPROM library. Flash memory and EEPROM memory are non-volatile (the information persists after the power is turned off). for example. puts 32 bytes into SRAM (each character takes a byte). an int takes up two bytes. to do this. The ATmega168 chip has the following amounts of memory: Flash 16k bytes (of which 2k is used for the bootloader) SRAM 1024 bytes EEPROM 512 bytes Notice that there's not much SRAM available. If you don't need to modify the strings or data while your sketch is running. EEPROM is memory space that programmers can use to store long-term information. you can store them in flash (program) memory instead of SRAM. To use the EEPROM. It's easy to use it all up by having lots of strings in your program.". it will appear to upload successfully. use the smallest data type necessary to store the values you need. Foundations Edit Page | Page History | Printable View | All Recent Site Changes . If you run out of SRAM. To check if this is happening. but it doesn't take long to get to 1024. or run strangely. If you have lookup tables or other large arrays. For example. while a byte uses only one (but can store a smaller range of values). SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs. a declaration like: char message[] = "I support the Cape Wind project. is where the Arduino sketch is stored. This might not seem like a lot. SRAM is volatile and will be lost when the power is cycled. for example. reducing the load on the Arduino.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Memory There are three pools of memory in the microcontroller used on Arduino boards (ATmega168): Flash memory (program space). especially if you have a large amount of text to send to a display. If it then runs successfully. or a large lookup table. your program may fail in unexpected ways. use the PROGMEM keyword. you can try shifting data or calculations to the computer.

requires one of these external programmers. If.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Bootloader The bootloader is a small piece of software that we've burned onto the chips that come with your Arduino boards. Usually. Edit Page | Page History | Printable View | All Recent Site Changes . no data arrives from the computer. however. The bootloader pulses digital pin 13 (you can connect an LED to make sure that the bootloader is installed). Then. If the chip is still "virgin" the bootloader is the only program in memory and will start itself again. It allows you to upload sketches to the board without external hardware.about 8-10 seconds . On the NG. the bootloader launches whatever program was last uploaded onto the chip. Looking for more information? See the bootloader development page for information on burning a bootloader and other ways to configure a chip. the autoreset feature on the Diecimila means that the board resets (and the bootloader starts) whenever you open a serial connection to it.) Why doesn't my sketch start? It's possible to "confuse" the bootloader so that it never starts your sketch. you should wait for two seconds or so after opening the connection before sending any data.to timeout. To avoid this problem. however. but when it does reset it takes longer . it may think you're talking to it and never quit. it runs the bootloader (if present). Why are we using a bootloader? The use of a bootloader allows us to avoid the use of external hardware programmers. the board doesn't reset when you open a serial connection to it. In particular. In particular. When you reset the Arduino board. this is a sketch that the bootloader writes to the flash memory on the ATmega168 or ATmega8 chip. The bootloader then listens for commands or data to arrive from the the computer. the bootloader launches the newly-uploaded program. (Burning the bootloader onto the chip. if you send serial data to the board just after it resets (when the bootloader is running).

did the word "scope" in that error message above mean? It refers to the part of your program in which the variable can be used. you can change the value of a variable using an assignment (indicated by an equals sign). Notice that we don't specify the type of the variable: it's not changed by the assignment. but you can use it lots of times. a program controlling an RGB LED might have variables called redPin. } void loop() { digitalWrite(pin. Now what. and a type. you can refer to this variable by its name. It has a name. This is called a global variable. For example. you're making a copy of its value and storing that copy in the location in memory associated with the other variable. A variable has other advantages over a value like a number. only pin has the value 12. and bluePin). whose value is 13 . at which point its value will be looked up and used. you can use a descriptive name to make the significance of the variable clear (e. you can declare at the top of your code. Most importantly.g. int pin2 = pin. [1] Note that you have to declare a variable before you can assign a value to it. and whose type is int . you'll get a message like: "error: pin was not declared in this scope". In this case. When you assign one variable to another. OUTPUT). creates a variable whose name is pin . } . For example. Changing one has no effect on the other. will change the value of the variable to 12. you don't actually need to use a variable. after: int pin = 13. OUTPUT). For example. it is the value of pin (13) that will be passed to the pinMode() function. only its value changes. Also. HIGH). a value. For example. For example: pin = 12. If you include the preceding statement in a program without the first statement above. here's an example: int pin = 13. this statement would work just as well: pinMode(13. this statement (called a declaration ): int pin = 13. pin = 12. Later on in the program. So if you later decide to change from pin 13 to pin 12. you only need to change one spot in the code.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Variables A variable is a place to store a piece of data. you might be wondering. The advantage of a variable in this case is that you only need to specify the actual number of the pin once. the name of the variable is permanently associated with a type. in this statement: pinMode(pin. if you want to be able to use a variable anywhere in your program. pin2 is still 13. greenPin. That is. void setup() { pinMode(pin. This is determined by where you declare it. OUTPUT).

the variable pin can only be used inside the setup() function. // wrong: pin is not in scope here. its value could be changed anywhere in the code. it can be much easier to figure out where the value came from if the variable has a limited scope. why should I limit its scope to just one function? The answer is that it can make it easier to figure out what happens to it. and you can assign values of any type to a variable. wouldn't you make all your variables global? After all. you can declare it there. even though you've declared pin somewhere in your program. the digitalWrite() function called from loop() will be passed a value of 12. since that's the value that was assigned to the variable in the setup() function. For example. Both functions are referring to the same variable. so that changing it one will affect the value it has in the other. void setup() { pin = 12. } you'll get the same message as before: "error: 'pin' was not declared in this scope". If you only need to use a variable in a single function. if I don't know where I might need a variable. like Python. } In this case. as in: int pin = 13. you're trying to use it somewhere outside its scope. OUTPUT). If you try to do something like this: void loop() { digitalWrite(pin. OUTPUT). LOW). meaning that you need to understand the whole program to know what will happen to the variable. [block scope] [size of variables] [1] In some languages. pinMode(pin. if your variable has a value you didn't expect. That is. For example: void setup() { int pin = 13. pinMode(pin. HIGH). Why. } void loop() { digitalWrite(pin. in which case its scope will be limited to that function.As you can see. types are associated with values. you might be wondering. } Here. Edit Page | Page History | Printable View | All Recent Site Changes . If a variable is global. This is referred to as dynamic typing . HIGH). pin is used in both the setup() and loop() functions. digitalWrite(pin. not variable names.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Mellis Added lines 5-8: Basics Sketch: The various components of a sketch and how they work. at 07:39 AM by Paul Badger Changed lines 31-35 from: test to: test Restore April 29. at 10:33 AM by David A. 2008.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.Show changes to markup June 01. 2008. at 08:38 PM by David A. 2008. 2008. at 07:34 AM by Paul Badger Changed lines 31-35 from: test to: test Restore April 29. 2008. at 07:31 AM by Paul Badger Added lines 29-35: test . at 07:38 AM by Paul Badger Changed lines 31-35 from: test to: test Restore April 29. Mellis Deleted lines 0-2: Reference | Extended Reference Deleted lines 2-3: Restore April 29. Restore April 29. 2008. at 07:47 AM by Paul Badger Changed lines 31-35 from: test to: Restore April 29. 2008.Foundations History Hide minor edits .

2008. Added line 27: Restore April 06. 2008. at 09:44 AM by David A. 2008. at 06:23 AM by Paul Badger Changed lines 1-4 from: Reference | Reference| Extended Reference to: Reference | Extended Reference Restore March 31. at 06:27 PM by Paul Badger Changed lines 13-14 from: Arduino Software . 2008. at 06:20 AM by Paul Badger Added lines 3-5: Reference Restore March 21. at 05:57 PM by Paul Badger Restore April 10. at 07:28 AM by Paul Badger Changed lines 51-52 from: GroupHead to: Restore April 29. at 05:33 PM by Paul Badger Changed lines 25-26 from: to: Port Manipulation: Manipulating ports directly for faster manipulation of multiple pins Restore March 31. Mellis .adding pwm tutorial Added lines 16-17: PWM: How the analogWrite() function simulates an analog output using pulse-width modulation. 2008. at 06:22 AM by Paul Badger Added lines 1-4: Reference | Reference| Extended Reference Changed lines 8-9 from: Reference to: Restore March 31.Restore April 29. 2008. at 07:27 AM by Paul Badger Changed lines 51-52 from: GroupHead to: GroupHead Restore April 29. 2008. 2008. 2008. 2008. at 07:26 AM by Paul Badger Added lines 51-52: GroupHead Restore April 22.

. at 10:48 PM by Paul Badger Deleted lines 6-7: Memory: The various types of memory available on the Arduino board. 2008. at 11:15 PM by Paul Badger Changed lines 5-6 from: Chip-Level Documentation and Techniques to: Microcontrollers Changed lines 17-18 from: Programming Techniques to: Programming Technique Restore March 09. at 11:11 PM by Paul Badger Changed lines 5-6 from: Chip Hardware to: Chip Level Documentation and Techniques Restore March 09. 2008. 2008.to: Arduino Firmware Restore March 09. at 11:09 PM by Paul Badger Changed lines 5-6 from: Hardware to: Chip Hardware Restore March 09. 2008. at 10:49 PM by Paul Badger Changed lines 13-14 from: Arduino Software to: Arduino Software Restore March 09. at 11:12 PM by Paul Badger Changed lines 5-6 from: Chip Level Documentation and Techniques to: Chip-Level Documentation and Techniques Restore March 09. 2008. 2008. 2008. at 10:49 PM by Paul Badger Added lines 13-14: Arduino Software Restore March 09.

Page Discussion Restore March 07. at 07:19 PM by David A. 2008. at 09:25 PM by Paul Badger Changed lines 11-12 from: Foundations to: Restore March 07. at 07:16 PM by David A.Added lines 11-12: Memory: The various types of memory available on the Arduino board. 2008. Deleted lines 25-26: Variables: How to define and use variables. 2008. Changed lines 15-16 from: Programming to: Programming Techniques Restore March 09. Page Discussion to: This page contains chip-level reference material and low-level hardare and software techniques used in the Arduino language. Mellis Changed lines 3-4 from: This page contains chip-level reference material and low-level hardare and software techniques used in the Arduino language. Page Discussion to: This page contains explanations of some of the elements of the Arduino hardware and software and the concepts behind them. Mellis Changed lines 11-12 from: to: Variables: How to define and use variables. Restore March 09. at 09:24 PM by Paul Badger Changed lines 3-37 from: . Restore March 07. 2008. 2008. Page Discussion Added lines 11-12: Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. at 09:46 PM by Paul Badger Changed lines 3-4 from: This page contains general chip-level reference material as it relates to basic low-level hardare and software techniques used in the Arduino language. 2008. at 10:47 PM by Paul Badger Added lines 5-6: Hardware Added lines 15-16: Programming Restore March 09.

Debugging?: Figuring out what's wrong with your hardware or software and how to fix it.) Serial Communication?: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). at 09:21 PM by Paul Badger Changed line 3 from: This page contains general chip-level reference material as it relates to basic low-level techniques. Page Discussion to: This page contains general chip-level reference material as it relates to basic low-level hardare and software techniques used in the Arduino language. etc. Variables: How to define and use variables. 2008. I2C.This page contains general chip-level reference material as it relates to basic low-level hardare and software techniques used in the Arduino language. at 09:12 PM by Paul Badger Added lines 1-3: Foundations This page contains general chip-level reference material as it relates to basic low-level techniques. Midi. Page Discussion Restore March 07. SPI. 2008. Arrays?: How to store multiple values of the same type. Page Discussion Restore Edit Page | Page History | Printable View | All Recent Site Changes . Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs. Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. Interrupts?: Code that interrupts other code under certain conditions. Page Discussion to: This page contains general chip-level reference material as it relates to basic low-level hardare and software techniques used in the Arduino language. Communication?: An overview of the various ways in which an Arduino board can communicate with other devices (serial. Foundations (:if false:) PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. Optimization?: What to do when your program runs too slowly. Numbers?: The various types of numbers available and how to use them. (:ifend:) Restore March 07. Pointers?: Functions?: How to write and call functions. Page Discussion Memory: The various types of memory available on the Arduino board.

Programming Technique Variables: How to define and use variables. Arduino Firmware Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches.Arduino : Tutorial / Foundations Learning Examples | Foundations | Hacking | Links Foundations This page contains explanations of some of the elements of the Arduino hardware and software and the concepts behind them.cc/en/Tutorial/Foundations) . Microcontrollers Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs.arduino. Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. Memory: The various types of memory available on the Arduino board. PWM: How the analogWrite() function simulates an analog output using pulse-width modulation. Port Manipulation: Manipulating ports directly for faster manipulation of multiple pins (Printable View of http://www. Page Discussion Basics Sketch: The various components of a sketch and how they work.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Mellis Added lines 8-28: Books and Manuals .getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. schematics. input / output. etc. if/if-else statements. a simple blinking light Lesson 2: Sketches. Lesson 0: Pre-flight check. and basic RGB color-mixing Lesson 4: The serial library and binary data . procedures and hacking code Lesson 3: Breadboards. 2008. By ladyada. schematics. Restore June 08.Show changes to markup June 08.Links History Hide minor edits . 2008.. at 11:28 AM by David A.. digital inputs. debouncing and your first contract product design. a guide to transforming circuit diagrams into physical circuits. input / output. pull-up and pull-down resistors. procedures and hacking code Lesson 3: Breadboards. digital inputs. etc. Schematics to circuits: from Wiring. and basic RGB color-mixing Lesson 4: The serial library and binary data .Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. pull-up and pull-down resistors. using Arduino. By ladyada. if/if-else statements. at 11:29 AM by David A. variables... 2008. Restore June 08. communication. to: Added lines 41-49: Learn electronics using Arduino: an introduction to programming. variables. communication.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. Lesson 0: Pre-flight check. resistors and LEDs.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. resistors and LEDs. Mellis Changed lines 18-27 from: Learn electronics using Arduino: an introduction to programming. debouncing and your first contract product design. using Arduino. a simple blinking light Lesson 2: Sketches. Mellis Added lines 62-65: Wiring electronics reference: circuit diagrams for connecting a variety of basic electronic components. at 11:30 AM by David A.

debouncing and your first contract product design. and basic RGB color-mixing Lesson 4: The serial library and binary data .. if/if-else statements. using Arduino. Lesson 0: Pre-flight check.. resistors and LEDs. a simple blinking light Lesson 2: Sketches.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. schematics. communication.Making Things Talk (by Tom Igoe): teaches you how to get your creations to communicate with one another by forming networks of smart devices that carry on conversations with you and your environment. Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino. variables. procedures and hacking code Lesson 3: Breadboards. digital inputs. pull-up and pull-down resistors. (:cell width=50%:) Deleted lines 66-86: (:cell width=50%:) Books and Manuals . Learn electronics using Arduino: an introduction to programming. By ladyada.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. etc. input / output.

communication.Making Things Talk (by Tom Igoe): teaches you how to get your creations to communicate with one another by forming networks of smart devices that carry on conversations with you and your environment. etc. debouncing and your first contract product design. Lesson 0: Pre-flight check. digital inputs. books. Restore May 06. at 01:23 PM by David A.. 2008. pull-up and pull-down resistors. microcontrollers.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. resistors and LEDs. using Arduino. sensors. and basic RGB color-mixing Lesson 4: The serial library and binary data .. Learn electronics using Arduino: an introduction to programming. if/if-else statements. 2008. variables. Mellis Changed lines 51-52 from: .getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. at 01:21 PM by David A. schematics. etc. actuators. a simple blinking light Lesson 2: Sketches. Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino. Restore May 06. By ladyada. Mellis Added lines 29-30: Tom Igoe's Physical Computing Site: lots of information on electronics. input / output. procedures and hacking code Lesson 3: Breadboards.

Mellis Changed lines 47-48 from: Making Things Talk (by Tom Igoe): teaches you how to get your creations to communicate .to: Restore May 06. at 01:20 PM by David A. at 01:14 PM by David A. Mellis Added lines 51-52: Restore May 06. 2008. 2008.

at 01:13 PM by David A. and Other Resources to: Books and Manuals Making Things Talk (by Tom Igoe): teaches you how to get your creations to communicate with one another by forming networks of smart devices that carry on conversations with you and your environment. Mellis Added lines 27-43: Other Examples and Tutorials Example labs from ITP Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class class class class 1 2 3 4 (getting started) (input and sensors) (communication. this one focusing on physical sensing and making motion. Changed lines 60-73 from: Example labs from ITP . stand-alone operation) Bionic Arduino: another Arduino class from TodBot.with one another by forming networks of smart devices that carry on conversations with you and your environment. to: Making Things Talk (by Tom Igoe): teaches you how to get your creations to communicate with one another by forming networks of smart devices that carry on conversations with you and your environment. Curricula. Restore May 06. Examples from Tom Igoe Examples from Jeff Gray Changed lines 45-47 from: Manuals. servos. and pwm) (piezo sound & sensors. arduino+processing. 2008.

etc. Flash. Lesson 0: Pre-flight check. input / output. communication. this one focusing on physical sensing and making motion. Hosted on the publicly-editable playground wiki. Output Input Interaction Storage Communication Interfacing with Software: how to get an Arduino board talking to software running on the computer (e. Manuals.g. and pwm) (piezo sound & sensors.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. at 06:43 PM by David A. tutorials. Board Setup and Configuration: Information about the components and usage of Arduino hardware. Electronics Techniques: tutorials on soldering and other electronics resources. Examples from Tom Igoe Examples from Jeff Gray to: Restore April 29. By ladyada. Learn electronics using Arduino: an introduction to programming. Max/MSP). Community Documentation Tutorials created by the Arduino community. Mellis Added lines 5-7: (:table width=100% border=0 cellpadding=5 cellspacing=0:) (:cell width=50%:) Added lines 27-28: (:cell width=50%:) Changed lines 54-56 from: Examples from Jeff Gray to: Examples from Jeff Gray (:tableend:) Restore April 29. a simple blinking light . at 06:44 PM by David A. Curricula. Processing. and instructions for using various electronic components with an Arduino board. 2008. circuits.. Mellis Added lines 1-49: Links Arduino examples. 2008. arduino+processing..Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class class class class 1 2 3 4 (getting started) (input and sensors) (communication. Interfacing With Hardware: Code. servos. Code Library and Tutorials: Arduino functions for performing specific tasks and other programming tutorials. using Arduino. PD. and documentation elsewhere on the web. and Other Resources Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino. stand-alone operation) Bionic Arduino: another Arduino class from TodBot.

this one focusing on physical sensing and making motion.Lesson 2: Sketches. and pwm) (piezo sound & sensors. debouncing and your first contract product design. digital inputs. schematics. pull-up and pull-down resistors. resistors and LEDs. stand-alone operation) Bionic Arduino: another Arduino class from TodBot.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. arduino+processing. Examples from Tom Igoe Examples from Jeff Gray Restore Edit Page | Page History | Printable View | All Recent Site Changes . if/if-else statements. variables. Example labs from ITP Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class class class class 1 2 3 4 (getting started) (input and sensors) (communication. procedures and hacking code Lesson 3: Breadboards. and basic RGB color-mixing Lesson 4: The serial library and binary data . servos.

debouncing and your first contract product design. a simple blinking light Lesson 2: Sketches. variables. and basic RGB color-mixing Lesson 4: The serial library and binary data getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. digital inputs. Flash.Arduino : Tutorial / Links Learning Examples | Foundations | Hacking | Links Links Arduino examples. . procedures and hacking code Lesson 3: Breadboards. Hosted on the publicly-editable playground wiki. circuits. if/if-else statements. Interfacing with Software: how to get an Arduino board talking to software running on the computer (e.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. Code Library and Tutorials: Arduino functions for performing specific tasks and other programming tutorials. Max/MSP). and documentation elsewhere on the web. By ladyada. Interfacing With Hardware: Code. Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino. Other Examples and Tutorials Learn electronics using Arduino: an introduction to programming. Output Input Interaction Storage Communication Making Things Talk (by Tom Igoe): teaches you how to get your creations to communicate with one another by forming networks of smart devices that carry on conversations with you and your environment. Electronics Techniques: tutorials on soldering and other electronics resources. Lesson 0: Pre-flight check.. using Arduino. resistors and LEDs. Processing..g. input / output. PD. pullup and pull-down resistors. Board Setup and Configuration: Information about the components and usage of Arduino hardware. tutorials. schematics. etc. communication. and instructions for using various electronic components with an Arduino board. Books and Manuals Community Documentation Tutorials created by the Arduino community.

books. arduino+processing.arduino. actuators. sensors.Tom Igoe's Physical Computing Site: lots of information on electronics. stand-alone operation) Bionic Arduino: another Arduino class from TodBot. microcontrollers. Schematics to circuits: from Wiring. a guide to transforming circuit diagrams into physical circuits. Wiring electronics reference: circuit diagrams for connecting a variety of basic electronic components. this one focusing on physical sensing and making motion. Example labs from ITP Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class 1 (getting started) class 2 (input and sensors) class 3 (communication. etc.cc/en/Tutorial/Links) . servos. Examples from Tom Igoe Examples from Jeff Gray (Printable View of http://www. and pwm) class 4 (piezo sound & sensors.

and should connect to pin 13. the bulb of the LED will also typically have a flat edge on this side.berlios. in intervals of 2 seconds. The long leg is typically positive. Ideally we use pin 13 on the Arduino board because it has a resistor attached to it. LEDs have polarity.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » The "Hello World!" of Physical Computing The first program every programmer learns consists in writing enough code to make their code show the sentence "Hello World!" on a screen. As a microcontroller. If the LED doesn't light up. Code The example code is very simple. Barragan for the Wiring i/o board . trying reversing the legs (you won't hurt the LED if you plug it in backwards for a short period of time). We have added a 1K resistor to pin 13. /* * * * * * * * * * * * Blinking LED -----------turns on and off a light emitting diode(LED) connected to a digital pin. The short leg connects to GND. credits are to be found in the comments.de based on an orginal by H. Arduino doesn't have any pre-established output devices.0j0.org> http://arduino. Willing to provide newcomers with some help while debugging programs. we propose the use of one of the board's pins plugging a LED that we will make blink indicating the right functionallity of the program. needing only an LED Created 1 June 2005 copyleft 2005 DojoDave <http://www. which means they will only light up if you orient the legs properly. what allows the immediate connection of a LED between that pin and ground.

void setup() { pinMode(ledPin. } // LED connected to digital pin 13 // sets the digital pin as output // // // // sets the LED on waits for a second sets the LED off waits for a second Edit Page | Page History | Printable View | All Recent Site Changes . HIGH). delay(1000).*/ int ledPin = 13. OUTPUT). LOW). delay(1000). digitalWrite(ledPin. } void loop() { digitalWrite(ledPin.

shorten for faster fades int DEBUG = 0. OUTPUT).begin()-style functions * Clay Shirky <clay. // Green low . // Increment counter if (i < 255) // First phase of fades { redVal -= 1.. // Blue up } else if (i < 763) // Third phase of fades { redVal += 1. // Initial values are Red full. connected to digital pin 10 // Blue LED. green and blue. int greenPin = 10. // sets the pins as output pinMode(greenPin. // DEBUG counter. // .. // Red LED. // Loop counter int wait = 50.begin(9600).. // Variables to store the values to send to the pins int greenVal = 1. red. if (DEBUG) { // If we want to see the pin values for debugging.edu> */ // Output int redPin = 9. or one tri-color LED. // Red down greenVal += 1. Serial. // 50ms (. OUTPUT).shirky@nyu. // Blue low } else if (i < 509) // Second phase of fades { redVal = 1. and blue to red * The debugging code assumes Arduino 0004. int i = 0. will write values back via serial void setup() { pinMode(redPin.set up the serial ouput on 0004 style } } // Main program void loop() { i += 1. using PWM * The program cross-fades slowly from red to green. Green and Blue off int blueVal = 1. connected to digital pin 9 // Green LED.05 second) delay. // Red up greenVal = 1. // Red low greenVal -= 1. green to blue. // Green up blueVal = 1.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » /* * Code for cross-fading 3 LEDs. if set to 1.. // Green down blueVal += 1. as it uses the new Serial. int bluePin = 11. pinMode(bluePin. OUTPUT). connected to digital pin 11 // Program variables int redVal = 255.

to end with a carriage return } } delay(wait). blueVal).print(i).print(greenVal). greenVal). and start the fades again { i = 1. redVal). // Reset the counter Serial. Serial. Serial.print("\t"). // println.print("\t"). Serial.blueVal -= 1. // Write current values to LED pins analogWrite(greenPin. // Print a tab Serial. // Serial commands in 0004 style Serial.print("G:"). // Repeat for green and blue. // Indicate that output is red value Serial. // Print red value Serial.print(redVal). // Print a tab Serial. if (DEBUG) { // If we want to read the output DEBUG += 1. } analogWrite(redPin.print("B:").print("R:"). // Pause for 'wait' milliseconds before resuming the loop } Edit Page | Page History | Printable View | All Recent Site Changes . analogWrite(bluePin.. // Blue down } else // Re-set the counter.println(blueVal)..print("\t"). // Increment the DEBUG counter if (DEBUG > 10) // Print every 10 loops { DEBUG = 1. Serial.

green and blue (RGB) * To create fades. but they * are a little fussy -. there are 5 optional settings you can adjust: * 1. List the order you want them to fade in * * DESCRIBING A COLOR: * A color is just an array of three percentages. YMMV. e. fading out of * one color and into the next * * In addition. Clay Shirky <clay. Set the DEBUG flag to 1 if you want debugging output to be * sent to the serial monitor. it will loop that number of times. There is an optional 'hold' variable. the other functions the code is performing slow this * down to ~11 seconds on my board. but * you can set the initial color to be any other color * 2. 0. the 'wait' variable * sets the approximate duration of a single crossfade. * * Those colors will appear in that order. or make your own * * LISTING THE ORDER: * In the main part of the program. red. you need to do two things: * 1. which pasues the * program for 'hold' milliseconds when a color is complete.g. * * April 2007. blue and green off * int red = { 100. the program will loop indefinitely.) * 4. 0-100. * 5. * 3. * if it is set to a number. In * practice. * a 'wait' of 10 ms should make a crossFade of ~10 seconds. * and make the last color black if you want it to fade out at the end.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » /* * Code for cross-fading 3 LEDs. * crossFade(green). * controlling the red. * * The internals of the program aren't complicated. If 'repeat' is set to 0. Describe the colors you want to be displayed * 2.shirky@nyu. (Set 'return' to 1. The initial color is set to black (so the first color fades in). * crossFade(blue). * crossFade(red). * then stop on the last color in the sequence. 30} * etc. you need to list the order * you want to colors to appear in.edu> */ . * but before the next color starts. green and blue LEDs * * Red is the red LED at full. The internal loop runs for 1020 interations. 0 } * Dim white is all three LEDs at 30% * int dimWhite = {30.the inner workings are explained * below the main loop. * * Some common colors are provided below. 30. In theory.

0 }. // sets the pins as output if (DEBUG) { Serial. 95. int bluPin = 11. int prevB = bluVal. int bluVal = black[2]. 100. // Set initial color int redVal = black[0]. connected to digital pin 10 // Blue LED. // .begin(9600). connected to digital pin 11 { { { { { { = 0. outputs OUTPUT). int prevG = grnVal.. before the next crossFade DEBUG = 1. 0.set up the serial ouput // Main program: list the order of crossfades void loop() { crossFade(red).. pinMode(grnPin. 100 }. if set to 1. // Red LED. { 30. 100.. 30. crossFade(green). . 0. // DEBUG counter. int grnPin = 10. increase for slower fades hold = 0. 0. will write values back via serial loopCount = 60. // If so. } } // If we want to see values for debugging. // How often should DEBUG report? repeat = 3. 0 }. 100. if (repeat) { // Do we loop a finite number of times? j += 1. // 10ms internal crossFade delay.. crossFade(blue). 40. 0. 0. // How many times should we loop before stopping? (0 for no stop) j = 0. 100. crossFade(yellow). // Optional hold when a color is complete. // Loop counter for repeat // Initialize color variables int prevR = redVal. 30 }.YOU SHOULDN'T NEED TO CHANGE THIS FOR THE BASICS * * The program works like this: * Imagine a crossfade that moves the red LED from 0-10. OUTPUT). OUTPUT). } } } /* BELOW THIS LINE IS THE MATH -. int int int int int int wait = 10. // Set up the LED void setup() { pinMode(redPin. 100 }. connected to digital pin 9 // Green LED. int grnVal = black[1]. stop.// Output int redPin = 9. pinMode(bluPin. if (j >= repeat) { // Are we there yet? exit(j). 0 }. // Color arrays int black[3] = int white[3] = int red[3] = int green[3] = int blue[3] = int yellow[3] = int dimWhite[3] // etc. 0 }.

* and then divides that gap by 1020 to determine the size of the step * between adjustments in the value. */ int calculateStep(int prevValue. in * ten steps. and there are 1020 steps (255*4). . } } // Defensive driving: make sure val stays in the range 0-255 if (val > 255) { val = 255. the green from * 0-5 in 5 steps.. if (step > 0) { // increment the value if step is positive. When the loop value. int i) { if ((step) && i % step == 0) { // If step is non-zero and its time to change a value. * * To figure out how big a step there should be between one up. } else if (step < 0) { // . then loops 1020 times. Our 10 step fade would look like: * * 1 2 3 4 5 6 7 8 9 10 * R + + + + + + + + + + * G + + + + + * B * * The red rises from 0 to 10 in ten steps. and a * equals lowering it.. * which calculates the absolute gap between the start and end values. int val. val += 1.or decrement it if step is negative val -= 1.prevValue.) int calculateVal(int step. step = 1020/step. G. } return val. and the blue from 10 to 7. * * In the real program.or * down-tick of one of the LED values. } /* * * * */ The next function is calculateVal. the color percentages are converted to * 0-255 values. // divide by 1020 } return step. * Imagine a + indicates raising a value by 1.* the green from 0-5. reaches the step size appropriate for one of the colors. (R.. and B are each calculated separately. i. and the blue falls from 10 to 7 in three steps. then writing the color values to the correct pins. it increases or decreases the value of that color by 1. } /* * * * */ crossFade() converts the percentage colors to a 0-255 range. we call calculateStep().. } else if (val < 0) { val = 0. // What's the overall gap? if (step) { // If its non-zero. int endValue) { int step = endValue . checking to see if the value needs to be updated each time. * We'd want to count the 10 steps and increase or * decrease color values in evenly stepped increments.

Serial. calculateVal(stepG. // Pause for 'wait' milliseconds before resuming the loop if (DEBUG) { // If we want serial output. print it at the if (i == 0 or i % loopCount == 0) { // beginning. int stepR = calculateStep(prevR. 100. prevB = bluVal.print(" / "). int stepG = calculateStep(prevG. Serial. i). } } // Update current values for next loop prevR = redVal. B). redVal. redVal). i++) { calculateVal(stepR.print(grnVal). 100.print("Loop/RGB: #"). for (int redVal grnVal bluVal i = = = = 0.print(" | "). i <= 1020.print(i). grnVal). R). Serial.print(redVal). // Write current values to LED pins analogWrite(redPin. and every loopCount times Serial. i).void crossFade(int color[3]) // Convert to 0-255 int R = (color[0] * 255) / int G = (color[1] * 255) / int B = (color[2] * 255) / { 100. grnVal. i). Serial. Serial. analogWrite(bluPin. // Pause for optional 'wait' milliseconds before resuming the loop } Edit Page | Page History | Printable View | All Recent Site Changes . Serial. calculateVal(stepB. } DEBUG += 1. G). Serial. prevG = grnVal. delay(hold). bluVal). analogWrite(grnPin.println(bluVal). int stepB = calculateStep(prevB.print(" / "). bluVal. delay(wait).

This example makes use of 6 LEDs connected to the pins 2 . Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O board.7 on the board using 220 Ohm resistors.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Knight Rider We have named this example in memory to a TV-series from the 80's where the famous David Hasselhoff had an AI machine driving his Pontiac.HIGH/LOW) and delay(time) .) construction to perform the very same thing. The second example shows how to use a for(. The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way. Malmo University * @author: David Cuartielles * @hardware: David Cuartielles. one by one using only digitalWrite(pinNum.. Example for Hasselhoff's fans Knight Rider 1 /* Knight Rider 1 * -------------* * Basically an extension of Blink_LED. but in fewer lines. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. * * * (cleft) 2005 K3. The first code example will make the LEDs blink in a sequence. Aaron Hallborg */ . it would be interesting to use the Knight Rider as a metaphor.

digitalWrite(pin4. digitalWrite(pin6. LOW). OUTPUT). delay(timer). pin7 = 7. pin6 = 6. digitalWrite(pin5. HIGH). digitalWrite(pin3. pinMode(pin3. LOW). pin4 = 4. HIGH). HIGH). . LOW). HIGH).int int int int int int int pin2 = 2. digitalWrite(pin5. delay(timer). delay(timer). digitalWrite(pin6. pinMode(pin4. pin3 = 3. LOW). HIGH). HIGH). delay(timer). OUTPUT). digitalWrite(pin2. digitalWrite(pin3. digitalWrite(pin4. delay(timer). delay(timer). HIGH). pinMode(pin6. OUTPUT). HIGH). void loop() { digitalWrite(pin2. digitalWrite(pin7. } OUTPUT). delay(timer). digitalWrite(pin5. pinMode(pin7. digitalWrite(pin4. digitalWrite(pin6. digitalWrite(pin4. delay(timer). OUTPUT). delay(timer). LOW). delay(timer). digitalWrite(pin3. LOW). digitalWrite(pin7. LOW). delay(timer). delay(timer). digitalWrite(pin6. pinMode(pin5. pin5 = 5. delay(timer). delay(timer). delay(timer). OUTPUT). HIGH). LOW). LOW). digitalWrite(pin5. delay(timer). void setup(){ pinMode(pin2. timer = 100. delay(timer). HIGH). delay(timer).

count++) { pinMode(pinArray[count]. } } void loop() { for (count=0. HIGH). delay(timer).count<6. Aaron Hallborg */ int pinArray[] = {2. digitalWrite(pin3. int count = 0.). void setup(){ . 5. } } Knight Rider 3 /* Knight Rider 3 * -------------* * This example concentrates on making the visuals fluid.count++) { digitalWrite(pinArray[count]. delay(timer). digitalWrite(pinArray[count]. void setup(){ // we make all the declarations at once for (count=0. int count = 0. * * * (cleft) 2005 K3.delay(timer). 3. delay(timer). 7}. 7}.count>=0. * * * (cleft) 2005 K3.. Aaron Hallborg */ int pinArray[] = {2. 4. LOW). int timer = 30. digitalWrite(pinArray[count]. Malmo University * @author: David Cuartielles * @hardware: David Cuartielles. 5. LOW). Malmo University * @author: David Cuartielles * @hardware: David Cuartielles. LOW). 6.count<6. HIGH). } Knight Rider 2 /* Knight Rider 2 * -------------* * Reducing the amount of code using for(. } for (count=5. 3. delay(timer). int timer = 100. OUTPUT). delay(timer). 4. 6.count--) { digitalWrite(pinArray[count].

1]. delay(timer). HIGH). HIGH). OUTPUT). digitalWrite(pinArray[count]. LOW). LOW). delay(timer).count<5. delay(timer*2). digitalWrite(pinArray[count + 1].count<6.count>0. } } Edit Page | Page History | Printable View | All Recent Site Changes . HIGH). } for (count=5. delay(timer). } } void loop() { for (count=0. delay(timer). HIGH).count++) { digitalWrite(pinArray[count].for (count=0. digitalWrite(pinArray[count]. digitalWrite(pinArray[count .count++) { pinMode(pinArray[count]. delay(timer*2).count--) { digitalWrite(pinArray[count].

and how long its 'tail' is. It isn't very elegant because the tail is as bright as the star. or more poetically a Shooting Star. and in the end it seems like a solid ray that crosses the LED line. go through a line of LEDs. allow longer tails. Then it will continue lighting LEDs towards the left (if you mount it like and look at it like the image) to make the star keep movint.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Shooting Star This example shows how to make a ray of light. ?v=0 How this works You connect 11 LEDs to 11 arduino digital pins. The program starts lighting up LEDs until it reaches the number of LEDs equal to the size you have stablished for the tail. You will be able to controle how fast the 'star' shoots. Of course you can increase the number of LEDs using an LED driver (see tutorial) and therefore. and will start erasing from the right. this will happen also if the tail size is equal or bigger than 11) The tail size should be relatively small in comparison with the number of LEDs in order to see it. through a 220 Ohm resistance (see image above). to make sure we see the tail (otherwise we would just light up the whole line of leds. Code /* * * * * * * * ShootingStar -----------This program is kind of a variation of the KnightRider It plays in a loop a "Shooting Star" that is displayed on a line of 11 LEDs directly connected to Arduino You can control how fast the star shoots thanx to the variable called "waitNextLed" .

// Array where I declare the pins connected to the // Time before I light up the next LED // Number of LEDs that stay lit befor I start turning them off. i< lineSize.12 }.8. thus the tail // Number of LEDs connected (which also is the size of the pinArray) // I asign the sens of the different Pins void setup() { int i. // I light up consecutively the LEDs delay(waitNextLed).4.7. // I set up the tail length in a counter digitalWrite(controlLed.France .LOW). // This time variable controles how fast I light them upm. and turn off as well } } @idea: Cristina Hoffmann @code: Cristina Hoffmann @pictures and graphics: Cristina Hoffmann @date: 20060203 . waitNextLed = 100. i<lineSize. controlLed = 13.Rennes .10. } for (i=(lineSize-tailLength). // This time variable controles how fast I light them up if (tailCounter == 0) { digitalWrite(pinArray[i-tailLength]. int tailCounter = tailLength. i++) { digitalWrite(pinArray[i].6.5. i<lineSize. } } // Main loop void loop() { int i. OUTPUT).9. HIGH). // I turn off the LEDs delay(waitNextLed).* * You can also control the length of the star's "tail" * through the variable "tail length" * First it reads two analog pins that are connected * to a joystick made of two potentiometers * * @author: Cristina Hoffmann * @hardware: Cristina Hofmann * */ // Variable declaration int LEDs int int int int pinArray [] = { 2. // I turn off the LEDs depending on my tailLength } else if (tailCounter > 0) tailCounter--. pinMode (controlLed. i++) { pinMode(pinArray[i].HIGH).LOW). for (i=0.11. tailLength = 4. lineSize = 11. OUTPUT). // I make sure I enter the loop indicating it with this LED for (i=0.3. i++) { digitalWrite(pinArray[i].

Edit Page | Page History | Printable View | All Recent Site Changes .

berlios. so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. * * Created 1 December 2005 * copyleft 2005 DojoDave <http://www.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Pushbutton The pushbutton is a component that connects two points in a circuit when you press it. but the resistor in-between them means that the pin is "closer" to ground. (The pin is still connected to 5 volts.org> * http://arduino. // choose the pin for the LED int inPin = 7. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. When the button is closed (pressed). which consists in connecting buttons using a * 1K to 10K pull-up resistor. when pressing a pushbutton attached to pin 7.) /* Basic Digital Read * -----------------* * turns on and off a light emitting diode(LED) connected to digital * pin 13. so that we read a LOW. // choose the input pin (for a pushbutton) int val = 0. connecting the pin to ground. The example turns on an LED when you press the button. The second goes from the corresponding leg of the pushbutton to ground.2 KOhms) to the 5 volt supply.0j0. The first goes from one leg of the pushbutton through a pull-up resistor (here 2. it makes a connection between its two legs. // variable for reading the pin status . It illustrates the * concept of Active-Low. The third connects to a digital i/o pin (here pin 7) which reads the button's state.de * */ int ledPin = 13. We connect three wires to the Arduino board.

// if (val == HIGH) { // digitalWrite(ledPin. pinMode(inPin. } else { digitalWrite(ledPin. LOW). INPUT).void setup() { pinMode(ledPin. } } read input value check if the input is HIGH (button released) // turn LED OFF // turn LED ON Edit Page | Page History | Printable View | All Recent Site Changes . OUTPUT). HIGH). } // declare LED as output // declare pushbutton as input void loop(){ val = digitalRead(inPin).

g. without which pressing the button once would appear to the code as multiple presses. int reading.e. Mellis * 21 November 2006 */ int inPin = 2. * * David A. . // the number of the input pin // the number of the output pin // the current state of the output pin // the current reading from the input pin // the previous reading from the input pin // the follow variables are long's because the time. because of a push-button * press). measured in miliseconds. There's * a minimum delay between toggles to debounce the circuit (i. Circuit A push-button on pin 2 and an LED on pin 13. to ignore * noise).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Examples > Digital I/O Switch This example demonstrates the use of a pushbutton as a switch: each time you press the button. the output pin is toggled from LOW to HIGH or HIGH to LOW. It also debounces the input. int previous = LOW. Code /* switch * * Each time the input pin goes from LOW to HIGH (e. the LED (or whatever) is turned on (if it's off) or off (if on). int state = HIGH. int outPin = 13.

toggle the output pin and remember the time (reading == HIGH && previous == LOW && millis() . increase if the output flickers void setup() { pinMode(inPin. state). pinMode(outPin. // the debounce time. previous = reading. else state = HIGH. } digitalWrite(outPin.time > debounce) { if (state == HIGH) state = LOW. OUTPUT). // the last time the output pin was toggled long debounce = 200. } Edit Page | Page History | Printable View | All Recent Site Changes . INPUT). time = millis(). } void loop() { reading = digitalRead(inPin). // // // if if the input just went from LOW and HIGH and we've waited long enough to ignore any noise on the circuit. long time = 0.// will quickly become a bigger number than can be stored in an int.

When the shaft is turned all the way in the other direction. This changes the relative "closeness" of that pin to 5 volts and ground. analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin. In the easiest case we connect * a potentiometer to analog pin 2. there are 0 volts going to the pin. The amount of time the LED will be on and off depends on * the value obtained by analogRead(). and we read 0. The first goes to ground from one of the outer pins of the potentiometer. that value controls the rate at which an LED blinks. * * Created 1 December 2005 * copyleft 2005 DojoDave <http://www. The third goes from analog input 2 to the middle pin of the potentiometer. When the shaft is turned all the way in one direction. By turning the shaft of the potentiometer. In between. In this example.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Reading a Potentiometer (analog input) A potentiometer is a simple knob that provides a variable resistance. there are 5 volts going to the pin and we read 1023.de * */ . We connect three wires to the Arduino board. we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. Code /* Analog Read to LED * -----------------* * turns on and off a light emitting diode(LED) connected to digital * pin 13. which we can read into the Arduino board as an analog value. The second goes from 5 volts to the other outer pin of the potentiometer.berlios.org> * http://arduino. giving us a different analog input.0j0.

int ledPin = 13. HIGH).int potPin = 2. int val = 0. } // // // // // read turn stop turn stop the the the the the value from the sensor ledPin on program for some time ledPin off program for some time Edit Page | Page History | Printable View | All Recent Site Changes . } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin). OUTPUT). delay(val). // select the input pin for the potentiometer // select the pin for the LED // variable to store the value coming from the sensor void setup() { pinMode(ledPin. delay(val). digitalWrite(ledPin. LOW). digitalWrite(ledPin.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Interfacing a Joystick The Joystick Schematic .

joyPin1 = 0. The following code includes a method called treatValue() that is transforming the sensor's messurement into a value between 0 and 9 and sends it in ASCII back to the computer. The kind of program that we need to monitor the joystick has to make a polling to two of the analog pins. this will take the form: * Jxy\r\n * * x and y are integers and sent in ASCII * * http://www. while our DAC (Digital to Analog Converter .berlios. value1 = 0. } int treatValue(int data) { // initializes digital pins 0 to 7 as outputs . Potentiometers are variable resistors and. /* Read Jostick * -----------* * Reads two analog pins that are supposed to be * connected to a jostick made of two potentiometers * * We send three bytes back to the comp: one header and two * with data as signed bytes.How this works The joystick in the picture is nothing but two potentiometers that allow us to messure the movement of the stick in 2-D.that is messuring the values from the potentiometers in the joystick) has a resolution of 10bits. We can send these values back to the computer. but then we face the classic problem that the transmission over the communication port has to be made with 8bit values. joyPin2 = 1. in a way. value2 = 0.g. beginSerial(9600). they act as sensors providing us with a variable voltage depending on the rotation of the device around its shaft.org | http://arduino.de * copyleft 2005 DojoDave for DojoCorp */ int int int int int ledPin = 13.0j0. // // // // slider variable connecetd to analog slider variable connecetd to analog variable to read the value from the variable to read the value from the pin 0 pin 1 analog pin 0 analog pin 1 void setup() { pinMode(ledPin. Flash and parse it inside your own code. This allows to easily send the information into e. In other words this means that our sensors are characterized with a value between 0 and 1024. OUTPUT). Finally we make the LED blink with the values read from the sensors as a direct visual feedback of how we control the joystick.

HIGH). digitalWrite(ledPin. serialWrite(13). } @idea: the order of the blinking LED @code: David Cuartielles @pictures and graphics: Massimo Banzi @date: 20050820 . serialWrite(treatValue(value1)). serialWrite('J').Sweden Edit Page | Page History | Printable View | All Recent Site Changes . delay(value2).return (data * 9 / 1024) + 48. LOW). // reads the value of the variable resistor value2 = analogRead(joyPin2). otherwise we get the same value twice delay(100). // this small pause is needed between reading // analog pins.Malmo . delay(value1). } void loop() { // reads the value of the variable resistor value1 = analogRead(joyPin1). serialWrite(treatValue(value2)). serialWrite(10). digitalWrite(ledPin.

The other thing to remember is that Piezos have polarity. commercial devices are usually having a red and a black wires indicating how to plug it to the board. we transform the voltage into a value in the range 0. In order to see this text you could either use a terminal program.analog to digital converter. and not just a plain HIGH or LOW. These converters read a voltage value and transform it into a value encoded digitally. which will read data from the serial port and show it in a window. In the case of the Arduino boards.g. We also have to connect a resistor in the range of the Megaohms in parallel to the Piezo element. that supports the functionality of reading a value between 0 and 5volts. it will send the string "Knock!" back to the computer over the serial port. Later in this article we propose a program that works for the software designed by Reas and Fry.. in the example we have plugged it directly in the female connectors. Sometimes it is possible to acquire Piezo elements without a plastic housing. Processing. A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. 0 represents 0volts. We are taking advantage of the processors capability to read analog signals through its ADC . Example of connection of a Piezo to analog pin 0 with a resistor /* Knock Sensor * ---------------* . In our example we are plugging the Piezo on the analog input pin number 0. The code example will capture the knock and if it is stronger than a certain threshold.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Knock Sensor Here we use a Piezo element to detect sound.1024. what will allow us to use it as a knock sensor. We connect the black one to ground and the red one to the input. or make your own program in e. while 1024 represents 5volts at the input of one of the six analog pins. then they will just look like a metallic disc and are easier to use as input sensors.

Running this example requires you have an Arduino board as peripheral hardware sending values and adding an EOLN + CR in the end. int val = 0. } delay(100). Serial port. String buff = "". or CR .serial. Directly after sends the byte 10. } void loop() { val = analogRead(knockSensor). what stands for EOLN or End Of LiNe. OUTPUT).Carriage Return.com> // // // // // // // Reads a value from the serial port and makes the background color toggle when there is a knock on a piezo used as a knock sensor. // we have to make a delay to avoid overloading the serial port } Representing the Knock in Processing If. It writes * "knock" to the serial port if the Threshold is crossed. if (val >= THRESHOLD) { statePin = !statePin.0j0. byte val = 0. Once that happens. statePin).jtnimoy. Those two symbols will be useful to determine when the message sent by the board is over. More information can be found on the Arduino pages: http://www. * * We have to basically listen to an analog pin and detect * if the signal goes over a certain threshold. int NEWLINE = 10. int knockSensor = 0.g. printByte(13). int statePin = LOW. the processing program will toggle the background color of the screen and print out "Knock!" in the command line. we have to look into how the information is transferred from the board over the serial port. * and toggles the LED on pin 13. * * (cleft) 2005 D. printByte(10). printString("Knock!"). beginSerial(9600). the program is printing (thus sending) "Knock!" over the serial port. we would like to capture this "knock" from the Arduino board.cc // Created 23 November 2005 // Updated 23 November 2005 import processing. . First we see that whenever there is a knock bigger that the threshold.org> // based on Analog In by Josh Nimoy <http://itp. digitalWrite(ledPin.* Program using a Piezo element as if it was a knock sensor. e. and byte 13. void setup() { pinMode(ledPin. // Knock In // by David Cuartielles <http://www. Cuartielles for K3 */ int ledPin = 13. int THRESHOLD = 100.*.arduino.

} else { buff = buff.void setup() { size(200. } void draw() { // Process each one of the serial port events while (port. } } // <-. } else { val = 0. "COMXX". // Clear the value of "buff" buff = "".read()).SUBSTITUTE COMXX with your serial port name!! Edit Page | Page History | Printable View | All Recent Site Changes . 9600). } println(buff). buff. // Capture the string and print it to the commandline // we have to take from position 1 because // the Arduino sketch sends EOLN (10) and CR (13) if (val == 0) { val = 255.length()-1). // Open your serial port port = new Serial(this. } background(val).available() > 0) { serialEvent(port.substring(1. 200). } void serialEvent(int serial) { if(serial != NEWLINE) { buff += char(serial).

. } } // sets the pins as output // If we want to see the pin values for debugging. // .shirky@nyu. OUTPUT).set up the serial ouput in 0004 format // Main program void loop() { potVal = analogRead(potPin).begin()-style functions * Clay Shirky <clay. or one tri-color LED * The program cross-fades from red to grn. // Red LED. pinMode(grnPin. = 0. OUTPUT). // Variables to store the values to send to the pins = 0. // read the potentiometer value at the input pin if (potVal < 341) // Lowest third of the potentiometer's range (0-340) { potVal = (potVal * 3) / 4. grnVal = potVal. OUTPUT). and blu to red * Debugging code assumes Arduino 0004. // Normalize to 0-255 . bluVal = 1. red. the Pulse-width Modulation (PWM) pins // LED's cathodes should be connected to digital GND int redPin = 9.begin(9600).potVal. // Potentiometer output connected to analog pin 3 int potVal = 0. // Normalize to 0-255 redVal = 256 . pinMode(bluPin. connected to digital pin 10 int bluPin = 11.edu> */ // INPUT: Potentiometer should be connected to 5V and GND int potPin = 3... grn to blu.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » /* * Code for making one potentiometer control 3 LEDs. grn and blu. // Blue LED.. // Green LED. connected to digital pin 9 int grnPin = 10. // Set to 1 to turn on debugging output int DEBUG = 1. if (DEBUG) { Serial. // Variable to store the input from the potentiometer // OUTPUT: Use digital pins 9-11. // Red from full to off // Green from off to full // Blue off } else if (potVal < 682) // Middle third of potentiometer's range (341-681) { potVal = ( (potVal-341) * 3) / 4. void setup() { pinMode(redPin. connected to digital pin 11 // Program int redVal int grnVal int bluVal variables = 0. as it uses Serial.

// Print a tab Serial. // println. // Blue from full to off } analogWrite(redPin. Serial. if (DEBUG > 100) { DEBUG = 1.print(redVal). bluVal). redVal). analogWrite(bluPin.. // Green off bluVal = 256 .potVal.print("R:"). // Print red value Serial. if (DEBUG) { // If DEBUG += 1.potVal. Serial.print("\t"). // Red from off to full grnVal = 1. Serial.print(grnVal).. Serial. // Normalize to 0-255 redVal = potVal. // Write values to LED pins we want to read the output // Increment the DEBUG counter // Print every hundred loops // Reset the counter // Serial output using 0004-style functions Serial.print("\t"). // Indicate that output is red value Serial. analogWrite(grnPin.print("B:"). // Red off grnVal = 256 .println(bluVal). grnVal).print("G:"). to end with a carriage return } } } Edit Page | Page History | Printable View | All Recent Site Changes .redVal = 1. // Blue from off to full } else // Upper third of potentiometer"s range (682-1023) { potVal = ( (potVal-683) * 3) / 4. // Green from full to off bluVal = potVal. // Repeat for grn and blu.

sometimes referred to as an “8-Stage Static Shift Register. Tell the register that I’m ready to get the information serially (latch pin LOW) 3. like hearing a musical cord. within reason. is heavily reliant on what is referred to as a clock pin. referred to as the data pin . The pseudo code to coordinate this all looks something like this: 1. You can keep extending this daisy-chain of shift registers until you have all the inputs you need. An example of a parallel to serial register is the CD4021B. _______ .Clock Data from Arduino |_____| <. That is what makes it “synchronous. Using a parallel to serial shift register allows you collect information from 8 or more switches while only using 3 of the pins on your Arduino. When the latch pin is HIGH the shift register is listening to its 8 parallel ins.Latch Data from Arduino switch switch switch switch switch switch switch switch -> -> -> -> -> -> -> -> If supplementing your Arduino with an additional 8 digital-ins isn’t going to be enough for your project you can have a second CD4021 pass its information on to that first CD4021 which will then be streaming all 16 bits of information to the Arduino in turn. When it is LOW it is listening to the clock pin and passing information serially.” The clock pin is the metronome of the conversation between the shift register and the Arduino. That means every time the latch pin transitions from HIGH to LOW the shift register will start passing its most current switch information. This pin should be connected to an input pin on your Arduino Board. Make sure the register has the latest information from its parallel inputs (i. This is called Asynchronous Parallel Input. That happens in the next step when those 8 pin states are translated into a series of HIGH and LOW pulses on the serial-out pin of the shift register. The transfer of information itself is called Synchronous Serial Output because the shift register waits to deliver linear sequence of data to the Arduino until the Arduino asks for it. that the latch pin is HIGH) 2. pulse the clockPin and then check to see if the data pin is low or high This is a basic diagram. Synchronous Serial Input is the feature that allows the first shift register to receive and transmit the serial-output from the second one linked to it.” The third pin attached to the Arduino is a “Parallel to Serial Control” pin.” This means you can read the state of up to 8 digital inputs attached to the register all at once. “Asynchronous” because the CD4021B is doing all this data collection at its own pace without coordinating with the Arduino. Synchronous Serial communication. '07 Shifting In & the CD4021B Sometimes you'll end up needing more digital input than the 13 pins on your Arduino board can readily handle. You can think of it as a latch pin .Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Parallel to Serial Shifting-In with a CD4021BE Started By Carlyn Maw and Tom Igoe Jan. The second example will cover this situation. If you know you will need to use multiple shift registers like this check that any shift registers you buy can handle Synchronous Serial Input as well as the standard Synchronous Serial Output capability. “Parallel” because it is all at once.e. Every time the Arduino sends the clock pin from LOW to HIGH it is telling the shift register “change the state of your Serial Output pin to tell me about the next switch. _______ | | | C | | D | | 4 | -> Serial Data to Arduino | 0 | | 2 | | 1 | <. “Input” because you are collecting information. input or output. For each of the inputs I’m expecting.

VDD (pin 16) to 5V .Latch Data from Arduino <-----| | | | Serial Data Passed to First | Shift Register | | ______| switch switch switch switch switch switch switch switch -> -> -> -> -> -> -> -> _______ | | | C | | D | | 4 | | 0 | | 2 | <. 3 PIN 8 PIN 9 PIN 10 PIN 11 PIN 16 P1 – P8 (Pins 07) Parallel Inputs Q6. GND Vss P/S C Parallel/Serial Control (latch pin) CLOCK Shift register clock pin SERIALIN VDD Serial data input DC supply voltage Example 1: One Shift Register The first step is to extend your Arduino with one shift register. Q7.Clock Data from Arduino | 1 | <. and before you start wiring up your board here is the pin diagram of the CD4021 from the Texas Instruments Datasheet PINS 1.Latch Data from Arduino |_____| There is more information about shifting in the ShiftOut tutorial.47. Q7 is a pulse behind Q8 and Q6 is a pulse behind Q7. 12.Clock Data from Arduino <. The Circuit 1.switch switch switch switch switch switch switch switch -> -> -> -> -> -> -> -> | | | C | | D | | 4 | | 0 | | 2 | | 1 | |_____| -> Serial Data to Arduino <. Q8 is the only one used in these examples. 1315 PINS 2. Power Connections Make the following connections: GND (pin 8) to ground. Q8 Serial Output Pins from different steps in the sequence.

3. the clockPin and the latchPin respectively.Connect to Arduino Q8 (pin 3) to Ardunio DigitalPin 9 (blue wire) CLOCK (pin 10) to to Ardunio DigitalPin 7 (yellow wire) P/S C (pin 9) to Ardunio DigitalPin 8 (green wire) From now on those will be refered to as the dataPin. Add 8 Switches .2.

2 – What is Pressed? Code Sample 1.3 – Button Combination Check .Diagram The Code Code Sample 1.1 – Hello World Code Sample 1.

doubling the number of input pins while still using the same number of pins on the Arduino. The blue wire is going from the serial out pin (pin 9) of the first shift register to the serial data input (pin 14) of the second register. Add a second shift register. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires). 2.Code Sample 1. Connect the 2 registers. .4 – Is it pressed? (sub-function) Example 2: Daisy Chained In this example you’ll add a second shift register. The Circuit 1.

like a preference file. This is because the code examples will be using the switches attached to the second shift register as settings. . The one momentary switch will be telling the microcontroller that the setting switches are being changed. Notice that there is one momentary switch and the rest are toggle switches. rather than as event triggers. Add a second set of Switches.3.

Diagram .

2 – Using the second byte for settings.The Code Code Sample 2.3 – Using the second byte for settings.1 – Hello World Code Sample 2. Print on only (uses sub-function) Edit Page | Page History | Printable View | All Recent Site Changes . Print all Code Sample 2.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

at 11:10 PM by David A. Mellis . (:table width=90% border=0 cellpadding=5 cellspacing=0:) (:cell width=50%:) Examples Digital Output Blinking LED Blinking an LED without using the delay() function Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) More complex dimming/color crossfader Knight Rider example Shooting star PWM all of the digital pins in a sinewave pattern Digital Input Digital Input and Output (from ITP physcomp labs) Read a Pushbutton Using a pushbutton as a switch Read a Tilt Sensor Analog Input Read a Potentiometer Interfacing a Joystick Controlling an LED circle with a joystick Read a Piezo Sensor 3 LED cross-fades with a potentiometer 3 LED color mixer with 3 potentiometers Complex Sensors Read an Accelerometer Read an Ultrasonic Range Finder (ultrasound sensor) Reading the qprox qt401 linear touch sensor Use two Arduino pins as a capacitive sensor Sound Play Melodies with a Piezo Speaker More sound ideas Play Tones from the Serial Connection .HomePage-0007 History Hide minor edits .backing up the 0007 tutorials page Added lines 1-91: (:title Tutorials:) Arduino Tutorials Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. see the Arduino guide.Show changes to markup June 11. For instructions on getting the board and environment up and running. 2007.

Driving a Unipolar Stepper Motor Implement a software serial connection RS-232 computer interface Interface with a serial EEPROM using SPI Control a digital potentiometer using SPI Multiple digital outs with a 595 Shift Register Multiple digital inputs with a CD4021 Shift Register Other Arduino Examples Example labs from ITP Examples from Tom Igoe Examples from Jeff Gray (:cell width=50%:) Interfacing with Other Software Introduction to Serial Communication (from ITP physcomp labs) Arduino + Flash Arduino + Processing Arduino + PD Arduino + MaxMSP Arduino + VVVV Arduino + Director Arduino + Ruby Arduino + C Tech Notes (from the forums or playground) Software serial (serial on pins besides 0 and 1) L297 motor driver Hex inverter Analog multiplexer Power supplies The components on the Arduino board Arduino build process AVRISP mkII on the Mac Non-volatile memory (EEPROM) Bluetooth Zigbee LED as light sensor (en Francais) Arduino and the Asuro robot Using Arduino from the command line (:tableend:) Restore Edit Page | Page History | Printable View | All Recent Site Changes .MIDI Output (from ITP physcomp labs) and from Spooky Arduino Interfacing w/ Hardware Multiply the Amount of Outputs with an LED Driver Interfacing an LCD display with 8 bits LCD interface library Driving a DC Motor with an L293 (from ITP physcomp labs).

For instructions on getting the board and environment up and running. Examples Digital Output Blinking LED Blinking an LED without using the delay() function Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) More complex dimming/color crossfader Knight Rider example Shooting star PWM all of the digital pins in a sinewave pattern Interfacing with Other Software Introduction to Serial Communication (from ITP physcomp labs) Arduino + Flash Arduino + Processing Arduino + PD Arduino + MaxMSP Arduino + VVVV Arduino + Director Arduino + Ruby Arduino + C Digital Input Digital Input and Output (from ITP physcomp labs) Read a Pushbutton Using a pushbutton as a switch Read a Tilt Sensor Tech Notes (from the forums or playground) Software serial (serial on pins besides 0 and 1) L297 motor driver Hex inverter Analog multiplexer Power supplies The components on the Arduino board Arduino build process AVRISP mkII on the Mac Non-volatile memory (EEPROM) Bluetooth Zigbee LED as light sensor (en Francais) Arduino and the Asuro robot Using Arduino from the command line Analog Input Read a Potentiometer Interfacing a Joystick Controlling an LED circle with a joystick Read a Piezo Sensor 3 LED cross-fades with a potentiometer 3 LED color mixer with 3 potentiometers Complex Sensors Read an Read an sensor) Reading Use two Accelerometer Ultrasonic Range Finder (ultrasound the qprox qt401 linear touch sensor Arduino pins as a capacitive sensor Sound Play Melodies with a Piezo Speaker More sound ideas Play Tones from the Serial Connection MIDI Output (from ITP physcomp labs) and .Arduino : Tutorial / Tutorials Learning Examples | Foundations | Hacking | Links Arduino Tutorials Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. see the Arduino guide.

cc/en/Tutorial/HomePage-0007) .arduino. Driving a Unipolar Stepper Motor Implement a software serial connection RS-232 computer interface Interface with a serial EEPROM using SPI Control a digital potentiometer using SPI Multiple digital outs with a 595 Shift Register Multiple digital inputs with a CD4021 Shift Register Other Arduino Examples Example labs from ITP Examples from Tom Igoe Examples from Jeff Gray (Printable View of http://www.from Spooky Arduino Interfacing w/ Hardware Multiply the Amount of Outputs with an LED Driver Interfacing an LCD display with 8 bits LCD interface library Driving a DC Motor with an L293 (from ITP physcomp labs).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

2007. to: In most programming languages.Blink History Hide minor edits . Arduino doesn't have any pre-established output devices.Show changes to markup February 15. On most others (like the Mini and BT). Since an Arduino board doesn't have a screen. we propose the use of one of the board's pins plugging a LED that we will make blink indicating the right functionallity of the program. others have 1 KB resistor on pin 13 Changed lines 5-10 from: The first program every programmer learns consists in writing enough code to make their code show the sentence "Hello World!" on a screen. what allows the immediate connection of a LED between that pin and ground. Mellis Changed lines 3-4 from: blink to: Blinking LED Restore February 03. Mellis . 2007.) Restore February 03.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. allowing you to connect an LED directly. at 03:51 AM by David A. 2007. at 04:59 PM by David A. 2008. the first program you write prints "hello world" to the screen. Mellis Changed lines 3-4 from: Blinking LED to: blink Restore January 29. As a microcontroller. Mellis Changed lines 3-4 from: . (To connect an LED to another digital pin. you should use an external resistor. at 08:32 AM by David A. Willing to provide newcomers with some help while debugging programs. Mellis Changed lines 3-4 from: Blinking LED to: Blink Restore February 03. at 11:39 AM by David A. there is a 1 KB resistor on the pin. The boards are designed to make it easy to blink an LED using digital pin 13. 2007. at 03:51 AM by David A.clarifying that some boards have built-in leds. Some (like the Diecimila and LilyPad) have the LED built-in to the board. we blink an LED instead. We have added a 1K resistor to pin 13.

Mellis Changed line 21 from: * ----------to: * -----------Restore January 28. Mellis Changed line 21 from: * -----------to: * ----------Deleted line 43: if (1 & 0) Restore January 28. 2007. at 04:27 AM by David A. at 04:26 AM by David A. 2007. Mellis Changed line 44 from: if (1 < 0) to: if (1 & 0) Restore January 28. at 04:27 AM by David A. 2007. at 04:27 AM by David A. 2007. Mellis Changed line 19 from: [= to: [@ Added line 44: .Blink to: Blinking LED Restore January 28. 2007. at 05:06 AM by David A. Mellis Changed lines 3-4 from: blink to: Blink Added lines 13-14: Circuit Changed lines 17-18 from: Code to: Code Restore January 28.

LOW).0j0.org> * http://arduino.arduino.if (1 < 0) Changed line 50 from: =] to: @] Restore January 28.berlios. Changed lines 44-47 from: digitalWrite(pin. digitalWrite(pin. delay(1000). 2007. // LED connected to digital pin 13 Changed line 39 from: pinMode(pin. in intervals of 2 seconds. HIGH). delay(1000). to: pinMode(ledPin. Barragan for the Wiring i/o board */ int ledPin = 13.de * * based on an orginal by H. digitalWrite(ledPin. to: Code The example code is very simple. at 04:26 AM by David A. delay(1000). Mellis Changed lines 15-19 from: [@ // blink // <http://www. Changed line 49 from: @] to: =] Restore January 28. LOW). to: digitalWrite(ledPin. OUTPUT). OUTPUT). delay(1000). [= /* Blinking LED * * * * * -----------turns on and off a light emitting diode(LED) connected to a digital pin. 2007. HIGH). needing only an LED * * Created 1 June 2005 * copyleft 2005 DojoDave <http://www. Ideally we use pin 13 on the Arduino board because it has a resistor attached to it. credits are to be found in the comments. at 04:25 AM by David A. Mellis Changed lines 5-6 from: // // // // sets the LED on waits for a second sets the LED off waits for a second // sets the digital pin as output .cc/en/Tutorial/Blink> int pin = 13.

at 04:03 AM by David A. Willing to provide newcomers with some help while debugging programs. at 04:14 AM by David A. Arduino doesn't have any pre-established output devices. Mellis Changed lines 1-2 from: Examples > Digital I/O to: Examples > Digital I/O Added lines 8-9: // blink // <http://www.cc/en/Tutorial/Blink> Restore January 28. then off for one second. LEDs have polarity. As a microcontroller. 2007. the bulb of the LED will also typically have a flat edge on this side. trying reversing the legs (you won't hurt the LED if you plug it in backwards for a short period of time). Mellis Changed lines 1-2 from: examples > digital > blink . Mellis Changed lines 1-2 from: Examples > Digital I/O > blink to: Examples > Digital I/O blink Restore January 28. and should connect to pin 13. 2007. We have added a 1K resistor to pin 13. turning it on for one second. Restore January 28. which means they will only light up if you orient the legs properly. and so on. what allows the immediate connection of a LED between that pin and ground. to: The first program every programmer learns consists in writing enough code to make their code show the sentence "Hello World!" on a screen. at 04:03 AM by David A.This example blinks the LED on pin 13. The long leg is typically positive. If the LED doesn't light up.arduino. we propose the use of one of the board's pins plugging a LED that we will make blink indicating the right functionallity of the program. 2007. The short leg connects to GND.

digitalWrite(pin. } void loop() { digitalWrite(pin. then off for one second. void setup() { pinMode(pin. } Restore Edit Page | Page History | Printable View | All Recent Site Changes . OUTPUT). 2007. delay(1000). HIGH). LOW). at 08:24 AM by David A. and so on. turning it on for one second. at 04:02 AM by David A. 2007. Restore January 14. delay(1000). Mellis Added lines 1-16: int pin = 13.to: Examples > Digital I/O > blink Restore January 28. Mellis Added lines 1-4: examples > digital > blink This example blinks the LED on pin 13.

0j0. The boards are designed to make it easy to blink an LED using digital pin 13. If the LED doesn't light up. needing only an LED * * Created 1 June 2005 * copyleft 2005 DojoDave <http://www. (To connect an LED to another digital pin. trying reversing the legs (you won't hurt the LED if you plug it in backwards for a short period of time). the bulb of the LED will also typically have a flat edge on this side. /* * * * * * Blinking LED -----------turns on and off a light emitting diode(LED) connected to a digital pin. you should use an external resistor. Since an Arduino board doesn't have a screen. Barragan for the Wiring i/o board */ int ledPin = 13. The short leg connects to GND. allowing you to connect an LED directly. On most others (like the Mini and BT). The long leg is typically positive. Ideally we use pin 13 on the Arduino board because it has a resistor attached to it. which means they will only light up if you orient the legs properly.org> * http://arduino. // LED connected to digital pin 13 . Some (like the Diecimila and LilyPad) have the LED built-in to the board.Arduino : Tutorial / Blink Learning Examples | Foundations | Hacking | Links Examples > Digital I/O Blink In most programming languages. Circuit Code The example code is very simple. we blink an LED instead.berlios.de * * based on an orginal by H. the first program you write prints "hello world" to the screen. and should connect to pin 13. in intervals of 2 seconds.) LEDs have polarity. credits are to be found in the comments. there is a 1 KB resistor on the pin.

} (Printable View of http://www. } void loop() { digitalWrite(ledPin. LOW).void setup() { pinMode(ledPin. HIGH).arduino. delay(1000). OUTPUT).cc/en/Tutorial/Blink) // sets the digital pin as output // // // // sets the LED on waits for a second sets the LED off waits for a second . digitalWrite(ledPin. delay(1000).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

at 11:40 PM by David A. at 05:14 AM by David A. Mellis Changed lines 7-8 from: Code to: Code Restore December 19. without using the delay() function.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. Mellis * http://arduino. 2007. at 11:08 AM by 85. Mellis Deleted lines 7-18: /* Blinking LED without using delay * -------------------------------* * turns on and off a light emitting diode(LED) connected to a digital * pin. 2007. 2006.81. 2007. Mellis Changed lines 1-2 from: Blinking an LED without using the delay() function. 2006. at 11:41 PM by David A.BlinkWithoutDelay History Hide minor edits .berlios. Mellis . at 11:41 PM by David A. this means that other code * can run at the same time without being interrupted by the LED code. // interval at which to blink (milliseconds) Restore February 14. // will store last time LED was updated long interval = 1000.Show changes to markup December 19. // interval at which to blink (milliseconds) to: long previousMillis = 0.de */ Restore May 09. to: Examples > Digital I/O Blink Without Delay Restore December 19.18.int -> long Deleted line 20: int previousMillis = 0. * * Created 14 February 2006 * David A. // will store last time LED was updated Changed lines 22-23 from: int interval = 1000.162 - .

LOW. (millis() .Added lines 1-49: Blinking an LED without using the delay() function. it turns the LED off if it was on and vice-versa. each time through loop() it checks if a sufficient interval has passed . this means that other code * can run at the same time without being interrupted by the LED code. that is.berlios. That means you can't use delay(). value). Sometimes you need to blink an LED (or some other time sensitive function) at the same time as something else (like watching for a button press). or you'd stop everything else the program while the LED blinked. digitalWrite(ledPin. previousMillis = 0. Then. // remember the last time we blinked the LED // if the if (value value = else value = LED is off turn it on and vice-versa. Mellis * http://arduino. * * Created 14 February 2006 * David A. Here's some code that demonstrates how to blink the LED without using delay(). // // // // LED connected to digital pin 13 will store last time LED was updated previous value of the LED interval at which to blink (milliseconds) void setup() { pinMode(ledPin.previousMillis > interval) { previousMillis = millis(). Code /* Blinking LED without using delay * -------------------------------* * turns on and off a light emitting diode(LED) connected to a digital * pin. is the difference between the current time and last time we blinked the LED bigger than the interval at which we want to blink the LED. == LOW) HIGH.if it has. } // sets the digital pin as output void loop() { // here is where you'd put code that needs to be running all the time. OUTPUT). interval = 1000. // // // if check to see if it's time to blink the LED. } } Restore Edit Page | Page History | Printable View | All Recent Site Changes . value = LOW.de */ int int int int ledPin = 13. It keeps track of the last time it turned the LED on or off. without using the delay() function.

. is the difference between the current time and last time we blinked the LED bigger than the interval at which we want to blink the LED. (millis() . } // // // // LED connected to digital pin 13 previous value of the LED will store last time LED was updated interval at which to blink (milliseconds) // sets the digital pin as output void loop() { // here is where you'd put code that needs to be running all the time. // // // if check to see if it's time to blink the LED. each time through loop() it checks if a sufficient interval has passed . it turns the LED off if it was on and vice-versa. == LOW) HIGH. Here's some code that demonstrates how to blink the LED without using delay(). That means you can't use delay().if it has.arduino. that is.cc/en/Tutorial/BlinkWithoutDelay) LED is off turn it on and vice-versa. Then. OUTPUT). digitalWrite(ledPin. LOW.Arduino : Tutorial / Blink Without Delay Learning Examples | Foundations | Hacking | Links Examples > Digital I/O Blink Without Delay Sometimes you need to blink an LED (or some other time sensitive function) at the same time as something else (like watching for a button press). long previousMillis = 0. int value = LOW. void setup() { pinMode(ledPin. It keeps track of the last time it turned the LED on or off. // remember the last time we blinked the LED // if the if (value value = else value = } } (Printable View of http://www. Code int ledPin = 13. long interval = 1000. or you'd stop everything else the program while the LED blinked.previousMillis > interval) { previousMillis = millis(). value).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

2 KOhms) to the 5 volt supply.) Circuit . When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton.arduino. 2007. The second goes from the corresponding leg of the pushbutton to ground. (The pin is still connected to 5 volts. The example turns on an LED when you press the button.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.Button History Hide minor edits . so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. Restore April 11. which consists in connecting buttons using a * 1K to 10K pull-up resistor. it makes a connection between its two legs.cc/en/Tutorial/Invert> * * turns on and off a light emitting diode(LED) connected to digital * pin 13. * */ Restore February 03. Mellis Deleted lines 18-26: /* invert * <http://www.Show changes to markup January 17. the behavior of the sketch will be reversed. 2008. When the button is closed (pressed). the LED may blink erratically. The first goes from one leg of the pushbutton through a pull-up resistor (here 2. with the LED normally on and turning off when you press the button. at 08:56 AM by David A. We connect three wires to the Arduino board. connecting the pin to ground. Mellis Added lines 14-15: If you disconnect the digital i/o pin from everything. 2007. The third connects to a digital i/o pin (here pin 7) which reads the button's state. That's why you need a pull-up or pull-down resister in the circuit. This is because the input is "floating" that is. so that we read a LOW. It illustrates the * concept of Active-Low. with a pull-down resistor keeping the input LOW. at 09:02 AM by David A. at 11:10 AM by David A. but the resistor in-between them means that the pin is "closer" to ground. If so. Restore June 12. 2007. it will more-or-less randomly return either HIGH or LOW. Mellis Added lines 1-45: Examples > Digital I/O Button The pushbutton is a component that connects two points in a circuit when you press it.mentioning pull-down resistors (in addition to pull-up) Added lines 12-13: You can also wire this circuit the opposite way. Mellis . and going HIGH when the button is pressed. when pressing a pushbutton attached to pin 7. at 08:03 AM by David A.

LOW). } } read input value check if the input is HIGH (button released) // turn LED OFF // turn LED ON Restore Edit Page | Page History | Printable View | All Recent Site Changes . OUTPUT). } // declare LED as output // declare pushbutton as input void loop(){ val = digitalRead(inPin). pinMode(inPin.arduino. HIGH). } else { digitalWrite(ledPin.cc/en/Tutorial/Invert> * * turns on and off a light emitting diode(LED) connected to digital * pin 13. which consists in connecting buttons using a * 1K to 10K pull-up resistor. // variable for reading the pin status void setup() { pinMode(ledPin. when pressing a pushbutton attached to pin 7. // choose the pin for the LED int inPin = 2. // if (val == HIGH) { // digitalWrite(ledPin. INPUT). It illustrates the * concept of Active-Low. // choose the input pin (for a pushbutton) int val = 0. * */ int ledPin = 13.Code /* invert * <http://www.

} // declare LED as output // declare pushbutton as input . pinMode(inPin.2 KOhms) to the 5 volt supply. it makes a connection between its two legs. The third connects to a digital i/o pin (here pin 7) which reads the button's state.Arduino : Tutorial / Button Learning Examples | Foundations | Hacking | Links Examples > Digital I/O Button The pushbutton is a component that connects two points in a circuit when you press it. with a pull-down resistor keeping the input LOW. This is because the input is "floating" . (The pin is still connected to 5 volts. That's why you need a pull-up or pulldown resister in the circuit. The second goes from the corresponding leg of the pushbutton to ground. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. the behavior of the sketch will be reversed. // choose the input pin (for a pushbutton) int val = 0. If so. but the resistor in-between them means that the pin is "closer" to ground.that is. When the button is closed (pressed). We connect three wires to the Arduino board.) You can also wire this circuit the opposite way. // choose the pin for the LED int inPin = 2. so that we read a LOW. The example turns on an LED when you press the button. The first goes from one leg of the pushbutton through a pull-up resistor (here 2. and going HIGH when the button is pressed. with the LED normally on and turning off when you press the button. it will more-or-less randomly return either HIGH or LOW. so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. Circuit Code int ledPin = 13. // variable for reading the pin status void setup() { pinMode(ledPin. OUTPUT). INPUT). If you disconnect the digital i/o pin from everything. the LED may blink erratically. connecting the pin to ground.

void loop(){ val = digitalRead(inPin).cc/en/Tutorial/Button) read input value check if the input is HIGH (button released) // turn LED OFF // turn LED ON .arduino. LOW). // if (val == HIGH) { // digitalWrite(ledPin. } else { digitalWrite(ledPin. } } (Printable View of http://www. HIGH).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

the LED (or whatever) is turned on (if it's off) or off (if on). Restore June 16.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. without which pressing the button once would appear to the code as multiple presses. to ignore * noise). at 10:13 AM by David A. // the number of the input pin . Mellis Changed lines 9-10 from: A push-button on pin 7 and an LED on pin 13. Changed lines 16-28 from: /* * Debounce * by David A. * * http://www. the LED (or whatever) is turned on (if it's off) or off (if on). to: A push-button on pin 2 and an LED on pin 13.arduino.cc/en/Tutorial/Debounce */ int inPin = 7. without which pressing the button once would appear to the code as multiple presses. There's * a minimum delay between toggles to debounce the circuit (i. because of a push-button * press). // the number of the input pin Restore June 16. Mellis * * Each time the input pin goes from LOW to HIGH (e. to: This example demonstrates the use of a pushbutton as a switch: each time you press the button. 2007.Debounce History Hide minor edits . Mellis Changed lines 9-10 from: A push-button on pin 2 and an LED on pin 13. // the number of the input pin to: int inPin = 7.g. It also debounces the input. Makes use of the millis() function to keep track of the time when the button is pressed. at 10:17 AM by David A. 2007. at 10:14 AM by David A.e. It also debounces the input. 2007. to: A push-button on pin 7 and an LED on pin 13. Mellis Changed lines 5-6 from: This example demonstrates the use of a pushbutton as a switch: each time you press the button. Changed line 16 from: int inPin = 2. the output pin is toggled from LOW to HIGH or HIGH to LOW.Show changes to markup June 16.

at 02:47 AM by David A..arduino.. the input went from LOW to HIGH). state).e. toggle the output pin and remember // the time to: // if we just pressed the button (i. Mellis Changed lines 16-18 from: /* switch to: /* * Debounce * by David A. 2007.. at 02:46 AM by David A. Restore March 25. 2007.to: int inPin = 2. invert the output Changed lines 46-48 from: digitalWrite(outPin. Mellis Changed lines 9-10 from: A push-button on pin 2 and an LED on pin 13..cc/en/Tutorial/Debounce Deleted lines 41-43: . state). Mellis Changed lines 25-26 from: * David A.. time = millis(). Added lines 51-52: digitalWrite(outPin. and remember when the last button press was time = millis(). // the number of the input pin Restore March 25. // and we've waited long enough since the last press to ignore any noise. Changed line 28 from: int inPin = 2. Added line 41: // .. to: A push-button on pin 7 and an LED on pin 13. // the number of the input pin to: int inPin = 7. to: // . Mellis * 21 November 2006 to: * http://www. // the number of the input pin Changed lines 37-40 from: // if the input just went from LOW and HIGH and we've waited long enough // to ignore any noise on the circuit.

time = millis(). 2007. Circuit A push-button on pin 2 and an LED on pin 13. the LED (or whatever) is turned on (if it's off) or off (if on). It also debounces the input. at 02:45 AM by David A. There's . because of a push-button * press). without which pressing the button once would appear to the code as multiple presses. at 02:45 AM by David A.g. Code /* switch * * Each time the input pin goes from LOW to HIGH (e. Mellis Changed lines 3-4 from: Switch to: Debounce Restore March 25. to: Restore March 25.Renaming Switch example Added lines 1-68: Examples > Digital I/O Switch This example demonstrates the use of a pushbutton as a switch: each time you press the button. Mellis .begin(19200). 2007. state).if (DEBUG) Serial. Changed lines 62-64 from: digitalWrite(outPin. to: digitalWrite(outPin. the output pin is toggled from LOW to HIGH or HIGH to LOW. Changed lines 59-60 from: time = millis(). state).

// the debounce time. pinMode(outPin. Mellis * 21 November 2006 */ int inPin = 2. long time = 0. state). increase if the output flickers void setup() { if (DEBUG) Serial. int reading.e. } Restore Edit Page | Page History | Printable View | All Recent Site Changes . // will quickly become a bigger number than can be stored in an int. time = millis(). toggle the output pin and remember the time (reading == HIGH && previous == LOW && millis() . pinMode(inPin. OUTPUT). previous = reading.time > debounce) { if (state == HIGH) state = LOW.* a minimum delay between toggles to debounce the circuit (i. INPUT). // // // if if the input just went from LOW and HIGH and we've waited long enough to ignore any noise on the circuit. * * David A. } digitalWrite(outPin. } void loop() { reading = digitalRead(inPin). // the last time the output pin was toggled long debounce = 200. to ignore * noise). else state = HIGH. int previous = LOW. int outPin = 13. measured in miliseconds. int state = HIGH.begin(19200). // the number of the input pin // the number of the output pin // the current state of the output pin // the current reading from the input pin // the previous reading from the input pin // the follow variables are long's because the time.

int outPin = 13. int reading. pinMode(outPin... increase if the output flickers void setup() { pinMode(inPin. // and we've waited long enough since the last press to ignore any noise. } void loop() { reading = digitalRead(inPin). the LED (or whatever) is turned on (if it's off) or off (if on). Code int inPin = 7. without which pressing the button once would appear to the code as multiple presses. int previous = LOW. Makes use of the millis() function to keep track of the time when the button is pressed. the input went from LOW to HIGH). // the number of the input pin // the number of the output pin // the current state of the output pin // the current reading from the input pin // the previous reading from the input pin // the follow variables are long's because the time.Arduino : Tutorial / Debounce Learning Examples | Foundations | Hacking | Links Examples > Digital I/O Debounce This example demonstrates the use of a pushbutton as a switch: each time you press the button. // if we just pressed the button (i. measured in miliseconds. // the last time the output pin was toggled long debounce = 200.time > debounce) { // ... OUTPUT). It also debounces the input. INPUT). long time = 0.e. invert the output . // the debounce time. int state = HIGH. Circuit A push-button on pin 7 and an LED on pin 13. // will quickly become a bigger number than can be stored in an int. if (reading == HIGH && previous == LOW && millis() .

// . previous = reading.cc/en/Tutorial/Debounce) . state). else state = HIGH.. and remember when the last button press was time = millis().if (state == HIGH) state = LOW.arduino. } (Printable View of http://www.. } digitalWrite(outPin.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

LOW). HIGH). i++) pinMode(pins[i].. // The higher the number.e. Deleted lines 43-48: for (i = 7. i >= 2. // pausing. at 08:37 PM by David A. i++) { // loop through each pin.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. LOW). 3.Loop History Hide minor edits . HIGH). HIGH). at 12:20 PM by David A. 5. Mellis Changed lines 18-19 from: int timer = 100. Restore April 22. to: digitalWrite(pins[i]. i <= 7. i >= 0. OUTPUT). 2007.. i++) { to: for (i = 0. i < num_pins. Changed line 42 from: digitalWrite(i. // and turning it off. Mellis Changed line 40 from: digitalWrite(i. OUTPUT). digitalWrite(pins[i]. 7 }. Changed lines 34-39 from: for (i = 2. i--) { // the array elements are numbered from 0 to num_pins . // an array of pin numbers int num_pins = 6.1 // set each pin as an output . the slower the timing. delay(timer). 4.1. 6.Show changes to markup September 23. LOW). to: int timer = 100. i <= 7. } for (i = num_pins . i < num_pins. 2007. i--) { Deleted line 42: delay(timer). i++) pinMode(i. // turning it on. to: digitalWrite(pins[i]. to: for (i = 0. the length of the array) Changed lines 26-27 from: for (i = 2. int pins[] = { 2. // the number of pins (i. digitalWrite(pins[i].

Mellis Changed lines 1-4 from: Examples > Digital I/O loop to: Examples > Digital I/O Loop Restore January 28. delay(timer). Mellis - . 2007. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. HIGH). Restore January 29. to: Loop We also call this example "Knight Rider" in memory to a TV-series from the 80's where the famous David Hasselhoff had an AI machine driving his Pontiac. Mellis Changed lines 3-6 from: Knight Rider We have named this example in memory to a TV-series from the 80's where the famous David Hasselhoff had an AI machine driving his Pontiac. digitalWrite(i. 2007. delay(timer). The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. 2007. } Restore April 15. Mellis Added lines 11-12: Circuit Added lines 15-16: Code Restore January 28.digitalWrite(i. at 05:01 AM by David A. 2007. 2007. 2007. at 04:40 AM by David A. LOW). at 04:40 AM by David A. at 04:28 AM by David A. Mellis Changed lines 3-4 from: Loop to: Knight Rider Restore January 28. at 11:39 AM by David A. Mellis Changed lines 1-2 from: Knight Rider to: Examples > Digital I/O loop Restore January 28. at 10:33 AM by David A.

LOW). The first code example will make the LEDs blink in a sequence. digitalWrite(i. digitalWrite(i. i++) pinMode(i. 2. at 08:25 AM by David A. LOW). The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. delay(timer). delay(timer). Mellis Added lines 1-29: int timer = 100. delay(timer). } } Restore 7. for (i = 2.HIGH/LOW) and delay(time) . it would be interesting to use the Knight Rider as a metaphor. OUTPUT).flickr.jpg Restore January 14. delay(timer)..) construction to perform the very same thing. http://static. } void loop() { int i. i <= 7. } for (i = 7.7 on the board using 220 Ohm resistors. Edit Page | Page History | Printable View | All Recent Site Changes . Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O board. i++) { HIGH). but in fewer lines. one by one using only digitalWrite(pinNum. This example makes use of 6 LEDs connected to the pins 2 .Added lines 1-10: Knight Rider We have named this example in memory to a TV-series from the 80's where the famous David Hasselhoff had an AI machine driving his Pontiac. i <= digitalWrite(i. for (i = 2. The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way. i >= digitalWrite(i. i--) { HIGH). 2007. The second example shows how to use a for(. void setup() { int i.com/27/61933851_3b9a25ab42.

) construction to perform the very same thing. 5. 6. This example makes use of 6 LEDs connected to the pins 2 .7 on the board using 220 Ohm resistors. i++) pinMode(pins[i]. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects.HIGH/LOW) and delay(time) .. Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O board. // an array of pin numbers int num_pins = 6. the length of the array) void setup() { int i. but in fewer lines. 4. for (i = 0. } // the array elements are numbered from 0 to num_pins .e.1 // set each pin as an output . 7 }. i < num_pins.Arduino : Tutorial / Loop Learning Examples | Foundations | Hacking | Links Examples > Digital I/O Loop We also call this example "Knight Rider" in memory to a TV-series from the 80's where the famous David Hasselhoff had an AI machine driving his Pontiac. the slower the timing. The first code example will make the LEDs blink in a sequence. one by one using only digitalWrite(pinNum. // The higher the number. Circuit Code int timer = 100. it would be interesting to use the Knight Rider as a metaphor. OUTPUT). The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way. // the number of pins (i. 3. int pins[] = { 2. The second example shows how to use a for(.

i < num_pins. HIGH). delay(timer). // pausing. LOW).1.cc/en/Tutorial/Loop) . digitalWrite(pins[i]. delay(timer). // turning it on. digitalWrite(pins[i]. HIGH). i--) { digitalWrite(pins[i].. } } (Printable View of http://www.. i >= 0. // and turning it off. digitalWrite(pins[i]. LOW).arduino.void loop() { int i. } for (i = num_pins . i++) { // loop through each pin. for (i = 0.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

When the shaft is turned all the way in the other direction.AnalogInput History Hide minor edits . In this example. In the easiest case we connect . we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. at 02:49 AM by David A. The amount of time the LED will be on and off depends on the value obtained by analogRead(). By turning the shaft of the potentiometer.org> Turns on and off a light emitting diode(LED) connected to digital pin 13. Mellis Added lines 1-43: Examples > Analog I/O Analog Input A potentiometer is a simple knob that provides a variable resistance. This changes the relative "closeness" of that pin to 5 volts and ground. We connect three wires to the Arduino board. In between. there are 0 volts going to the pin.Show changes to markup March 25. which we can read into the Arduino board as an analog value. there are 5 volts going to the pin and we read 1023. The third goes from analog input 2 to the middle pin of the potentiometer. 2007. analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin. The first goes to ground from one of the outer pins of the potentiometer. When the shaft is turned all the way in one direction.0j0.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. and we read 0. Circuit Code /* * * * * * * AnalogInput by DojoDave <http://www. The second goes from 5 volts to the other outer pin of the potentiometer. giving us a different analog input. that value controls the rate at which an LED blinks.

int val = 0. // select the input pin for the potentiometer // select the pin for the LED // variable to store the value coming from the sensor void setup() { pinMode(ledPin. HIGH). delay(val). OUTPUT). digitalWrite(ledPin. */ int potPin = 2. LOW).* a potentiometer to analog pin 2. } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin). int ledPin = 13. digitalWrite(ledPin. delay(val). } // // // // // read turn stop turn stop the the the the the value from the sensor ledPin on program for some time ledPin off program for some time Restore Edit Page | Page History | Printable View | All Recent Site Changes .

analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin. The amount of time the LED will be on and off depends on * the value obtained by analogRead(). which we can read into the Arduino board as an analog value.0j0. When the shaft is turned all the way in one direction. The first goes to ground from one of the outer pins of the potentiometer. By turning the shaft of the potentiometer. In the easiest case we connect * a potentiometer to analog pin 2. int val = 0. The second goes from 5 volts to the other outer pin of the potentiometer.org> * * Turns on and off a light emitting diode(LED) connected to digital * pin 13. we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. and we read 0. When the shaft is turned all the way in the other direction. int ledPin = 13. Circuit Code /* * AnalogInput * by DojoDave <http://www. there are 5 volts going to the pin and we read 1023. } . The third goes from analog input 2 to the middle pin of the potentiometer. there are 0 volts going to the pin. that value controls the rate at which an LED blinks. In this example. We connect three wires to the Arduino board. */ int potPin = 2. This changes the relative "closeness" of that pin to 5 volts and ground.Arduino : Tutorial / Analog Input Learning Examples | Foundations | Hacking | Links Examples > Analog I/O Analog Input A potentiometer is a simple knob that provides a variable resistance. OUTPUT). // select the input pin for the potentiometer // select the pin for the LED // variable to store the value coming from the sensor // declare the ledPin as an OUTPUT void setup() { pinMode(ledPin. giving us a different analog input. In between.

HIGH).void loop() { val = analogRead(potPin).arduino. delay(val).cc/en/Tutorial/AnalogInput) . } // // // // // read turn stop turn stop the the the the the value from the sensor ledPin on program for some time ledPin off program for some time (Printable View of http://www. LOW). digitalWrite(ledPin. delay(val). digitalWrite(ledPin.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

value-=5) // fade out (from max to min) { analogWrite(ledpin. int ledpin = 9. Added lines 9-10: An LED connected to digital pin 9. value <= 255. delay(30).Fading History Hide minor edits . // waits for 30 milli seconds to see the dimming effect } for(value = 255. value+=5) // fade in (from min to max) { analogWrite(ledpin. Mellis Added lines 5-6: Demonstrates the use of analog output (PWM) to fade an LED. // sets the value (range from 0 to 255) delay(30). void setup() { // nothing for setup } void loop() { for(value = 0 .Show changes to markup March 26. value >=0. Mellis Added lines 1-31: Examples > Analog I/O Fading Circuit Code int value = 0. Restore March 26. 2007. value). value). } } // variable to keep the actual value // light connected to digital pin 9 Restore Edit Page | Page History | Printable View | All Recent Site Changes . at 06:54 AM by David A.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 2007. at 06:52 AM by David A.

Code int value = 0.arduino. value). int ledpin = 9.Arduino : Tutorial / Fading Learning Examples | Foundations | Hacking | Links Examples > Analog I/O Fading Demonstrates the use of analog output (PWM) to fade an LED. value >=0. value <= 255. } for(value = 255.cc/en/Tutorial/Fading) // variable to keep the actual value // light connected to digital pin 9 // fade in (from min to max) // sets the value (range from 0 to 255) // waits for 30 milli seconds to see the dimming effect // fade out (from max to min) . value). delay(30). delay(30). void setup() { // nothing for setup } void loop() { for(value = 0 . value+=5) { analogWrite(ledpin. } } (Printable View of http://www. Circuit An LED connected to digital pin 9. value-=5) { analogWrite(ledpin.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

at 03:42 AM by David A. Mellis - . // short delay to avoid overloading the serial port // short delay to avoid overloading the serial port Restore April 08. to: Serial. to: delay(10). // send the string "Knock!" back to the computer. at 03:42 AM by David A. delay(10). at 06:21 PM by Paul Badger Changed line 49 from: } to: } Restore April 08. 2007. 2008. Mellis Changed lines 1-2 from: Knock Sensor to: Examples > Analog I/O Knock Restore March 25. 2008. followed by newline // short delay to avoid overloading the serial port // send the string "Knock!" back to the computer.println("Knock!"). at 06:21 PM by Paul Badger Changed lines 47-49 from: Serial.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. at 06:20 PM by Paul Badger Added lines 48-49: delay(10). Deleted line 50: delay(100).Knock History Hide minor edits . followed by // short delay to avoid overloading the serial port Restore April 08. 2008. at 06:21 PM by Paul Badger Changed line 48 from: delay(10). newline delay(10). 2007.println("Knock!"). 2008.Show changes to markup April 08. // we have to make a delay to avoid overloading the serial port // short delay to avoid overloading the serial port Restore March 25.

More information can be found on the Arduino pages: http://www. it will send the string "Knock!" back to the computer over the serial port.jtnimoy.SUBSTITUTE COMXX with your serial port name!! . the program is printing (thus sending) "Knock!" over the serial port. what stands for EOLN or End Of LiNe. or CR .0j0.cc // Created 23 November 2005 // Updated 23 November 2005 import processing. to: The code example will capture the knock and if it is stronger than a certain threshold. In order to see this text you can use the Arduino serial monitor. the processing program will toggle the background color of the screen and print out "Knock!" in the command line.org> // based on Analog In by Josh Nimoy <http://itp. it will send the string "Knock!" back to the computer over the serial port. // Open your serial port port = new Serial(this. which will read data from the serial port and show it in a window.com> // // // // // // // Reads a value from the serial port and makes the background color toggle when there is a knock on a piezo used as a knock sensor. int NEWLINE = 10.arduino. String buff = "". 200).g. Processing. or make your own program in e. // Knock In // by David Cuartielles <http://www.*. and byte 13. Later in this article we propose a program that works for the software designed by Reas and Fry. we would like to capture this "knock" from the Arduino board. "COMXX". First we see that whenever there is a knock bigger that the threshold.Changed lines 9-10 from: The code example will capture the knock and if it is stronger than a certain threshold. Changed line 15 from: [= to: [@ Changed lines 50-117 from: =] Representing the Knock in Processing If. Directly after sends the byte 10. Those two symbols will be useful to determine when the message sent by the board is over.serial. } void draw() { // Process each one of the serial port events // <-. void setup() { size(200. Running this example requires you have an Arduino board as peripheral hardware sending values and adding an EOLN + CR in the end. int val = 0.g. we have to look into how the information is transferred from the board over the serial port. e.Carriage Return. Once that happens. In order to see this text you could either use a terminal program. Serial port. 9600).

or make your own program in e. In our example we are plugging the Piezo on the analog input pin number 0.while (port. commercial devices are usually having a red and a black wires indicating how to plug it to the board. at 03:25 AM by David A. } else { buff = buff.flickr. These converters read a voltage value and transform it into a value encoded digitally.com/28/53535494_73f63436cb. A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. we transform the voltage into a value in the range 0. it will send the string "Knock!" back to the computer over the serial port.g. // Clear the value of "buff" buff = "".analog to digital converter. buff. The code example will capture the knock and if it is stronger than a certain threshold.read()).substring(1.org> Program using a Piezo element as if it was a knock sensor. http://static. } } to: @] Restore March 25. We connect the black one to ground and the red one to the input. In the case of the Arduino boards. We have to basically listen to an analog pin and detect . that supports the functionality of reading a value between 0 and 5volts.jpg Example of connection of a Piezo to analog pin 0 with a resistor /* * * * * * Knock Sensor by DojoDave <http://www. what will allow us to use it as a knock sensor. Mellis Added lines 1-117: Knock Sensor Here we use a Piezo element to detect sound.1024. and not just a plain HIGH or LOW. The other thing to remember is that Piezos have polarity. } else { val = 0. Processing. } void serialEvent(int serial) { if(serial != NEWLINE) { buff += char(serial). Later in this article we propose a program that works for the software designed by Reas and Fry. } println(buff). In order to see this text you could either use a terminal program. which will read data from the serial port and show it in a window.0j0. We are taking advantage of the processors capability to read analog signals through its ADC . while 1024 represents 5volts at the input of one of the six analog pins.available() > 0) { serialEvent(port.length()-1). 0 represents 0volts. then they will just look like a metallic disc and are easier to use as input sensors. // Capture the string and print it to the commandline // we have to take from position 1 because // the Arduino sketch sends EOLN (10) and CR (13) if (val == 0) { val = 255. in the example we have plugged it directly in the female connectors.. 2007. We also have to connect a resistor in the range of the Megaohms in parallel to the Piezo element. Sometimes it is possible to acquire Piezo elements without a plastic housing. } background(val).

cc/en/Tutorial/Knock */ int ledPin = 13. // use the serial port } void loop() { val = analogRead(knockSensor). int NEWLINE = 10.0j0.begin(9600).org> // based on Analog In by Josh Nimoy <http://itp. // turn the led on or off Serial. e. we have to look into how the information is transferred from the board over the serial port.serial. the processing program will toggle the background color of the screen and print out "Knock!" in the command line. * and toggles the LED on pin 13. // declare the ledPin as as OUTPUT Serial. // Knock In // by David Cuartielles <http://www. we would like to capture this "knock" from the Arduino board. // send the string "Knock!" back to the computer. * * http://www.Carriage Return.*.g. void setup() { . More information can be found on the Arduino pages: http://www. int THRESHOLD = 100. the program is printing (thus sending) "Knock!" over the serial port. statePin). // toggle the status of the ledPin (this trick doesn't use time cycles) digitalWrite(ledPin.com> // // // // // // // Reads a value from the serial port and makes the background color toggle when there is a knock on a piezo used as a knock sensor. Directly after sends the byte 10. Once that happens. and byte 13.cc // Created 23 November 2005 // Updated 23 November 2005 import processing.arduino. Those two symbols will be useful to determine when the message sent by the board is over. First we see that whenever there is a knock bigger that the threshold. int knockSensor = 0. byte val = 0.println("Knock!"). or CR . Serial port. OUTPUT). String buff = "". Running this example requires you have an Arduino board as peripheral hardware sending values and adding an EOLN + CR in the end.* if the signal goes over a certain threshold. followed by newline } delay(100).arduino.jtnimoy. to toggle the light threshold value to decide when the detected sound is a knock or not void setup() { pinMode(ledPin. // // // // // led connected to control pin 13 the knock sensor will be plugged at analog pin 0 variable to store the value read from the sensor pin variable used to store the last LED status. It writes * "knock" to the serial port if the Threshold is crossed. what stands for EOLN or End Of LiNe. int val = 0. int statePin = LOW. // we have to make a delay to avoid overloading the serial port } Representing the Knock in Processing If. // read the sensor and store it in the variable "val" if (val >= THRESHOLD) { statePin = !statePin.

} else { val = 0. // Open your serial port port = new Serial(this. "COMXX". // Capture the string and print it to the commandline // we have to take from position 1 because // the Arduino sketch sends EOLN (10) and CR (13) if (val == 0) { val = 255.substring(1. } println(buff). 200).available() > 0) { serialEvent(port.read()). // Clear the value of "buff" buff = "". } else { buff = buff. buff. } void serialEvent(int serial) { if(serial != NEWLINE) { buff += char(serial). 9600).size(200. } } // <-. } void draw() { // Process each one of the serial port events while (port.SUBSTITUTE COMXX with your serial port name!! Restore Edit Page | Page History | Printable View | All Recent Site Changes .length()-1). } background(val).

0j0. that supports the functionality of reading a value between 0 and 5volts. Example of connection of a Piezo to analog pin 0 with a resistor /* * * * * * Knock Sensor by DojoDave <http://www. In the case of the Arduino boards.org> Program using a Piezo element as if it was a knock sensor. it will send the string "Knock!" back to the computer over the serial port.. then they will just look like a metallic disc and are easier to use as input sensors.1024. 0 represents 0volts. in the example we have plugged it directly in the female connectors. The code example will capture the knock and if it is stronger than a certain threshold. In order to see this text you can use the Arduino serial monitor. Sometimes it is possible to acquire Piezo elements without a plastic housing.Arduino : Tutorial / Knock Learning Examples | Foundations | Hacking | Links Examples > Analog I/O Knock Here we use a Piezo element to detect sound.analog to digital converter. and not just a plain HIGH or LOW. These converters read a voltage value and transform it into a value encoded digitally. what will allow us to use it as a knock sensor. The other thing to remember is that Piezos have polarity. We also have to connect a resistor in the range of the Megaohms in parallel to the Piezo element. In our example we are plugging the Piezo on the analog input pin number 0. We connect the black one to ground and the red one to the input. commercial devices are usually having a red and a black wires indicating how to plug it to the board. We are taking advantage of the processors capability to read analog signals through its ADC . we transform the voltage into a value in the range 0. A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. while 1024 represents 5volts at the input of one of the six analog pins. We have to basically listen to an analog pin and detect .

It writes * "knock" to the serial port if the Threshold is crossed.arduino. statePin).cc/en/Tutorial/Knock) . int THRESHOLD = 100. followed by // short delay to avoid overloading the serial port (Printable View of http://www. * * http://www.println("Knock!"). byte val = 0. newline delay(10).arduino. OUTPUT).* if the signal goes over a certain threshold.begin(9600). to toggle the light threshold value to decide when the detected sound is a knock or not void setup() { pinMode(ledPin. // use the serial port } void loop() { val = analogRead(knockSensor). time cycles) digitalWrite(ledPin. int knockSensor = 0.cc/en/Tutorial/Knock */ int ledPin = 13. int statePin = LOW. if (val >= THRESHOLD) { statePin = !statePin. } } // read the sensor and store it in the variable "val" // toggle the status of the ledPin (this trick doesn't use // turn the led on or off // send the string "Knock!" back to the computer. Serial. * and toggles the LED on pin 13. // declare the ledPin as as OUTPUT Serial. // // // // // led connected to control pin 13 the knock sensor will be plugged at analog pin 0 variable to store the value read from the sensor pin variable used to store the last LED status.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Smoothing History Hide minor edits . Mellis Added lines 1-12: Examples > Analog I/O Smoothing . Demonstrates the use of arrays. to: Reads repeatedly from an analog input.begin(9600).println(average). // send it to the computer (as ASCII digits) // analog inputs go up to 1023. calculating a running average * and outputting it to an analog output.cc/en/Tutorial/Smoothing */ Changed lines 26-27 from: int outputPin = 9. Mellis <dam@mellis. 2007. LED on pin 9. Demonstrates the use of arrays. Mellis Changed lines 5-6 from: Reads repeatedly from an analog input. average / 4). to: Added line 29: Serial. outputs to 255 // initialize serial communication with computer Restore March 25. Changed lines 9-10 from: Potentiometer on analog input pin 0. calculating a running average and outputting it to an analog output.org> * * Reads repeatedly from an analog input. at 12:19 PM by David A.arduino.Show changes to markup April 22. 2007. Changed line 45 from: analogWrite(outputPin. at 03:02 AM by David A. to: Serial. to: Potentiometer on analog input pin 0. calculating a running average and printing it to the computer. Deleted lines 13-22: /* * Smoothing * David A. * * http://www.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.

i++) readings[i] = 0. to: for (int i = 0. // the index of the current reading int total = 0. // the more the readings will be smoothed. The higher the number. // the average int inputPin = 0. Changed lines 40-41 from: for (int i = 0. total += samples[index].. index = (index + 1) % NUMSAMPLES.Reads repeatedly from an analog input. analogWrite(outputPin. if (index >= NUMREADINGS) index = 0. Restore // // // // subtract the last reading read from the sensor add the reading to the total advance to the next index // initialize all the readings to 0 // if we're at the end of the array. average / 4). i < NUMSAMPLES. int index = 0. but the slower the output will // respond to the input. i++) samples[i] = 0. Using a #define rather than a normal variable lets // use this value to determine the size of the readings array.cc/en/Tutorial/Smoothing */ // Define the number of samples to keep track of. // the readings from the analog input int index = 0. // the running total int average = 0. Mellis <dam@mellis. 1... total / NUMSAMPLES). int actuator = 9. int total = 0.arduino. Demonstrates the use of arrays. define NUMREADINGS 10 int readings[NUMREADINGS]. LED on pin 9. samples[index] = analogRead(sensor). readings[index] = analogRead(inputPin). to: /* * Smoothing * David A.org> * * Reads repeatedly from an analog input. int outputPin = 9. outputs to 255 . average = total / NUMREADINGS. Code Changed lines 14-22 from: 1.wrap around to the beginning // calculate the average // analog inputs go up to 1023. calculating a running average * and outputting it to an analog output. to: total -= readings[index]. * * http://www. Changed lines 46-50 from: total -= samples[index]. analogWrite(actuator. int sensor = 0. i < NUMREADINGS. total += readings[index]. define NUMSAMPLES 10 int samples[NUMSAMPLES]. index = (index + 1). // .. Circuit Potentiometer on analog input pin 0. calculating a running average and outputting it to an analog output.

int index = 0. index = (index + 1) % NUMSAMPLES. int sensor = 0. i++) samples[i] = 0. analogWrite(actuator. int actuator = 9. Mellis Added line 1: [@ Added line 25: @] Restore January 14. 2007. int total = 0. i < NUMSAMPLES. define NUMSAMPLES 10 int samples[NUMSAMPLES]. total += samples[index]. void setup() { for (int i = 0. at 08:28 AM by David A. at 08:28 AM by David A. } void loop() { total -= samples[index]. 2007. samples[index] = analogRead(sensor). Mellis Added lines 1-23: 1.January 14. } Restore Edit Page | Page History | Printable View | All Recent Site Changes . total / NUMSAMPLES).

begin(9600). i++) readings[i] = 0.arduino. for (int i = 0. // .Arduino : Tutorial / Smoothing Learning Examples | Foundations | Hacking | Links Examples > Analog I/O Smoothing Reads repeatedly from an analog input.cc/en/Tutorial/Smoothing) // if we're at the end of the array. average = 0. total = 0. } // initialize serial communication with computer // initialize all the readings to 0 void loop() { total -= readings[index]. Code // Define the number of samples to keep track of.wrap around to the beginning // calculate the average // send it to the computer (as ASCII digits) . // the more the readings will be smoothed. calculating a running average and printing it to the computer. Circuit Potentiometer on analog input pin 0. i < NUMREADINGS.. // read from the sensor total += readings[index]. The higher the number. } (Printable View of http://www. void setup() { Serial. #define NUMREADINGS 10 int int int int readings[NUMREADINGS]. // advance to the next index if (index >= NUMREADINGS) index = 0..println(average). // // // // the the the the readings from the analog input index of the current reading running total average int inputPin = 0.. // subtract the last reading readings[index] = analogRead(inputPin). // add the reading to the total index = (index + 1).. Demonstrates the use of arrays. but the slower the output will // respond to the input. average = total / NUMREADINGS. Using a #define rather than a normal variable lets // use this value to determine the size of the readings array. Serial. index = 0.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Restore April 11. dec: 40.. hex: 26.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. hex: 23. at 07:02 AM by David A.. 2007. 2007. Mellis Changed lines 60-76 from: @] to: @] Output ASCII Table !. at 10:16 AM by David A. oct: 47... %. hex: 22. hex: 25. Mellis Added lines 1-60: Examples > Communication ASCII Table Demonstrates the advanced serial printing functions by generating a table of characters and their ASCII values in decimal. ~ Character Map hex: 21. dec: 36. dec: 35.Show changes to markup April 11. hex: 28. dec: 33. hex: 24.. but the Arduino has to be connected to the computer. and binary. Restore March 26. hexadecimal.. 2007. bin: bin: bin: bin: bin: bin: bin: bin: 100001 100010 100011 100100 100101 100110 100111 101000 . &. Circuit None. $. oct: 44. dec: 37. ". oct: 45. oct: 50. oct: 41. dec: 34.ASCIITable History Hide minor edits . oct: 46. oct: 43.zambetti. Deleted lines 75-76: . dec: 38. dec: 39.com> void setup() { . oct: 42. at 10:16 AM by David A. (. octal. Mellis Added line 74: . Code // ASCII Table // by Nicholas Zambetti <http://www. #. hex: 27. '.

Serial.begin(9600); // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); // wait for the long string to be sent delay(100); } int number = 33; // first visible character '!' is #33 void loop() { Serial.print(number, BYTE); Serial.print(", dec: "); Serial.print(number); // Serial.print(number, DEC); Serial.print(", hex: "); Serial.print(number, HEX); Serial.print(", oct: "); Serial.print(number, OCT); Serial.print(", bin: "); Serial.println(number, BIN);

// prints value unaltered, first will be '!'

// prints value as string in decimal (base 10) // this also works

// prints value as string in hexadecimal (base 16)

// prints value as string in octal (base 8)

// prints value as string in binary (base 2) // also prints ending line break

// if printed last visible character '~' #126 ... if(number == 126) { // loop forever while(true) { continue; } } number++; // to the next character delay(100); // allow some time for the Serial data to be sent }

Restore

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino : Tutorial / ASCII Table
Learning Examples | Foundations | Hacking | Links

Examples > Communication

ASCII Table
Demonstrates the advanced serial printing functions by generating a table of characters and their ASCII values in decimal, hexadecimal, octal, and binary.

Circuit
None, but the Arduino has to be connected to the computer.

Code
// ASCII Table // by Nicholas Zambetti <http://www.zambetti.com> void setup() { Serial.begin(9600); // prints title with ending line break Serial.println("ASCII Table ~ Character Map"); // wait for the long string to be sent delay(100); } int number = 33; // first visible character '!' is #33 void loop() { Serial.print(number, BYTE); Serial.print(", dec: "); Serial.print(number); // Serial.print(number, DEC); Serial.print(", hex: "); Serial.print(number, HEX); Serial.print(", oct: "); Serial.print(number, OCT); Serial.print(", bin: "); Serial.println(number, BIN);

// prints value unaltered, first will be '!' // prints value as string in decimal (base 10) // this also works // prints value as string in hexadecimal (base 16) // prints value as string in octal (base 8) // prints value as string in binary (base 2) // also prints ending line break

// if printed last visible character '~' #126 ... if(number == 126) { // loop forever while(true) { continue; } } number++; // to the next character delay(100); // allow some time for the Serial data to be sent }

Output
ASCII Table !, dec: 33, ", dec: 34, #, dec: 35, ~ Character Map hex: 21, oct: 41, bin: 100001 hex: 22, oct: 42, bin: 100010 hex: 23, oct: 43, bin: 100011

$, dec: %, dec: &, dec: ', dec: (, dec: ...

36, 37, 38, 39, 40,

hex: hex: hex: hex: hex:

24, 25, 26, 27, 28,

oct: oct: oct: oct: oct:

44, 45, 46, 47, 50,

bin: bin: bin: bin: bin:

100100 100101 100110 100111 101000

(Printable View of http://www.arduino.cc/en/Tutorial/ASCIITable)

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Tutorial.Dimmer History
Hide minor edits - Show changes to markup April 11, 2007, at 10:36 AM by David A. Mellis Added lines 1-78: Examples > Communication

Dimmer
Demonstrates the sending data from the computer to the Arduino board, in this case to control the brightness of an LED. The data is sent in individual bytes, each of which ranges from 0 to 255. Arduino reads these bytes and uses them to set the brightness of the LED.

Circuit
An LED connected to pin 9 (with appropriate resistor).

Code
int ledPin = 9; void setup() { // begin the serial communication Serial.begin(9600); pinMode(ledPin, OUTPUT); } void loop() { byte val; // check if data has been sent from the computer if (Serial.available()) { // read the most recent byte (which will be from 0 to 255) val = Serial.read(); // set the brightness of the LED analogWrite(ledPin, val); } }

Processing Code
// Dimmer - sends bytes over a serial port // by David A. Mellis import processing.serial.*; Serial port; void setup() { size(256, 150);

println("Available serial ports:"); println(Serial.list()); // Uses the first port in this list (number 0). Change this to // select the port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin() in your // Arduino sketch. port = new Serial(this, Serial.list()[0], 9600); // If you know the name of the port used by the Arduino board, you // can specify it directly like this. //port = new Serial(this, "COM1", 9600); } void draw() { // draw a gradient from black to white for (int i = 0; i < 256; i++) { stroke(i); line(i, 0, i, 150); } // write the current X-position of the mouse to the serial port as // a single byte port.write(mouseX); }

Restore

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino : Tutorial / Dimmer
Learning Examples | Foundations | Hacking | Links

Examples > Communication

Dimmer
Demonstrates the sending data from the computer to the Arduino board, in this case to control the brightness of an LED. The data is sent in individual bytes, each of which ranges from 0 to 255. Arduino reads these bytes and uses them to set the brightness of the LED.

Circuit
An LED connected to pin 9 (with appropriate resistor).

Code
int ledPin = 9; void setup() { // begin the serial communication Serial.begin(9600); pinMode(ledPin, OUTPUT); } void loop() { byte val; // check if data has been sent from the computer if (Serial.available()) { // read the most recent byte (which will be from 0 to 255) val = Serial.read(); // set the brightness of the LED analogWrite(ledPin, val); } }

Processing Code
// Dimmer - sends bytes over a serial port // by David A. Mellis import processing.serial.*; Serial port; void setup() { size(256, 150); println("Available serial ports:"); println(Serial.list()); // Uses the first port in this list (number 0). Change this to // select the port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin() in your // Arduino sketch. port = new Serial(this, Serial.list()[0], 9600); // If you know the name of the port used by the Arduino board, you // can specify it directly like this. //port = new Serial(this, "COM1", 9600); } void draw()

{ // draw a gradient from black to white for (int i = 0; i < 256; i++) { stroke(i); line(i, 0, i, 150); } // write the current X-position of the mouse to the serial port as // a single byte port.write(mouseX); }
(Printable View of http://www.arduino.cc/en/Tutorial/Dimmer)

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Tutorial.Graph History
Hide minor edits - Show changes to markup March 25, 2007, at 06:14 AM by David A. Mellis Added lines 1-15: Examples > Communication

Graph
A simple example of communication from the Arduino board to the computer: the value of an analog input is printed. We call this "serial" communication because the connection appears to both the Arduino and the computer as an old-fashioned serial port, even though it may actually use a USB cable. You can use the Arduino serial monitor to view the sent data, or it can be read by Processing (see code below), Flash, PD, Max/MSP, etc.

Circuit
An analog input connected to analog input pin 0.

Code
Changed line 24 from: Serial.print(analogRead(0) / 4, BYTE); to: Serial.println(analogRead(0)); Changed lines 27-28 from: /* to: @]

Processing Code
[@ // Graph // by David A. Mellis // // Demonstrates reading data from the Arduino board by graphing the // values received. // // based on Analog In // by <a href="http://itp.jtnimoy.com">Josh Nimoy</a>. Added lines 44-47: String buff = ""; int NEWLINE = 10; // Store the last 64 values received so we can graph them. Changed lines 54-56 from: // Print a list in case COM1 doesn't work out //println("Available serial ports:"); //printarr(PSerial.list()); to: println("Available serial ports:"); println(Serial.list());

Changed lines 57-58 from: //port = new Serial(this, "COM1", 9600); // Uses the first available port to: // // // // // Uses the first port in this list (number 0). Change this to select the port corresponding to your Arduino board. The last parameter (e.g. 9600) is the speed of the communication. It has to correspond to the value passed to Serial.begin() in your Arduino sketch.

Added lines 63-66: // If you know the name of the port used by the Arduino board, you // can specify it directly like this. //port = new Serial(this, "COM1", 9600); Added line 74: // Graph the stored values by drawing a lines between them. Changed lines 84-87 from: println(serial); for (int i = 0; i < 63; i++) values[i] = values[i + 1]; to: if (serial != NEWLINE) { // Store all the characters on the line. buff += char(serial); } else { // The end of each line is marked by two characters, a carriage // return and a newline. We're here because we've gotten a newline, // but we still need to strip off the carriage return. buff = buff.substring(0, buff.length()-1); Changed lines 93-107 from: values[63] = serial; to: // Parse the String into an integer. We divide by 4 because // analog inputs go from 0 to 1023 while colors in Processing // only go from 0 to 255. int val = Integer.parseInt(buff)/4; // Clear the value of "buff" buff = ""; // Shift over the existing values to make room for the new one. for (int i = 0; i < 63; i++) values[i] = values[i + 1]; // Add the received value to the array. values[63] = val; } Deleted line 108: / Restore January 14, 2007, at 08:38 AM by David A. Mellis Added lines 1-54: void setup()

{ Serial.begin(9600); } void loop() { Serial.print(analogRead(0) / 4, BYTE); delay(20); } /* import processing.serial.*; Serial port; int[] values = new int[64]; void setup() { size(512, 256); // Print a list in case COM1 doesn't work out //println("Available serial ports:"); //printarr(PSerial.list()); //port = new Serial(this, "COM1", 9600); // Uses the first available port port = new Serial(this, Serial.list()[0], 9600); } void draw() { background(53); stroke(255); for (int i = 0; i < 63; i++) line(i * 8, 255 - values[i], (i + 1) * 8, 255 - values[i + 1]); while (port.available() > 0) serialEvent(port.read()); } void serialEvent(int serial) { println(serial); for (int i = 0; i < 63; i++) values[i] = values[i + 1]; values[63] = serial; } */ Restore

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino : Tutorial / Graph
Learning Examples | Foundations | Hacking | Links

Examples > Communication

Graph
A simple example of communication from the Arduino board to the computer: the value of an analog input is printed. We call this "serial" communication because the connection appears to both the Arduino and the computer as an old-fashioned serial port, even though it may actually use a USB cable. You can use the Arduino serial monitor to view the sent data, or it can be read by Processing (see code below), Flash, PD, Max/MSP, etc.

Circuit
An analog input connected to analog input pin 0.

Code
void setup() { Serial.begin(9600); } void loop() { Serial.println(analogRead(0)); delay(20); }

Processing Code
// // // // // // // // Graph by David A. Mellis Demonstrates reading data from the Arduino board by graphing the values received. based on Analog In by <a href="http://itp.jtnimoy.com">Josh Nimoy</a>.

import processing.serial.*; Serial port; String buff = ""; int NEWLINE = 10; // Store the last 64 values received so we can graph them. int[] values = new int[64]; void setup() { size(512, 256); println("Available serial ports:"); println(Serial.list()); // Uses the first port in this list (number 0). Change this to // select the port corresponding to your Arduino board. The last // parameter (e.g. 9600) is the speed of the communication. It // has to correspond to the value passed to Serial.begin() in your // Arduino sketch. port = new Serial(this, Serial.list()[0], 9600); // If you know the name of the port used by the Arduino board, you // can specify it directly like this.

//port = new Serial(this, "COM1", 9600); } void draw() { background(53); stroke(255); // Graph the stored values by drawing a lines between them. for (int i = 0; i < 63; i++) line(i * 8, 255 - values[i], (i + 1) * 8, 255 - values[i + 1]); while (port.available() > 0) serialEvent(port.read()); } void serialEvent(int serial) { if (serial != NEWLINE) { // Store all the characters on the line. buff += char(serial); } else { // The end of each line is marked by two characters, a carriage // return and a newline. We're here because we've gotten a newline, // but we still need to strip off the carriage return. buff = buff.substring(0, buff.length()-1); // Parse the String into an integer. We divide by 4 because // analog inputs go from 0 to 1023 while colors in Processing // only go from 0 to 255. int val = Integer.parseInt(buff)/4; // Clear the value of "buff" buff = ""; // Shift over the existing values to make room for the new one. for (int i = 0; i < 63; i++) values[i] = values[i + 1]; // Add the received value to the array. values[63] = val; } }
(Printable View of http://www.arduino.cc/en/Tutorial/Graph)

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

available()) { val = Serial.interaction-ivrea. the Arduino boards turns on an LED when it receives the character 'H'. OUTPUT).Show changes to markup April 11.read(). void setup() { Serial.begin(9600). or Max/MSP. The data can be sent from the Arduino serial monitor. if (val == 'H') { digitalWrite(outputPin. 2007. at 10:12 AM by David A. PD.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. int val. Code int outputPin = 13. HIGH). pinMode(outputPin. LOW). or another program like Processing (see code below). Flash (via a serial-net proxy).it/h. } void loop() { if (Serial.barragan> // Demonstrates how to send data to the Arduino I/O board. } } } Processing Code // mouseover serial // by BARRAGAN <http://people. In this case. } if (val == 'L') { digitalWrite(outputPin. Mellis Added lines 1-91: Examples > Communication Physical Pixel An example of using the Arduino board to receive data from the computer. Circuit An LED on pin 13. and turns off the LED when it receives the character 'L'.PhysicalPixel History Hide minor edits . // created 13 May 2004 . in order to // turn ON a light if the mouse is over a rectangle and turn it off // if the mouse is not.

} // if mouse is over square // change color // send an 'H' to indicate mouse is over square // change color // send an 'L' otherwise // draw square Restore Edit Page | Page History | Printable View | All Recent Site Changes . 100. 9600). 50.list()[0].import processing. 200). // List all the available serial ports in the output pane. // You will need to choose the port that the Arduino board is // connected to from this list.write('L'). 100). if(mouseOverRect()) { fill(#BBBBB0). } // function to test if mouse is over square boolean mouseOverRect() { return ((mouseX >= 50)&&(mouseX <= 150)&&(mouseY >= 50)&(mouseY <= 150)). } else { fill(#666660).list()). } void draw() { background(#222222). println(Serial.serial. port. Serial. port.*.write('H'). void setup() { size(200. Serial port. } rect(50. The first port in the list is // port #0 and the third port in the list is port #2. // Open the port that the Arduino board is connected to (in this case #0) // Make sure to open the port at the same speed Arduino is using (9600bps) port = new Serial(this. frameRate(10). noStroke().

int val. HIGH).it/h. } if (val == 'L') { digitalWrite(outputPin. noStroke(). or another program like Processing (see code below). // created 13 May 2004 import processing. The first port in the list is // port #0 and the third port in the list is port #2.barragan> // Demonstrates how to send data to the Arduino I/O board. } void loop() { if (Serial.available()) { val = Serial. // You will need to choose the port that the Arduino board is // connected to from this list. } } } Processing Code // mouseover serial // by BARRAGAN <http://people. Flash (via a serial-net proxy).list()). if (val == 'H') { digitalWrite(outputPin. frameRate(10). or Max/MSP. println(Serial. Serial port. Circuit An LED on pin 13.serial. .read(). in order to // turn ON a light if the mouse is over a rectangle and turn it off // if the mouse is not. PD. In this case. Code int outputPin = 13. 200). and turns off the LED when it receives the character 'L'. The data can be sent from the Arduino serial monitor. void setup() { Serial.Arduino : Tutorial / Physical Pixel Learning Examples | Foundations | Hacking | Links Examples > Communication Physical Pixel An example of using the Arduino board to receive data from the computer. void setup() { size(200.interaction-ivrea. // List all the available serial ports in the output pane. OUTPUT). LOW).begin(9600). pinMode(outputPin.*. the Arduino boards turns on an LED when it receives the character 'H'.

// Open the port that the Arduino board is connected to (in this case #0) // Make sure to open the port at the same speed Arduino is using (9600bps) port = new Serial(this. 50. } else { fill(#666660).cc/en/Tutorial/PhysicalPixel) . port.list()[0].write('L'). } rect(50.arduino. port. } // if mouse is over square // change color // send an 'H' to indicate mouse is over square // change color // send an 'L' otherwise // draw square (Printable View of http://www. 100).write('H'). 100. } void draw() { background(#222222). } // function to test if mouse is over square boolean mouseOverRect() { return ((mouseX >= 50)&&(mouseX <= 150)&&(mouseY >= 50)&(mouseY <= 150)). if(mouseOverRect()) { fill(#BBBBB0). 9600). Serial.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

1.begin(9600). green. Code Changed lines 33-37 from: to: @] Processing Code [@ Deleted line 50: /* Deleted line 105: / Restore January 14.VirtualColorMixer History Hide minor edits .print("G"). Circuit Potentiometers connected to analog input pins 0. Serial.print("B"). at 08:30 AM by David A. Mellis Added lines 1-92: int redPin = 0. Serial. } void loop() { Serial. and 2.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. at 07:39 AM by David A.Show changes to markup March 26. Mellis Added lines 1-12: Examples > Communication Virtual Color Mixer Demonstrates one technique for sending multiple values from the Arduino board to the computer. Serial. int greenPin = 1. .println(analogRead(bluePin)). void setup() { Serial. and blue components of the background color of a Processing sketch. the readings from three potentiometers are used to set the red. 2007. Serial. 2007.print("R"). int bluePin = 2. Serial. In this case.println(analogRead(redPin)).println(analogRead(greenPin)).

bval). } background(rval. // Discard the carriage return at the end of the buffer buff = buff.charAt(0). Serial. // Uses the first available port port = new Serial(this.com">Josh Nimoy</a>. int rval = 0. } else { // The first character tells us which color this value is for char c = buff.jtnimoy. println(Serial.*. If the // value "serial" is equal to the value for a new line. // Print a list in case COM1 doesn't work out println("Available serial ports:").delay(100).read()). } void draw() { while (port. } void serialEvent(int serial) { // If the variable "serial" is not equal to the value for // a new line.list()[0]. 9600). int NEWLINE = 10. // Remove it from the string buff = buff.substring(1). Mellis * * Created 2 December 2006 * * based on Analog In * by <a href="http://itp. // Parse the String into an integer if (c == 'R') rval = Integer. 9600). } /** * Color Mixer * by David A. gval.length()-1). 200).serial. "COM1". buff. Serial port.substring(0.available() > 0) { serialEvent(port. String buff = "". gval = 0.list()).parseInt(buff). * * Created 8 February 2003 * Updated 2 April 2005 */ /* import processing. //port = new Serial(this. // save the value of the buffer into the variable "val". add the value to the variable "buff". if(serial != NEWLINE) { buff += char(serial). void setup() { size(200. bval = 0. else if (c == 'G') .

} } */ Restore Edit Page | Page History | Printable View | All Recent Site Changes . // Clear the value of "buff" buff = "".parseInt(buff).gval = Integer. else if (c == 'B') bval = Integer.parseInt(buff).

println(Serial. Code int redPin = 0. void setup() { Serial. delay(100).Arduino : Tutorial / Virtual Color Mixer Learning Examples | Foundations | Hacking | Links Examples > Communication Virtual Color Mixer Demonstrates one technique for sending multiple values from the Arduino board to the computer.print("G"). Serial port. and blue components of the background color of a Processing sketch. Mellis * * Created 2 December 2006 * * based on Analog In * by <a href="http://itp.print("B"). int greenPin = 1. int bluePin = 2. } Processing Code /** * Color Mixer * by David A.println(analogRead(greenPin)). In this case. gval = 0. green. void setup() { size(200. Serial. } void loop() { Serial. Serial. String buff = "". // Print a list in case COM1 doesn't work out println("Available serial ports:").begin(9600). Serial. Serial. and 2. Serial. * * Created 8 February 2003 * Updated 2 April 2005 */ import processing. Circuit Potentiometers connected to analog input pins 0.println(analogRead(bluePin)).serial. . the readings from three potentiometers are used to set the red.println(analogRead(redPin)).print("R").*. 200). int rval = 0. int NEWLINE = 10. 1.com">Josh Nimoy</a>.jtnimoy.list()). bval = 0.

9600). // save the value of the buffer into the variable "val". } void draw() { while (port. add the value to the variable "buff". else if (c == 'G') gval = Integer. Serial. if(serial != NEWLINE) { buff += char(serial). // Parse the String into an integer if (c == 'R') rval = Integer.length()-1). } else { // The first character tells us which color this value is for char c = buff.//port = new Serial(this. gval. else if (c == 'B') bval = Integer.read()).cc/en/Tutorial/VirtualColorMixer) .available() > 0) { serialEvent(port. 9600).substring(1).substring(0. // Discard the carriage return at the end of the buffer buff = buff.parseInt(buff). buff. If the // value "serial" is equal to the value for a new line. // Clear the value of "buff" buff = "". // Remove it from the string buff = buff. "COM1".parseInt(buff). bval). } } (Printable View of http://www. // Uses the first available port port = new Serial(this. } background(rval.arduino.charAt(0).parseInt(buff).list()[0]. } void serialEvent(int serial) { // If the variable "serial" is not equal to the value for // a new line.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

to: if both buttons are pushed at the same time.TwoSwitchesOnePin History Hide minor edits . In this case the scheme just reports sw2 is pushed. at 08:24 PM by David A. The job of the 10K series resistor incidentally is to prevent a short circuit if a pesky user pushes both buttons at once. 2008. when the pin is set to an input. Swap the 10k * resistor to the bottom of the schematic if you want it to favor sw1. The job of the 10K series resitor is to prevent * a short circuit if pesky user pushes both buttons at once. at 07:56 PM by Paul Badger Changed line 16 from: . Restore April 08. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive. Mellis Changed line 17 from: * Read two pushbutton switches or one center-off toggle switch with one Freeduino pin to: * Read two pushbutton switches or one center-off toggle switch with one Arduino pin Restore April 08.freeduino -> arduino Changed lines 3-4 from: There are handy 20K pullup resistors (resistors connected internally between Freeduino I/O pins and VCC . It can be ommitted on a center-off slide or toggle * where states are mutually exclusive. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive.+5 volts in the Arduino's case) built into the Atmega chip upon which Freeduino's are based. The job of the 10K series resistor. They are accessible from software by using the digitalWrite() function.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. * Restore April 08. is to prevent a short circuit if a pesky user pushes both buttons at once. 2008. They are accessible from software by using the digitalWrite() function. In this case the scheme just reports that sw2 is pushed. at 07:59 PM by Paul Badger Changed lines 9-12 from: if both buttons are pushed at the same time. at 08:23 PM by David A. at 07:57 PM by Paul Badger Deleted lines 25-30: * One downside of the scheme (there always has to be a downside doesn't there?) is that you can't tell * if both buttons are pushed at the same time. to: There are handy 20K pullup resistors (resistors connected internally between Arduino I/O pins and VCC . 2008.+5 volts in the Freeduino's case) built into the Atmega chip upon which Freeduino's are based. 2008. when the pin is set to an input. incidentally. Restore April 08.Show changes to markup April 08. Mellis . In this case the scheme just reports that sw2 is pushed. 2008.

This sketch exploits the pullup resistors under software control. Restore April 08. The idea is that an external 200K resistor to ground will cause the input pin to report LOW when the internal (20K) pullup resistor is turned off. The job of the 10K series resitor incidentally is to prevent a short circuit if a pesky user pushes both buttons at once. it will overwhelm the external 200K resistor and the pin will report HIGH. In this case the scheme just reports that sw2 is pushed. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive. When the internal pullup resistor is turned on.* Read_Two_Switches_ON_One_Pin to: * Read_Two_Switches_On_One_Pin Restore April 08. when the pin is set to an input. 2008.+5 volts in the Freeduino's case). to: There are handy 20K pullup resistors (resistors connected internally between Freeduino I/O pins and VCC . They are accessible from software by using the digitalWrite() function. at 07:56 PM by Paul Badger Changed lines 9-12 from: if both buttons are pushed at the same time. It can be ommitted on a center-off slide or toggle swithc where the states are mutually exclusive. The idea is that an external 200K resistor to ground will cause the input pin to report LOW when the internal (20K) pullup resistor is turned off. Restore April 08. Restore April 08. to: if both buttons are pushed at the same time. when the pin is set to an input.+5 volts in the Freeduino's case) built into the Atmega chip upon which Freeduino's are based. It can be ommitted on a center-off slide or toggle swithc where the states are mutually exclusive. 2008. One downside of the scheme (there always has to be a downside doesn't there?) is that one can't tell if both buttons are pushed at the same time. In this case the scheme just reports that sw2 is pushed. it will overwhelm the external 200K resistor and the pin will report HIGH. 2008. In this case the scheme just reports that sw2 is pushed. The job of the 10K series resitor incidentally is to prevent a short circuit if a pesky user pushes both buttons at once. When the internal pullup resistor is turned on. They are accessible from software by using the digitalWrite() function. at 07:53 PM by Paul Badger Added lines 3-12: There are handy 20K pullup resistors (resistors connected internally between Freeduino I/O pins and VCC . at 07:43 PM by Paul Badger Added lines 1-86: Read Two Switches With One I/O Pin /* . The idea is that an external 200K resistor to ground will cause an input pin to report LOW when the internal (20K) pullup resistor is turned off. to: This sketch exploits the pullup resistors under software control. They are accessible from software by using the digitalWrite() function. at 07:55 PM by Paul Badger Changed lines 5-7 from: This sketch exploits the pullup resistors under software control. it will overwhelm the external 200K resistor and the pin will report HIGH. when the pin is set to an input. When the internal pullup resistor is turned on however. 2008.+5 volts in the Freeduino's case). The job of the 10K series resistor incidentally is to prevent a short circuit if a pesky user pushes both buttons at once. at 07:54 PM by Paul Badger Changed lines 3-4 from: There are handy 20K pullup resistors (resistors connected internally between Freeduino I/O pins and VCC . 2008. Restore April 08.

stateB. but when the pullup resistor is turned on.begin(9600). sw2. stateB = digitalRead(swPin). * it will overwhelm the 200K resistor and the pin will report HIGH. // both states HIGH .* Read_Two_Switches_ON_One_Pin * Read two pushbutton switches or one center-off toggle switch with one Freeduino pin * Paul Badger 2008 * From an idea in EDN (Electronic Design News) * * Exploits the pullup resistors available on each I/O and analog pin * The idea is that the 200K resistor to ground will cause the input pin to report LOW when the * (20K) pullup resistor is turned off. In this case the scheme just reports sw2 is pushed.note: no semicolon after #define // variables to store pin states // variables to represent switch states // make sure the puillup resistors are off // turn on the puillup resistors if ( stateA == 1 && stateB == 1 ){ sw1 = 1. void setup() { Serial. Swap the 10k * resistor to the bottom of the schematic if you want it to favor sw1. digitalWrite(swPin. LOW). * * Schematic Diagram ( can't belive I drew this funky ascii schematic ) * * * +5 V * | * \ * / * \ 10K * / * \ * | * / switch 1 or 1/2 of center-off toggle or slide switch * / * | * digital pin ________+_____________/\/\/\____________ ground * | * | 200K to 1M (not critical) * / * / switch 2 or 1/2 of center-off toggle or slide switch * | * | * _____ * ___ ground * _ * */ #define swPin 2 int stateA. stateA = digitalRead(swPin). int sw1. // pin for input . It can be ommitted on a center-off slide or toggle * where states are mutually exclusive. The job of the 10K series resitor is to prevent * a short circuit if pesky user pushes both buttons at once. * * One downside of the scheme (there always has to be a downside doesn't there?) is that you can't tell * if both buttons are pushed at the same time. } void loop() { digitalWrite(swPin. HIGH).switch 1 must be pushed .

position sw2 = 0. Serial. } Serial. } else if ( stateA == 0 && stateB == 0 ){ sw1 = 0.print(" "). } else{ sw1 = 0.or center-off toggle in middle // pad some spaces to format print output Restore Edit Page | Page History | Printable View | All Recent Site Changes . } // both states LOW . delay(100).print(sw1). sw2 = 1.sw2 = 0.println(sw2). Serial.switch 2 must be pushed // stateA HIGH and stateB LOW // no switches pushed .

sw2. is to prevent a short circuit if a pesky user pushes both buttons at once. int sw1. * it will overwhelm the 200K resistor and the pin will report HIGH. They are accessible from software by using the digitalWrite() function. but when the pullup resistor is turned on. /* * Read_Two_Switches_On_One_Pin * Read two pushbutton switches or one center-off toggle switch with one Arduino pin * Paul Badger 2008 * From an idea in EDN (Electronic Design News) * * Exploits the pullup resistors available on each I/O and analog pin * The idea is that the 200K resistor to ground will cause the input pin to report LOW when the * (20K) pullup resistor is turned off. LOW). * * Schematic Diagram ( can't belive I drew this funky ascii schematic ) * * * +5 V * | * \ * / * \ 10K * / * \ * | * / switch 1 or 1/2 of center-off toggle or slide switch * / * | * digital pin ________+_____________/\/\/\____________ ground * | * | 200K to 1M (not critical) * / * / switch 2 or 1/2 of center-off toggle or slide switch * | * | * _____ * ___ ground * _ * */ #define swPin 2 int stateA. void setup() { Serial. } void loop() { digitalWrite(swPin.begin(9600). In this case the scheme just reports that sw2 is pushed. The job of the 10K series resistor. when the pin is set to an input.+5 volts in the Arduino's case) built into the Atmega chip upon which Freeduino's are based. The idea is that an external 200K resistor to ground will cause an input pin to report LOW when the internal (20K) pullup resistor is turned off.note: no semicolon after #define // variables to store pin states // variables to represent switch states // make sure the puillup resistors are off . When the internal pullup resistor is turned on however. incidentally. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive. This sketch exploits the pullup resistors under software control. it will overwhelm the external 200K resistor and the pin will report HIGH. One downside of the scheme (there always has to be a downside doesn't there?) is that one can't tell if both buttons are pushed at the same time. stateB.Arduino : Tutorial / Two Switches One Pin Learning Examples | Foundations | Hacking | Links Read Two Switches With One I/O Pin There are handy 20K pullup resistors (resistors connected internally between Arduino I/O pins and VCC . // pin for input .

middle position sw2 = 0. } // turn on the puillup resistors // both states HIGH . delay(100). if ( stateA == 1 && stateB == 1 ){ sw1 = 1. sw2 = 0. HIGH).switch 2 must be pushed // stateA HIGH and stateB LOW // no switches pushed .print(sw1).switch 1 must be pushed // both states LOW . Serial.arduino.print(" "). } else if ( stateA == 0 && stateB == 0 ){ sw1 = 0.cc/en/Tutorial/TwoSwitchesOnePin) . sw2 = 1.println(sw2). Serial. } else{ sw1 = 0. digitalWrite(swPin. stateB = digitalRead(swPin).stateA = digitalRead(swPin). } Serial.or center-off toggle in // pad some spaces to format print output (Printable View of http://www.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Note that due to the * use of active low inputs (through a pull-up resistor) * the input is at low when the sensor is active. INPUT). Mellis Added lines 9-10: Circuit Changed lines 15-44 from: /* Tilt Sensor * ----------* * Detects if the sensor has been tilted or not and * lights up the LED if so. pinMode(inPin. int value = 0. but you'll need to make sure that the inputPin variable in the code matches the digital pin you're using on the Arduino board. but you'll need to make sure that the inputPin variable in the code matches the digital pin you're using on the Arduino board.TiltSensor History Hide minor edits . } // initializes digital pin 13 as output // initializes digital pin 7 as input // reads the value at a digital input to: Code . int inPin = 7. at 08:53 AM by David A. 2007. value). OUTPUT). Cuartielles * */ int ledPin = 13. void setup() { pinMode(ledPin.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 2007. } void loop() { value = digitalRead(inPin). digitalWrite(ledPin. * * (cleft) David Cuartielles for DojoCorp and K3 * @author: D. at 08:53 AM by David A.Show changes to markup June 12. Restore June 12. to: Use the Digital > Button example to read the tilt-sensor. Mellis Changed line 17 from: Use the 'Digital > Button example to read the tilt-sensor.

The code example is exactly as the one we would use for a pushbutton but substituting this one with the tilt sensor. The hardware was mounted and photographed by Anders Gran.com/30/65458903_d9a89442a9. OUTPUT). The prototyping board has been populated with a 1K resitor to make the pull-up and the sensor itself. which datasheet can be found here. at 06:27 AM by 193. Note that due to the * use of active low inputs (through a pull-up resistor) * the input is at low when the sensor is active. We have chosen the tilt sensor from Assemtech. We use a pull-up resistor (thus use active-low to activate the pins) and connect the sensor to a digital input pin that we will read when needed. the software comes from the basic Arduino examples. * * (cleft) David Cuartielles for DojoCorp and K3 * @author: D. by Anders Gran to: Picture of a protoboard supporting the tilt sensor. int value = 0. Cuartielles * */ int ledPin = 13. by Anders Gran /* Tilt Sensor * ----------* * Detects if the sensor has been tilted or not and * lights up the LED if so. However it is only the equivalent to a pushbutton activated through a different physical mechanism. http://static. by Anders Gran Restore January 04. Restore December 01.Use the 'Digital > Button example to read the tilt-sensor. 2006. The hardware was mounted and photographed by Anders Gran. Changed lines 11-12 from: Picture of a protoboard supporting the tilt sensor. to: The prototyping board has been populated with a 1K resitor to make the pull-up and the sensor itself. the software comes from the basic Arduino examples. the software comes from the basic Arduino examples. but you'll need to make sure that the inputPin variable in the code matches the digital pin you're using on the Arduino board. at 04:57 AM by David Cuartielles Changed lines 7-8 from: The prototyping board has been populated with a 1K resitor to make the pull-up and the sensor itself.246. The hardware was mounted and photographed by Anders Gran. void setup() { pinMode(ledPin.222. It contains a metallic ball inside that will commute the two pins of the device from on to off and viceversa if the sensor reaches a certain angle. which datasheet can be found here.jpg Picture of a protoboard supporting the tilt sensor. 2006. We have chosen the tilt sensor from Assemtech.flickr. // initializes digital pin 13 as output . We have chosen the tilt sensor from Assemtech. This type of sensor is the environmental-friendly version of a mercuryswitch.39 Added lines 1-42: Tilt Sensor The tilt sensor is a component that can detect the tilting of an object. which datasheet can be found here. int inPin = 7.

pinMode(inPin. INPUT). } // initializes digital pin 7 as input // reads the value at a digital input Restore Edit Page | Page History | Printable View | All Recent Site Changes . value). } void loop() { value = digitalRead(inPin). digitalWrite(ledPin.

It contains a metallic ball inside that will commute the two pins of the device from on to off and viceversa if the sensor reaches a certain angle. We have chosen the tilt sensor from Assemtech. However it is only the equivalent to a pushbutton activated through a different physical mechanism. which datasheet can be found here. The prototyping board has been populated with a 1K resitor to make the pull-up and the sensor itself. Circuit Picture of a protoboard supporting the tilt sensor. (Printable View of http://www. We use a pull-up resistor (thus use active-low to activate the pins) and connect the sensor to a digital input pin that we will read when needed.cc/en/Tutorial/TiltSensor) . The code example is exactly as the one we would use for a pushbutton but substituting this one with the tilt sensor. The hardware was mounted and photographed by Anders Gran.arduino. the software comes from the basic Arduino examples. but you'll need to make sure that the inputPin variable in the code matches the digital pin you're using on the Arduino board. This type of sensor is the environmental-friendly version of a mercury-switch. by Anders Gran Code Use the Digital > Button example to read the tilt-sensor.Arduino : Tutorial / Tilt Sensor Learning Examples | Foundations | Hacking | Links Tilt Sensor The tilt sensor is a component that can detect the tilting of an object.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

com/35/94946013_ba47fe116e. int ledVerde = 13.jpg Code /* Controle_LEDcirle_with_joystik * -----------* This program controles a cirle of 8 LEDs through a joystick * * First it reads two analog pins that are connected * to a joystick made of two potentiometers * * This input is interpreted as a coordinate (x. // Array of 8 leds mounted in a circle . the program always lights up the LED corresponding to the pie in which the joystick is. 2006.com/19/94946024_f7fd4b55ec.8.y) back to arduino. when the joystick gives us a coordinate.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.com/42/94946020_2a1dd30b97. To each piece will correspond an LED.y) * * Finally it ligths up the LED which is placed in the * detected zone * * @authors: Cristina Hoffmann and Gustavo Jose Valera * @hardware: Cristina Hofmann and Gustavo Jose Valera * @context: Arduino Workshop at medialamadrid */ // Declaration of Variables int ledPins [] = { 2. it will necesarilly belong to one of the pies. This circle will be from now on our 'Pie' (see bottom right of the first image). at 10:31 AM by 193. As you can see looking to the joystick is that the space in which he moves is a circle.7.ControleLEDcircleWithJoystick History Hide minor edits . the joystick gives a coordinate (x.jpg Detail of the arduino wiring http://static.y) * * The program then calculates to which of the 8 * possible zones belogns the coordinate (x.flickr.Show changes to markup February 03. http://static.4.3.5.com/39/94946015_aaab0281e8.flickr. Then.6.jpg How this works As you know from the Interfacing a Joystick tutorial.jpg Detail of the LED wiring http://static.124.9 }.flickr.flickr. (See figure below).49. This way.107 Added lines 1-163: Controlling a circle of LEDs with a Joystick The whole circuit: http://static. The only thing we need now to understand is that we have divided our Pie in 8 pieces.

centerX = 500. given the center cx. OUTPUT). joyPin2 = 1.int int int int int int int int int espera = 40.cy). int y1. y2 int calculateSlope(int x1. cy int calculateZone (int x. else return 5. coordX = 0. else return 1. for (i=0. } } else { if (y < cy) // third cuadrant { if (alpha > 1) return 4. i< 8. } // function that calculates in which of the 8 possible zones is the coordinate x y. int y. // slope of the segment betweent the point and the center if (x > cx) { if (y > cy) // first cuadrant { if (alpha > 1) // The slope is > 1. . int x2. y1 and x2. actualZone = 0. pinMode (ledVerde. previousZone = 0. centerY = 500. OUTPUT). } else // fourth cuadrant { if (alpha > -1) return 6. else return 3. // // // // // // Time you should wait for turning on the leds slider variable connecetd to analog pin 0 slider variable connecetd to analog pin 1 variable to read the value from the analog pin 0 variable to read the value from the analog pin 1 we measured the value for the center of the joystick // Asignment of the pins void setup() { int i. beginSerial(9600). // Otherwise the point is in the lower part of the first quadrant } else // second cuadrant { if (alpha > -1) return 2. int cy) { int alpha = calculateSlope(x. joyPin1 = 0. thus higher part of the first quadrant return 0. } } // function that calculates the slope of the line that passes through the points // x1.y. int cx. coordY = 0. cx. int y2) { return ((y1-y2) / (x1-x2)). i++) { pinMode(ledPins[i].

serialWrite(13). coordY. // flag to know we entered the loop. if (actualZone != previousZone) digitalWrite (ledPins[previousZone]. coordY = analogRead(joyPin2).Spain Restore Edit Page | Page History | Printable View | All Recent Site Changes . } } } void loop() { digitalWrite(ledVerde. LOW). //This is not necesary for a standalone version serialWrite('C'). digitalWrite (ledPins[actualZone]. the cartesian value of the coordinate. serialWrite(32).Madrid . centerX.else return 7. serialWrite(32). // We calculate in which x actualZone = calculateZone(coordX. and the zone where it belongs. // print space printInteger(coordX). // delay (500). HIGH). } @idea: Cristina Hoffmann and Gustavo Jose Valera @code: Cristina Hoffmann and Gustavo Jose Valera @pictures and graphics: Cristina Hoffmann @date: 20051008 . centerY). HIGH). serialWrite('Z'). // we print int the terminal. you can erase this if you want // reads the value of the variable resistors coordX = analogRead(joyPin1). // print space printInteger(coordY). // But this is necesary so. don't delete it! previousZone = actualZone. serialWrite(10). serialWrite(10). // print space printInteger(actualZone). serialWrite(13). serialWrite(32).

Arduino : Tutorial / Controle LE Dcircle With Joystick Learning Examples | Foundations | Hacking | Links Controlling a circle of LEDs with a Joystick The whole circuit: Detail of the LED wiring .

when the joystick gives us a coordinate. (See figure below). it will necesarilly belong to one of the pies.y) back to arduino. As you can see looking to the joystick is that the space in which he moves is a circle. the program always lights up the LED corresponding to the pie in which the joystick is. To each piece will correspond an LED. Then. The only thing we need now to understand is that we have divided our Pie in 8 pieces. This circle will be from now on our 'Pie' (see bottom right of the first image). This way.Detail of the arduino wiring How this works As you know from the Interfacing a Joystick tutorial. the joystick gives a coordinate (x. .

3. // slider variable connecetd to analog pin 1 coordX = 0. // slider variable connecetd to analog pin 0 joyPin2 = 1.y) * * Finally it ligths up the LED which is placed in the * detected zone * * @authors: Cristina Hoffmann and Gustavo Jose Valera * @hardware: Cristina Hofmann and Gustavo Jose Valera * @context: Arduino Workshop at medialamadrid */ // Declaration of Variables int int int int int int int int int int int ledPins [] = { 2.9 }.4.6.7. .8.y) * * The program then calculates to which of the 8 * possible zones belogns the coordinate (x. // Array of 8 leds mounted in a circle ledVerde = 13. espera = 40. actualZone = 0.5. // variable to read the value from the analog pin 1 centerX = 500. previousZone = 0. // we measured the value for the center of the joystick centerY = 500. // variable to read the value from the analog pin 0 coordY = 0. // Time you should wait for turning on the leds joyPin1 = 0.Code /* Controle_LEDcirle_with_joystik * -----------* This program controles a cirle of 8 LEDs through a joystick * * First it reads two analog pins that are connected * to a joystick made of two potentiometers * * This input is interpreted as a coordinate (x.

} } else { if (y < cy) // third cuadrant { if (alpha > 1) return 4.y. // Otherwise the point is in the lower part of the first quadrant } else // second cuadrant { if (alpha > -1) return 2. y1 and x2. } } // function that calculates the slope of the line that passes through the points // x1. centerY). y2 int calculateSlope(int x1. int x2. you can erase this if you want // reads the value of the variable resistors coordX = analogRead(joyPin1).cy). // flag to know we entered the loop.// Asignment of the pins void setup() { int i. thus higher part of the first quadrant return 0. else return 7. OUTPUT). int cx. coordY. beginSerial(9600). int y1. OUTPUT). // slope of the segment betweent the point and the center if (x > cx) { if (y > cy) // first cuadrant { if (alpha > 1) // The slope is > 1. int cy) { int alpha = calculateSlope(x. for (i=0. pinMode (ledVerde. int y. . else return 1. i< 8. } } } void loop() { digitalWrite(ledVerde. i++) { pinMode(ledPins[i]. } else // fourth cuadrant { if (alpha > -1) return 6. // We calculate in which x actualZone = calculateZone(coordX. } // function that calculates in which of the 8 possible zones is the coordinate x y. int y2) { return ((y1-y2) / (x1-x2)). coordY = analogRead(joyPin2). HIGH). cx. else return 3. given the center cx. HIGH). cy int calculateZone (int x. digitalWrite (ledPins[actualZone]. centerX. else return 5.

serialWrite(32). // print space printInteger(coordY). serialWrite(13).Spain (Printable View of http://www. serialWrite(13). serialWrite(32). LOW).arduino.cc/en/Tutorial/ControleLEDcircleWithJoystick) . //This is not necesary for a standalone version serialWrite('C').Madrid . // print space printInteger(actualZone). serialWrite(10).if (actualZone != previousZone) digitalWrite (ledPins[previousZone]. // print space printInteger(coordX). serialWrite(10). // But this is necesary so. serialWrite('Z'). serialWrite(32). } @idea: Cristina Hoffmann and Gustavo Jose Valera @code: Cristina Hoffmann and Gustavo Jose Valera @pictures and graphics: Cristina Hoffmann @date: 20051008 . // we print int the terminal. and the zone where it belongs. the cartesian value of the coordinate. // delay (500). don't delete it! previousZone = actualZone.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

to: if ( abs(checkSum . 2006. 2006.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.prevCheckSum) <= sens ) // If old and new values are // within "sens" points... 2006. and are directed at a diffusing surface (stuck in a Ping-Pong ball. or placed in a paper coffee cup with a cut-out bottom and a white plastic lid).Show changes to markup September 07. Restore September 06. at 07:59 PM by Clay Shirky Changed lines 8-9 from: If the LEDs are different colors. at 07:58 PM by Clay Shirky Changed line 1 from: [= to: [= . the colors will mix together.LEDColorMixerWith3Potentiometers History Hide minor edits . at 08:00 PM by Clay Shirky Changed lines 8-10 from: If the LEDs are different colors.. or placed in a paper coffee cup with a cut-out bottom and a white plastic lid). the colors will mix together. and are behind a diffusing surface (anything from a Ping-Pong ball to a coffee cup with a cut-out bottom and a white plastic lid). to: If the LEDs are different colors.. Restore September 06. and are directed at diffusing surface (stuck in a a Ping-Pong ball. at 07:57 AM by Clay Shirky . to: If the LEDs are different colors. 2006. and are directed at a diffusing surface (stuck in a Ping-Pong ball. at 08:02 PM by Clay Shirky Changed line 74 from: // within sens points..prevCheckSum) > sens ) // If old and new values differ // above sensitivity threshold Restore September 06. or placed in a paper coffee cup with a cut-out bottom and a white plastic lid). to: // within "sens" points. 2006..Fixed sensitivity bug Changed lines 73-74 from: if ( abs(checkSum . Restore September 06.

) Put 220 Ohm resistors in line with pots. Restore September 06. // Aggregate pot values int prevCheckSum = 0. the colors will mix together. orange. or blue-green. and Blue. 1. as it uses Serial. though you can mix with any three colors. // (Connect power to 5V and ground to analog ground) int cIn = 2. // Variables to store the input from the potentiometers int bVal = 0. // LEDs connected to digital pins 9. The mix values that create that color will be reported via serial out. // Loop counter int wait = (1000). 2006. // (Connect cathodes to digital ground) int cOut = 11. and 2 int bIn = 1. to prevent small changes in // pot values from triggering false reporting // FLAGS int PRINT = 1. Red + Blue + White would let you mix shades of red. int cVal = 0. to: from a Ping-Pong ball to a coffee cup with a cut-out bottom and a white plastic lid). Green. the colors will mix together.begin()-style communication Control 3 LEDs with 3 potentiometers If the LEDs are different colors. // Delay between most recent pot adjustment and output int checkSum = 0. // Values int aVal = 0.Added line 105: =] Restore September 06. green. // Potentiometers connected to analog pins 0. blue. the colors will mix together. When you mix a color you like. // Sensitivity theshold. Standard colors for light mixing are Red. // Set to 1 to turn on debugging output . 10 and 11 int bOut = 10. at 07:56 PM by Clay Shirky Added line 1: [= Changed line 3 from: Espresso-cup Color Mixer: to: "Coffee-cup" Color Mixer: Changed lines 9-10 from: from a Ping-Pong ball to a coffee cup with a white plastic lid). 2006. at 07:53 PM by Clay Shirky Added lines 1-103: /* Espresso-cup Color Mixer: Code for mixing and reporting PWM-mediated color Assumes Arduino 0004 or higher. // Variables for comparing values between loops int i = 0. int sens = 3. stop adjusting the pots. // Set to 1 to output values int DEBUG = 1. // Digital pin settings int aOut = 9. and purple (though no yellow. to prevent circuit from grounding out when the pots are at zero / // Analog pin settings int aIn = 0. and are behind a diffusing surface (anything from a Ping-Pong ball to a coffee cup with a white plastic lid).

{ Serial. PRINT = 0.print("\tPrint: "). bVal). Serial.. OUTPUT)..print("\t"). { if (PRINT) // . Serial. Serial.print(aVal).void setup() { pinMode(aOut. cVal = analogRead(cIn) / 4. aVal)..then print the values.. } } } Restore Edit Page | Page History | Printable View | All Recent Site Changes .print(bVal). Serial. if ( abs(checkSum . } void loop() { i += 1.println(PRINT).println(cVal).prevCheckSum) <= sens ) // If old and new values are // within sens points.and if the PRINT flag is set... Serial.print(prevCheckSum).print("A: "). // . { Serial.. OUTPUT). cVal).print("\t"). Serial.print("C: "). Serial.print(checkSum). Serial.. Serial. // Count loop aVal = analogRead(aIn) / 4. pinMode(cOut. convert to 0-255 scale // sets the digital pins as output // Open serial communication for reporting // Send new values to LEDs if (i % wait == 0) // If enough time has passed. pinMode(bOut.add up the 3 values. // Update the values if (DEBUG) // If we want debugging output as well.begin(9600). Serial. Serial.... // ... // Re-set the flag } prevCheckSum = checkSum. { checkSum = aVal+bVal+cVal.print("<=>"). analogWrite(aOut. } } else { PRINT = 1. analogWrite(cOut. analogWrite(bOut.. bVal = analogRead(bIn) / 4.print("B: "). // read input pins. Serial. OUTPUT).

// int prevCheckSum = 0. * * When you mix a color you like. // Variables to store the input from the potentiometers // Digital int aOut = int bOut = int cOut = // Values int aVal = 0. // Count loop aVal = analogRead(aIn) / 4. analogWrite(cOut. * The mix values that create that color will be reported via serial out. // Loop counter int wait = (1000). aVal). if ( abs(checkSum . pinMode(bOut. to prevent circuit from * grounding out when the pots are at zero */ // Analog int aIn = int bIn = int cIn = pin settings 0. // LEDs connected to digital pins 9. or blue-green.Arduino : Tutorial / LED Color Mixer With 3 Potentiometers Learning Examples | Foundations | Hacking | Links /* * "Coffee-cup" Color Mixer: * Code for mixing and reporting PWM-mediated color * Assumes Arduino 0004 or higher. 1. and purple (though no yellow. // // // FLAGS int PRINT = 1. cVal). // (Connect cathodes to digital ground) 11.prevCheckSum) > sens ) // If old and new values differ // above sensitivity threshold { . and Blue. stop adjusting the pots.begin()-style communication * * Control 3 LEDs with 3 potentiometers * If the LEDs are different colors. // . pin settings 9. as it uses Serial. } void loop() { i += 1. // Delay between most recent pot adjustment and output int checkSum = 0.. pinMode(cOut. to prevent small changes in pot values from triggering false reporting 1 to output values 1 to turn on debugging output // sets the digital pins as output // Open serial communication for reporting // Send new values to LEDs if (i % wait == 0) // If enough time has passed.) * * Put 220 Ohm resistors in line with pots. * * Standard colors for light mixing are Red. convert to 0-255 scale Aggregate pot values Sensitivity theshold. Green. // (Connect power to 5V and ground to analog ground) 2. Serial. green. the colors will mix together. bVal). * blue.. Red + Blue + White would let you mix shades of red. OUTPUT). int bVal = 0. though you can mix * with any three colors. int sens = 3. OUTPUT). analogWrite(bOut. and 2 1. // read input pins. or placed in a paper coffee cup with a cut-out bottom and * a white plastic lid). cVal = analogRead(cIn) / 4. analogWrite(aOut.begin(9600). int cVal = 0. // Variables for comparing values between loops int i = 0. // Set to void setup() { pinMode(aOut. OUTPUT)..add up the 3 values. bVal = analogRead(bIn) / 4. orange. and are directed at diffusing surface (stuck in a * a Ping-Pong ball.. { checkSum = aVal+bVal+cVal. // Potentiometers connected to analog pins 0. // Set to int DEBUG = 1. 10 and 11 10.

. Serial. Serial.then print the values.print(prevCheckSum). Serial.. Serial.and if the PRINT flag is set.print("A: "). } // .if (PRINT) { Serial.print("\t"). Serial. } else { PRINT = 1. { Serial. } } } (Printable View of http://www. Serial.arduino. Serial. Serial..print("C: ")...print(bVal).print("B: ").print(aVal).print("\t")..print(checkSum). // Re-set the flag } prevCheckSum = checkSum. // .. Serial. Serial. Serial.cc/en/Tutorial/LEDColorMixerWith3Potentiometers) .print("\tPrint: ").print("<=>"). PRINT = 0.println(PRINT). // Update the values if (DEBUG) // If we want debugging output as well..println(cVal).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

// store elapsed time // store elapsed time (-5 to make up for // read the button state and store // read the button state and store Restore April 21. Restore April 21. printing fractions to: * Demonstrates using millis(). 2008. switch debounce time) to: elapsedTime = millis() . at 09:45 PM by Paul Badger Changed lines 70-71 from: // routine to report elapsed time to: // routine to report elapsed time . Fix this as a coding exercise. at 07:24 AM by Paul Badger Added lines 1-105: . printing fractions Restore April 18. Restore April 18. to: buttonState = digitalRead(buttonPin). at 09:48 PM by Paul Badger Changed lines 46-48 from: // here is where you'd put code that needs to be running all the time. // check for button press to: // check for button press Restore April 21. at 09:49 PM by Paul Badger Changed lines 47-48 from: buttonState = digitalRead(buttonPin). at 07:25 AM by Paul Badger Changed lines 10-11 from: * Demonstrates using millis(). 2008. 2008.startTime.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 2008.5.Stopwatch History Hide minor edits .startTime) . 2008. pullup resistors. * making two things happen at once.Show changes to markup April 21. making two things happen at once. 2008.this breaks when delays are in single or double digits. pullup resistors. at 09:47 PM by Paul Badger Changed line 64 from: elapsedTime = (millis() .

change to suit variable to store last time LED was updated start time for stop watch elapsed time for stop watch variable used to store fractional part of time void setup() { Serial. pins default to INPUT anyway // turn on pullup resistors. /* StopWatch * Paul Badger 2008 * Demonstrates using millis(). int buttonState. // LED connected to digital pin 13 // button on pin 4 // // // // // // // // // previous value of the LED variable to store button state variable to store last button state condition for blinking . compare next time } else if (buttonState == LOW && lastButtonState == HIGH && blinking == true){ // check for a high to low transition // if true then found a new button press while clock is running . to . long previousMillis = 0. long interval = 100.startTime) . lastButtonState = buttonState. blinking = true. delay(5). long startTime . pullup resistors. } void loop() { // here is where you'd put code that needs to be running all the time. INPUT). making two things happen at once.start the clock startTime = millis().5. digitalWrite(buttonPin. other side connected to ground * LED with series resistor between pin 13 and ground */ #define ledPin 13 #define buttonPin 4 int value = LOW. // sets the digital pin as output // not really necessary. pinMode(ledPin.timer is timing blink interval .begin(9600). ground.Stopwatch A sketch that demonstrates how to do two (or more) things at once by using millis(). // store elapsed time (-5 to make up for // // // // store the start time turn on blinking while timing short delay to debounce switch store buttonState in lastButtonState. OUTPUT). int blinking. long elapsedTime .stop the clock and report elapsedTime = (millis() . int lastButtonState. HIGH). Wire button so that press shorts pin to // read the button state and store if (buttonState == LOW && lastButtonState == HIGH && blinking == false){ // check for a high to low transition // if true then found a new button press while clock is not running . pinMode(buttonPin. printing fractions * * Physical setup: momentary switch connected to pin 4. int fractional. // check for button press buttonState = digitalRead(buttonPin).

if ( (millis() . LOW). lastButtonState = buttonState. } else{ digitalWrite(ledPin. value). cast to an int to print Serial.").then // print decimal point // use modulo operator to get fractional part // print fractional part of time // store buttonState in lastButtonState.previousMillis > interval) ) { if (blinking == true){ previousMillis = millis(). to blink routine . } } } // remember the last time we blinked the LED // turn off LED when not blinking Restore Edit Page | Page History | Printable View | All Recent Site Changes .println(fractional). } else{ lastButtonState = buttonState. all done timing // store buttonState in lastButtonState. that is.blink the LED while timing check to see if it's time to blink the LED.switch debounce time) blinking = false. compare next time } // // // // // divide by 1000 to convert to seconds . else value = LOW. compare next time // turn off blinking. // if the LED is off turn it on and vice-versa. if (value == LOW) value = HIGH.print( (int)(elapsedTime / 1000L) ). fractional = (int)(elapsedTime % 1000L). of time Serial. to // routine to report elapsed time Serial. is the difference between the current time and last time we blinked the LED bigger than the interval at which we want to blink the LED. digitalWrite(ledPin.print(".

blinking = true. Fix this as a coding exercise. } void loop() { // check for button press buttonState = digitalRead(buttonPin). long previousMillis = 0. int lastButtonState. lastButtonState. lastButtonState = buttonState. blinking = false.stop the clock and report elapsedTime = millis() .timer is timing blink interval . delay(5). // sets the digital pin as output // not really necessary. to compare next time } else if (buttonState == LOW && lastButtonState == HIGH && blinking == true){ // check for a high to low transition // if true then found a new button press while clock is running . int blinking. pins default to INPUT anyway // turn on pullup resistors. lastButtonState. timing lastButtonState = buttonState. * making two things happen at once. . /* StopWatch * Paul Badger 2008 * Demonstrates using millis(). Wire button so that press shorts // read the button state and store if (buttonState == LOW && lastButtonState == HIGH && blinking == false){ // check for a high to low transition // if true then found a new button press while clock is not running .change to suit variable to store last time LED was updated start time for stop watch elapsed time for stop watch variable used to store fractional part of time void setup() { Serial.begin(9600).Arduino : Tutorial / Stopwatch Learning Examples | Foundations | Hacking | Links Stopwatch A sketch that demonstrates how to do two (or more) things at once by using millis().this breaks when delays are in single or double digits. pinMode(buttonPin. // LED connected to digital pin 13 // button on pin 4 // // // // // // // // // previous value of the LED variable to store button state variable to store last button state condition for blinking .start the clock startTime = millis(). long interval = 100. int fractional. HIGH). pinMode(ledPin. pullup resistors. INPUT). digitalWrite(buttonPin. OUTPUT). long elapsedTime . other side connected to ground * LED with series resistor between pin 13 and ground */ #define ledPin 13 #define buttonPin 4 int value = LOW. to compare next time // store buttonState in // store elapsed time // turn off blinking. all done // // // // store the start time turn on blinking while timing short delay to debounce switch store buttonState in // routine to report elapsed time . long startTime . printing fractions * * Physical setup: momentary switch connected to pin 4. pin to ground. int buttonState.startTime.

lastButtonState. that is.print( (int)(elapsedTime / 1000L) ). } } } (Printable View of http://www.then cast to an int to print Serial.blink the LED while timing check to see if it's time to blink the LED.cc/en/Tutorial/Stopwatch) // remember the last time we blinked // turn off LED when not blinking .arduino. fractional part of time Serial. value). to compare next time } // // // // // divide by 1000 to convert to // print decimal point // use modulo operator to get // print fractional part of time // store buttonState in blink routine .print(". is the difference between the current time and last time we blinked the LED bigger than the interval at which we want to blink the LED."). } else{ digitalWrite(ledPin.previousMillis > interval) ) { if (blinking == true){ previousMillis = millis(). fractional = (int)(elapsedTime % 1000L). } else{ lastButtonState = buttonState. if (value == LOW) value = HIGH. LOW).println(fractional). the LED // if the LED is off turn it on and vice-versa. else value = LOW. if ( (millis() . seconds . digitalWrite(ledPin.Serial.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

The pins used are designed to be easily compatible with the breakout boards from Sparkfun. ADXL321. Restore July 02. ADXL320. The acceleration on each axis is output as an analog voltage between 0 and 5 volts. at 01:57 PM by David A. Mellis Changed lines 62-63 from: Here are some accelerometer readings from the y-axis of an ADXL322 2g accelerometer. Mellis Changed lines 5-6 from: Reads an Analog Devices ADXL3xx series (e. at 01:52 PM by David A. 2008.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. ADXL330) accelerometer and communicates the acceleration to the computer.g. Mellis Changed lines 1-2 from: Examples > Devices to: Examples > Analog I/O Restore July 02. The pins used are designed to be easily compatible with the breakout boards from Sparkfun. ADXL321.g. 2008.g. ADXL321. but will vary based on the sensitivity of the device. to: Reads an Analog Devices ADXL3xx series (e. The acceleration on each axis is output as an analog voltage between 0 and 5 volts. to: Here are some accelerometer readings collected by the positioning the y-axis of an ADXL322 2g accelerometer at various angles from ground. which is read by an analog input on the Arduino.e. ADXL330) accelerometer and communicates the acceleration to the computer. which is read by an analog input on the Arduino. 2008. 2008.g. at 01:58 PM by David A. but values at other angles will be different for a different accelerometer (e. but will vary based on the sensitivity of the device. which is read by an analog input on the Arduino. ADXL320. at 02:07 PM by David A. the accelerometer reading should be around 512. ADXL322. ADXL320. With the axis horizontal (i. to: Reads an Analog Devices ADXL3xx series (e. ADXL322. Mellis Changed lines 5-6 from: Reads an Analog Devices ADXL3xx series (e. The ADXL3xx outputs the acceleration on each axis as an analog voltage between 0 and 5 volts. Restore July 02.Show changes to markup July 02. ADXL330) accelerometer and communicates the acceleration to the computer. ADXL320. ADXL322.g. the ADXL302 5g one). ADXL330) accelerometer and communicates the acceleration to the computer. Mellis - . Values should be the same for the other axes. 2008. Restore July 02. at 01:49 PM by David A.ADXL3xx History Hide minor edits . The pins used are designed to be easily compatible with the breakout boards from Sparkfun. parallel to ground or 0°). ADXL322. ADXL321. The pins used are designed to be easily compatible with the breakout boards from Sparkfun. Values should be the same for the other axes.

Changed line 64 from: to: Restore July 02. Mellis - PM by David A. at 01:40 Changed line 13 from: to: Changed line 17 from: to: Restore July 02. 2008. Mellis - PM by David A. if you're using just the accelerometer: Restore July 02. Mellis Changed line 21 from: to: Restore July 02. 2008. at 01:42 PM by David A. Changed lines 14-21 from: Accelerometer Pin Arduino Pin Self-Test Z-Axis Analog Input 0 Analog Input 1 . 2008. but will vary based on the sensitivity of the device. Mellis Changed lines 58-66 from: @] to: @] Data Here are some accelerometer readings from the y-axis of an ADXL322 2g accelerometer. Mellis - PM by David A. at 01:43 PM by David A. Angle -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 Acceleration 662 660 654 642 628 610 589 563 537 510 485 455 433 408 390 374 363 357 355 Restore July 02. at 01:40 Changed line 13 from: to: Restore July 02. 2008. at 01:40 Changed line 17 from: to: Restore July 02. 2008. at 01:49 PM by David A. at 01:43 PM by David A. Mellis - PM by David A. Mellis Added lines 13-14: Pinout for the above configuration: Added lines 19-20: Or. 2008. Values should be the same for the other axes. Mellis - An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino. at 01:41 Changed line 13 from: to: Changed line 17 from: to: Restore July 02. 2008. 2008. Mellis Changed line 15 from: to: Restore July 02. 2008. at 01:40 Added lines 11-12: PM by David A.

Mellis Added line 11: Restore July 02. Circuit . 2008. The pins used are designed to be easily compatible with the breakout boards from Sparkfun.Y-Axis X-Axis Ground VDD to: Analog Input 2 Analog Input 3 Analog Input 4 Analog Input 5 Breakout Board Pin Self-Test Z-Axis Y-Axis X-Axis Ground VDD 1 ZOut 2 3 YOut 4 5 XOut Ground VDD 5V Arduino Analog Input Pin 0 ADXL3xx Pin Self-Test Arduino Pin None (unconnected) Analog Input 1 Analog Input 2 Analog Input 3 GND Restore July 02. at 01:32 PM by David A. ADXL330) accelerometer and communicates the acceleration to the computer. ADXL321. ADXL322. at 01:33 PM by David A.g. 2008. Mellis Added lines 1-52: Examples > Devices ADXL3xx Accelerometer Reads an Analog Devices ADXL3xx series (e. 2008. at 01:33 PM by David A. Mellis Changed lines 11-18 from: Accelerometer Pin Arduino Pin Self-Test Z-Axis Y-Axis X-Axis Ground VDD to: Accelerometer Pin Arduino Pin Self-Test Z-Axis Y-Axis X-Axis Ground VDD Analog Input 0 Analog Input 1 Analog Input 2 Analog Input 3 Analog Input 4 Analog Input 5 Analog Input 0 Analog Input 1 Analog Input 2 Analog Input 3 Analog Input 4 Analog Input 5 Restore July 02. ADXL320.

// // // // // analog analog x-axis y-axis z-axis input pin 4 input pin 5 of the accelerometer (only on 3-axis models) void setup() { Serial. This makes it possible to directly connect the // breakout board to the Arduino.print(analogRead(xpin)). } void loop() { Serial. } . digitalWrite(groundPin. LOW). OUTPUT). Serial. OUTPUT).print(analogRead(zpin)). powerpin = 19. pinMode(groundPin.print(analogRead(ypin)). If you use the normal 5V and // GND pins on the Arduino. zpin = 1. delay(1000).print(" "). Serial. Serial.println(). Serial. you can remove these lines. digitalWrite(powerPin.Accelerometer Pin Arduino Pin Self-Test Z-Axis Y-Axis X-Axis Ground VDD Analog Input 0 Analog Input 1 Analog Input 2 Analog Input 3 Analog Input 4 Analog Input 5 Code int int int int int groundpin = 18. ypin = 2. xpin = 3.begin(9600). pinMode(powerPin. Serial.print(" "). HIGH). // Provide ground and power by using the analog inputs as normal // digital pins.

Restore Edit Page | Page History | Printable View | All Recent Site Changes .

Circuit An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino. Pinout for the above configuration: Breakout Board Pin Self-Test Z-Axis Y-Axis X-Axis Ground VDD 1 2 3 4 5 Arduino Analog Input Pin 0 Or. ADXL320.g. which is read by an analog input on the Arduino. The pins used are designed to be easily compatible with the breakout boards from Sparkfun. The ADXL3xx outputs the acceleration on each axis as an analog voltage between 0 and 5 volts. powerpin = 19. xpin = 3. ADXL321. ypin = 2. zpin = 1.Arduino : Tutorial / ADX L3xx Learning Examples | Foundations | Hacking | Links Examples > Analog I/O ADXL3xx Accelerometer Reads an Analog Devices ADXL3xx series (e. // // // // // analog analog x-axis y-axis z-axis input pin 4 input pin 5 of the accelerometer (only on 3-axis models) void setup() . ADXL322. ADXL330) accelerometer and communicates the acceleration to the computer. if you're using just the accelerometer: ADXL3xx Pin Self-Test Arduino Pin ZOut YOut XOut Ground VDD 5V None (unconnected) Analog Input 1 Analog Input 2 Analog Input 3 GND Code int int int int int groundpin = 18.

OUTPUT).{ Serial. } void loop() { Serial. pinMode(groundPin.print(" "). With the axis horizontal (i. If you use the normal 5V and // GND pins on the Arduino. Serial. Serial. but will vary based on the sensitivity of the device. digitalWrite(powerPin. parallel to ground or 0°).g. Serial.begin(9600).print(" ").print(analogRead(xpin)). OUTPUT). delay(1000).arduino. you can remove these lines. but values at other angles will be different for a different accelerometer (e.print(analogRead(zpin)). // Provide ground and power by using the analog inputs as normal // digital pins. This makes it possible to directly connect the // breakout board to the Arduino.e. the accelerometer reading should be around 512.println(). digitalWrite(groundPin. } Data Here are some accelerometer readings collected by the positioning the y-axis of an ADXL322 2g accelerometer at various angles from ground. LOW).print(analogRead(ypin)).cc/en/Tutorial/ADXL3xx) . Values should be the same for the other axes. pinMode(powerPin. the ADXL302 5g one). Angle -90 -80 -70 -60 -50 -40 -30 -20 -10 0 10 20 30 40 50 60 70 80 90 Acceleration 662 660 654 642 628 610 589 563 537 510 485 455 433 408 390 374 363 357 355 (Printable View of http://www. Serial. Serial. HIGH).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

at 09:57 AM by 195. When making very accurate measurements.229. but the installation on the board allows to embed the whole circutry in a much smaller housing.112 Changed line 115 from: Here the code is exactly the same as before.178. Restore November 21.229. 2005. at 09:50 AM by 195. the sensor counts with a temperature pin that can be used to compensate possible errors. 2005. When making very accurate measurements. picture by Anders Gran to: Protoboard with an Accelerometer.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. to: Here the code is exactly the same as before (changing the input pins to be 2 and 3). Restore November 21. at 09:52 AM by 195.229. at 04:58 AM by David Cuartielles Changed lines 11-12 from: Protoboard with an Accelerometer.178.229. Marcos Yarza added two 220Ohm resistors to the pins coming out of the accelerometer. The board chosen for this small circuit is just a piece of prototyping board. 2005.112 Added lines 13-14: The following example is an adaptation of the previous one.178. Restore November 21. at 09:52 AM by 195.112 Deleted lines 12-13: The following example is an adaptation of the previous one.229. 2005. picture by Anders Gran Restore November 21. at 10:26 AM by 195. Changed lines 108-114 from: . Restore November 21. 2006.Show changes to markup December 01.112 Changed lines 3-4 from: The Memsic 2125 is a dual axis accelerometer sensor from Parallax able of measuring up to acceleration in the range of 2g.178.AccelerometerMemsic2125 History Hide minor edits . The board chosen for this small circuit is just a piece of prototyping board. the sensor counts with a temperature pin that can be used to compensate possible errors. 2005. but the installation on the board allows to embed the whole circutry in a much smaller housing.112 Added line 115: Here the code is exactly the same as before. Marcos Yarza added two 220Ohm resistors to the pins coming out of the accelerometer.178. but the installation on the board allows to embed the whole circutry in a much smaller housing. to: The Memsic 2125 is a dual axis accelerometer sensor from Parallax able of measuring up to a 2g acceleration.

at 07:30 AM by 195.178. who is Arduino's accelerometer technology researcher. The board is connected minimally. to: printByte('Y'). The board is connected minimally. Spain. leaving the temperature pin open.112 Changed lines 7-8 from: The example shown here was mounted by Anders Grant. Spain. to: The example shown here was mounted by Anders Grant. The board is connected minimally.229.229.178. while the software was created by Marcos Yarza. to: printByte('X'). leaving the temperature pin open.112 Changed lines 7-8 from: The example shown here was mounted by Anders Grant. at the University of Zaragoza. Changed line 92 from: serialWrite('Y'). who is Arduino's accelerometer technology researcher. Yarza The following example is an adaptation of the previous one. Changed line 94 from: serialWrite(sign).=] to: =] http://static. who is Arduino's accelerometer technology researcher. Changed lines 11-12 from: Protoboard with an Accelerometer. Restore November 21. Spain. to: The example shown here was mounted by Anders Gran. 2005. picture by Anders Gran Restore November 21. leaving the temperature pin open. only the two axis are plugged to the board. 2005.jpg Accelerometer mounted on prototyping board. at the University of Zaragoza. to: printByte(sign). at 07:32 AM by 195. Spain. while the software was created by Marcos Yarza.178. at 07:31 AM by 195. 2005.flickr.112 Changed line 89 from: serialWrite('X'). only the two axis pins are plugged to the board. Marcos Yarza added two 220Ohm resistors to the pins coming out of the accelerometer. only the two axis pins are plugged to the board. The board chosen for this small circuit is just a piece of prototyping board. . Restore November 21. only the two axis pins are plugged to the board.com/28/65531406_d7150f954a. at the University of Zaragoza. while the software was created by Marcos Yarza.229. while the software was created by Marcos Yarza. who is Arduino's accelerometer technology researcher. by M. at the University of Zaragoza. picture by Anders Grant to: Protoboard with an Accelerometer. leaving the temperature pin open. The board is connected minimally.

178. 1:1 Scale */ int ledPin = 13. int count = 0. void setup() { beginSerial(9600). OUTPUT). http://static. to: printByte(' '). When making very accurate measurements. picture by Anders Grant /* Accelerometer Sensor * -------------------* * Reads an 2-D accelerometer * attached to a couple of digital inputs and * sends their values over the serial port.229.jpg Protoboard with an Accelerometer.Sweden * @author: Marcos Yarza * @hardware: Marcos Yarza * @project: SMEE . makes * the monitor LED blink once sent * * * http://www.Malmo University . int xaccPin = 7.com/30/65458902_f4f2898ed9.Experiential Vehicles * @sponsor: Experiments in Art and Technology Sweden. who is Arduino's accelerometer technology researcher. at the University of Zaragoza. // Sets the baud rate to 9600 pinMode(ledPin. } /* (int) Operate Acceleration * function to calculate acceleration * returns an integer . The board is connected minimally. int yaccPin = 6.org * copyleft 2005 K3 .0j0. The pins dedicated to measure acceleration can be connected directly to digital inputs to the Arduino board. 2005. The example shown here was mounted by Anders Grant.flickr.112 Added lines 1-106: Memsic 2125 Accelerometer The Memsic 2125 is a dual axis accelerometer sensor from Parallax able of measuring up to acceleration in the range of 2g. int accel = 0. while the software was created by Marcos Yarza. leaving the temperature pin open. INPUT). Restore November 21. pinMode(yaccPin. int timer = 0. at 07:29 AM by 195.Changed lines 96-97 from: serialWrite(' '). only the two axis are plugged to the board. pinMode(xaccPin. The acceleration pins send the signals back to the computer in the form of pulses which width represents the acceleration. char sign = ' '. while the the temperature should be taken as an analog input. int value = 0. Spain. the sensor counts with a temperature pin that can be used to compensate possible errors. INPUT).

} if (timer < 5000){ sign = '-'. count = count + 1. } serialWrite(sign). } else { serialWrite('Y'). } //determine the value accel = operateAcceleration(timer). value = digitalRead(axe).500)). //reads and represents acceleration Y digitalWrite(ledPin. count = 0. while(value == HIGH) { // Loop until pin reads a low value = digitalRead(axe). } timer = count * 18. } Restore Edit Page | Page History | Printable View | All Recent Site Changes . } /* (void) readAccelerometer * procedure to read the sensor. //Represent acceleration over serial port if (axe == 7){ serialWrite('X'). digitalWrite(ledPin. //calculate the teme in miliseconds //operate sign if (timer > 5000){ sign = '+'.*/ int operateAcceleration(int time1) { return abs(8 * (time1 / 10 . } while(value == LOW) { // Loop until pin reads a high value = digitalRead(axe). LOW). printInteger(accel). } void loop() { readAcceleration(xaccPin). //reads and represents acceleration X readAcceleration(yaccPin). HIGH). } while(value == HIGH) { // Loop until pin reads a low and count value = digitalRead(axe). delay(300). serialWrite(' '). calculate * acceleration and represent the value */ void readAcceleration(int axe){ timer = 0.

org * copyleft 2005 K3 . Spain. only the two axis pins are plugged to the board. The acceleration pins send the signals back to the computer in the form of pulses which width represents the acceleration. while the software was created by Marcos Yarza. while the the temperature should be taken as an analog input. picture by Anders Gran /* Accelerometer Sensor * -------------------* * Reads an 2-D accelerometer * attached to a couple of digital inputs and * sends their values over the serial port. 1:1 Scale */ int ledPin = 13.Sweden * @author: Marcos Yarza * @hardware: Marcos Yarza * @project: SMEE . makes * the monitor LED blink once sent * * * http://www. leaving the temperature pin open. The pins dedicated to measure acceleration can be connected directly to digital inputs to the Arduino board. int xaccPin = 7.Arduino : Tutorial / Accelerometer Memsic 2125 Learning Examples | Foundations | Hacking | Links Memsic 2125 Accelerometer The Memsic 2125 is a dual axis accelerometer sensor from Parallax able of measuring up to a 2g acceleration.Experiential Vehicles * @sponsor: Experiments in Art and Technology Sweden. The board is connected minimally.Malmo University . The example shown here was mounted by Anders Gran.0j0. When making very accurate measurements. Protoboard with an Accelerometer. . the sensor counts with a temperature pin that can be used to compensate possible errors. at the University of Zaragoza. who is Arduino's accelerometer technology researcher.

} . printByte(' '). } while(value == LOW) { // Loop until pin reads a high value = digitalRead(axe). } /* (void) readAccelerometer * procedure to read the sensor. // Sets the baud rate to 9600 pinMode(ledPin. //Represent acceleration over serial port if (axe == 7){ printByte('X'). } else { printByte('Y'). INPUT). count = count + 1. INPUT). pinMode(yaccPin. LOW). } void loop() { readAcceleration(xaccPin). int timer = 0. 0. value = digitalRead(axe). OUTPUT). void setup() { beginSerial(9600). } while(value == HIGH) { // Loop until pin reads a low and count value = digitalRead(axe). ' '. printInteger(accel). calculate * acceleration and represent the value */ void readAcceleration(int axe){ timer = 0. } if (timer < 5000){ sign = '-'. 0. //calculate the teme in miliseconds //operate sign if (timer > 5000){ sign = '+'. //reads and represents acceleration Y digitalWrite(ledPin. } /* (int) Operate Acceleration * function to calculate acceleration * returns an integer */ int operateAcceleration(int time1) { return abs(8 * (time1 / 10 . } printByte(sign).500)). int count = 0. delay(300). //reads and represents acceleration X readAcceleration(yaccPin). count = 0. } timer = count * 18.int yaccPin int value = int accel = char sign = = 6. while(value == HIGH) { // Loop until pin reads a low value = digitalRead(axe). pinMode(xaccPin. } //determine the value accel = operateAcceleration(timer). digitalWrite(ledPin. HIGH).

Yarza The following example is an adaptation of the previous one.Accelerometer mounted on prototyping board. The board chosen for this small circuit is just a piece of prototyping board. (Printable View of http://www.arduino. but the installation on the board allows to embed the whole circutry in a much smaller housing.cc/en/Tutorial/AccelerometerMemsic2125) . Here the code is exactly the same as before (changing the input pins to be 2 and 3). Marcos Yarza added two 220Ohm resistors to the pins coming out of the accelerometer. by M.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

// LED connected to digital pin 13 to: int ultrasoundValue = 0. The width of that pulse will determine the distance to the object.33. // LED connected to digital pin 13 Deleted line 19: Deleted line 20: Deleted line 21: Changed lines 25-31 from: timecount = 0.112 Added lines 1-12: PING range finder The PING range finder is an ultrasound sensor from Parallax able of detecting objects up to a 3 mts distance.jpg Ultrasound sensor connected to an Arduino USB v1.178.141. int timecount = 0.UltrasoundSensor History Hide minor edits . while the software was created by David Cuartielles. // Switch signalpin to output to: . The pin dedicated to make the readings has to be shifting configuration from input to output according to the PING specification sheet.229.194 Added line 1: [= Changed lines 12-13 from: int ultraSoundSignal = 7. 2005. The example shown here was mounted by Marcus Hannerstig. pinMode(ultraSoundSignal. // Ultrasound signal pin Changed lines 15-21 from: int ultrasoundValue = 0. while the third one is used both as input and output. two are dedicated to power and ground. First we have to send a pulse that will make the sensor send an ultrasound tone and wait for an echo. The sensor counts with 3 pins.0 Restore October 10.flickr. // Echo counter int ledPin = 13. int timecount = 0. OUTPUT). http://static.Show changes to markup November 21. the sensor will send a pulse over the same pin as earlier. The board is connected as explained using only wires coming from an old computer. at 12:31 PM by 81. // Echo counter int ledPin = 13.com/31/65531405_fa57b9ff66. 2005.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. val = 0. // Ultrasound signal pin to: int ultraSoundSignal = 7. at 10:24 AM by 195. Once the tone is received back.

// Example identifier for the sensor to: ultrasoundValue = timecount. LOW). // Append signal value to val while(val == LOW) { // Loop until pin reads a high value Deleted line 46: Changed lines 49-50 from: while(val == HIGH) { // Loop until pin reads a high value to: while(val == HIGH) { // Loop until pin reads a high value Deleted line 50: Deleted line 51: Deleted line 54: Deleted line 55: Changed lines 58-61 from: ultrasoundValue = timecount. HIGH). // Wait for 5 microseconds digitalWrite(ultraSoundSignal. LOW). // Switch signalpin to input val = digitalRead(ultraSoundSignal). HIGH). // Holdoff Deleted line 39: Deleted line 40: Changed lines 43-48 from: pinMode(ultraSoundSignal. // Send low pulse delayMicroseconds(2). // Switch signalpin to input val = digitalRead(ultraSoundSignal). // Example identifier for the sensor Deleted line 61: Deleted line 62: Deleted line 65: Deleted line 66: Deleted line 69: Changed lines 71-74 from: } . LOW). // Wait for 5 microseconds digitalWrite(ultraSoundSignal. val = 0. // Send low pulse delayMicroseconds(2). // Holdoff to: digitalWrite(ultraSoundSignal. INPUT). // Send high pulse delayMicroseconds(5). OUTPUT). // Send high pulse delayMicroseconds(5). // Switch signalpin to output Deleted line 29: Deleted line 30: Changed lines 33-42 from: digitalWrite(ultraSoundSignal.timecount = 0. // Wait for 2 microseconds digitalWrite(ultraSoundSignal. // Append echo pulse time to ultrasoundValue serialWrite('A'). INPUT). // Append echo pulse time to ultrasoundValue serialWrite('A'). LOW). // Wait for 2 microseconds digitalWrite(ultraSoundSignal. // Append signal value to val while(val == LOW) { // Loop until pin reads a high value to: pinMode(ultraSoundSignal. pinMode(ultraSoundSignal.

OUTPUT). // Holdoff /* Listening for echo pulse // Sets the baud rate to 9600 // Sets the digital pin as output . } void loop() { timecount = 0. * * http://www. at 03:58 AM by 62.97.121. int timecount = 0. // Echo counter int ledPin = 13. HIGH).se | http://www.xlab. LOW). // Send high pulse delayMicroseconds(5). val = 0.0j0. 2005.to: } Deleted line 73: Deleted line 74: Changed lines 78-79 from: } to: } =] Restore October 08. // Send low pulse delayMicroseconds(2). // Ultrasound signal pin int val = 0. // LED connected to digital pin 13 void setup() { beginSerial(9600). pinMode(ledPin. // Switch signalpin to output /* Send low-high-low pulse to activate the trigger pulse of the sensor * ------------------------------------------------------------------*/ digitalWrite(ultraSoundSignal. int ultrasoundValue = 0.org * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp * */ int ultraSoundSignal = 7. pinMode(ultraSoundSignal. LOW).93 Added lines 1-114: /* Ultrasound Sensor *-----------------* * Reads values (00014-01199) from an ultrasound sensor (3m sensor) * and writes the values to the serialport. // Wait for 2 microseconds digitalWrite(ultraSoundSignal. OUTPUT). // Wait for 5 microseconds digitalWrite(ultraSoundSignal.

} Restore // Count echo pulse time Edit Page | Page History | Printable View | All Recent Site Changes . } /* Writing out values to the serial port * ------------------------------------------------------------------*/ ultrasoundValue = timecount. serialWrite(13). HIGH). } /* Delay of program * ------------------------------------------------------------------*/ delay(100). serialWrite(10). // Switch signalpin to input val = digitalRead(ultraSoundSignal). // Append echo pulse time to ultrasoundValue serialWrite('A'). /* Lite up LED if any value is passed by the echo pulse * ------------------------------------------------------------------*/ if(timecount > 0){ digitalWrite(ledPin. } while(val == HIGH) { // Loop until pin reads a high value val = digitalRead(ultraSoundSignal).* ------------------------------------------------------------------*/ pinMode(ultraSoundSignal. timecount = timecount +1. INPUT). // Append signal value to val while(val == LOW) { // Loop until pin reads a high value val = digitalRead(ultraSoundSignal). // Example identifier for the sensor printInteger(ultrasoundValue).

The sensor counts with 3 pins.org * copyleft 2005 Mackie for XLAB | DojoDave for DojoCorp * */ int int int int int ultraSoundSignal = 7. // Echo counter ledPin = 13. Ultrasound sensor connected to an Arduino USB v1.0j0. The pin dedicated to make the readings has to be shifting configuration from input to output according to the PING specification sheet. The board is connected as explained using only wires coming from an old computer. The example shown here was mounted by Marcus Hannerstig. timecount = 0. // Ultrasound signal pin val = 0.se | http://www. ultrasoundValue = 0. while the software was created by David Cuartielles. the sensor will send a pulse over the same pin as earlier. * * http://www. .Arduino : Tutorial / Ultrasound Sensor Learning Examples | Foundations | Hacking | Links PING range finder The PING range finder is an ultrasound sensor from Parallax able of detecting objects up to a 3 mts distance. two are dedicated to power and ground.0 /* Ultrasound Sensor *-----------------* * Reads values (00014-01199) from an ultrasound sensor (3m sensor) * and writes the values to the serialport. // LED connected to digital pin 13 // Sets the baud rate to 9600 void setup() { beginSerial(9600).xlab. while the third one is used both as input and output. The width of that pulse will determine the distance to the object. First we have to send a pulse that will make the sensor send an ultrasound tone and wait for an echo. Once the tone is received back.

// Wait for 2 microseconds digitalWrite(ultraSoundSignal. INPUT). // Switch signalpin to input val = digitalRead(ultraSoundSignal). // Send high pulse delayMicroseconds(5). } // Sets the digital pin as output void loop() { timecount = 0. /* Lite up LED if any value is passed by the echo pulse * ------------------------------------------------------------------*/ if(timecount > 0){ digitalWrite(ledPin. OUTPUT).arduino. // Count echo pulse time } /* Writing out values to the serial port * ------------------------------------------------------------------*/ ultrasoundValue = timecount. // Holdoff /* Listening for echo pulse * ------------------------------------------------------------------*/ pinMode(ultraSoundSignal. pinMode(ultraSoundSignal. // Wait for 5 microseconds digitalWrite(ultraSoundSignal. LOW). timecount = timecount +1. OUTPUT). } /* Delay of program * ------------------------------------------------------------------*/ delay(100). LOW). val = 0. // Example identifier for the sensor printInteger(ultrasoundValue). // Switch signalpin to output /* Send low-high-low pulse to activate the trigger pulse of the sensor * ------------------------------------------------------------------*/ digitalWrite(ultraSoundSignal.cc/en/Tutorial/UltrasoundSensor) . // Append echo pulse time to ultrasoundValue serialWrite('A'). HIGH). serialWrite(13). HIGH). } (Printable View of http://www.pinMode(ledPin. // Send low pulse delayMicroseconds(2). serialWrite(10). // Append signal value to val while(val == LOW) { // Loop until pin reads a high value val = digitalRead(ultraSoundSignal). } while(val == HIGH) { // Loop until pin reads a high value val = digitalRead(ultraSoundSignal).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

com is a linear capacitive sensor * that is able to read the position of a finger touching the sensor * the surface of the sensor is divided in 128 positions * the pin qt401_prx detects when a hand is near the sensor while * qt401_det determines when somebody is actually touching the sensor * these can be left unconnected if you are short of pins * * read the datasheet to understand the parametres passed to initialise the sensor * * Created January 2006 * Massimo Banzi http://www. OUTPUT). // = 7.Qt401 History Hide minor edits .qprox. // = 3.Show changes to markup January 19. INPUT).18. pinMode(qt401_clk. INPUT). at 06:19 AM by 85. // = 6.org * * based on C code written by Nicholas Zambetti */ // define pin int qt401_drd int qt401_di int qt401_ss int qt401_clk int qt401_do int qt401_det int qt401_prx mapping = 2. void qt401_init() { // define pin directions pinMode(qt401_drd. at 06:19 AM by 85.potemkin.18. . // = 4. // = 5.162 Added lines 1-195: /* qt401 demo * -----------* * the qt401 from qprox http://www. pinMode(qt401_ss. INPUT).81. 2006.81. INPUT). pinMode(qt401_di. 2006. OUTPUT). // = 8. pinMode(qt401 prx.162 Added lines 1-5: qt401 sensor full tutorial coming soon Restore January 19. // data ready data in (from sensor) slave select clock data out (to sensor) detect proximity byte result. OUTPUT).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. pinMode(qt401_do. pinMode(qt401_det.

LOW). } // // wait for the qt401 to be ready // void qt401_waitForReady(void) { while(!digitalRead(qt401_drd)){ continue. digitalWrite(qt401_ss. HIGH). } } // // // exchange a byte with the sensor byte qt401_transfer(byte data_out) { byte i = 8.// initialise pins digitalWrite(qt401_clk. // send 1 } else{ digitalWrite(qt401_do. digitalWrite(qt401_ss. byte data_in = 0.HIGH). this tells the sensor to read the bit we just put out digitalWrite(qt401_clk. //wait for 75 microseconds while(0 < i) { mask = 0x01 << --i. // tick // give the sensor time to read the data delayMicroseconds(75). // bring clock back up digitalWrite(qt401_clk.LOW). // select slave by lowering ss pin delayMicroseconds(75). byte mask = 0. . // tock // give the sensor some time to think delayMicroseconds(20). // send 0 } // lower clock pin.HIGH). // generate bitmask for the appropriate bit MSB first // set out byte if(data_out & mask){ // choose bit digitalWrite(qt401_do.HIGH).LOW).

qt401_transfer(0x40 & (amount & 0x3F)). qt401_transfer(0x02).HIGH). return qt401_transfer(0x00). } byte qt401_readSensor(void) { qt401_waitForReady(). // do acquisition burst return data_in. delay(600). qt401_transfer(0x01). } delayMicroseconds(75). } byte qt401_driftCompensate(void) { qt401_waitForReady(). } void setup() { //setup the sensor . } void qt401_calibrate(void) { // calibrate qt401_waitForReady(). qt401_transfer(0x80 & (amount & 0x3F)). return qt401_transfer(0x03). // calibrate ends qt401_waitForReady(). delay(600). } // give the sensor some time to think delayMicroseconds(20). // give the sensor some time to think digitalWrite(qt401_ss. } void qt401_setProxThreshold(byte amount) { qt401_waitForReady().// now read a bit coming from the sensor if(digitalRead(qt401_di)){ data_in |= mask. } void qt401_setTouchThreshold(byte amount) { qt401_waitForReady().

printInteger(result). } void loop() { if(digitalRead(qt401_det)){ result = qt401_readSensor().qt401_init(). } } } Restore Edit Page | Page History | Printable View | All Recent Site Changes . qt401_calibrate(). beginSerial(9600). qt401_setTouchThreshold(10). printNewline(). qt401_setProxThreshold(10). if(0x80 & result){ result = result & 0x7f.

qprox. INPUT). OUTPUT). OUTPUT). INPUT). byte mask = 0. pinMode(qt401_di. pinMode(qt401_ss.org * * based on C code written by Nicholas Zambetti */ // define pin int qt401_drd int qt401_di int qt401_ss int qt401_clk int qt401_do int qt401_det int qt401_prx byte result.HIGH). pinMode(qt401_do. void qt401_init() { // define pin directions pinMode(qt401_drd. . } // // wait for the qt401 to be ready // void qt401_waitForReady(void) { while(!digitalRead(qt401_drd)){ continue. INPUT). HIGH). // data ready data in (from sensor) slave select clock data out (to sensor) detect proximity // // // exchange a byte with the sensor byte qt401_transfer(byte data_out) { byte i = 8. // initialise pins digitalWrite(qt401_clk. // = 6. digitalWrite(qt401_ss. // = 4. // = 3. pinMode(qt401_clk. // = 8.Arduino : Tutorial / Qt 401 Learning Examples | Foundations | Hacking | Links qt401 sensor full tutorial coming soon /* qt401 demo * -----------* * the qt401 from qprox http://www. INPUT).com is a linear capacitive sensor * that is able to read the position of a finger touching the sensor * the surface of the sensor is divided in 128 positions * the pin qt401_prx detects when a hand is near the sensor while * qt401_det determines when somebody is actually touching the sensor * these can be left unconnected if you are short of pins * * read the datasheet to understand the parametres passed to initialise the sensor * * Created January 2006 * Massimo Banzi http://www. // = 7. // = 5. pinMode(qt401_det. pinMode(qt401_prx. } } mapping = 2.potemkin. OUTPUT).

qt401_transfer(0x02). // calibrate ends qt401_waitForReady(). // tick // give the sensor time to read the data delayMicroseconds(75). // generate bitmask for the appropriate bit MSB first // set out byte if(data_out & mask){ // choose bit digitalWrite(qt401_do. delay(600). // do acquisition burst return data_in. } // give the sensor some time to think delayMicroseconds(20). } delayMicroseconds(75).HIGH). qt401_transfer(0x01).HIGH). //wait for 75 microseconds while(0 < i) { mask = 0x01 << --i. qt401_transfer(0x40 & (amount & 0x3F)). // bring clock back up digitalWrite(qt401_clk. } void qt401_setProxThreshold(byte amount) { qt401_waitForReady(). // give the sensor some time to think digitalWrite(qt401_ss.LOW). } void qt401_calibrate(void) { // calibrate qt401_waitForReady(). // tock // give the sensor some time to think delayMicroseconds(20). // select slave by lowering ss pin delayMicroseconds(75). } . delay(600). digitalWrite(qt401_ss. this tells the sensor to read the bit we just put out digitalWrite(qt401_clk. // send 0 } // lower clock pin. // send 1 } else{ digitalWrite(qt401_do.byte data_in = 0. // now read a bit coming from the sensor if(digitalRead(qt401_di)){ data_in |= mask. } void qt401_setTouchThreshold(byte amount) { qt401_waitForReady(). qt401_transfer(0x80 & (amount & 0x3F)).LOW).HIGH).LOW).

printNewline(). beginSerial(9600). qt401_setProxThreshold(10). } } } (Printable View of http://www. qt401_calibrate(). if(0x80 & result){ result = result & 0x7f. return qt401_transfer(0x00).cc/en/Tutorial/Qt401) . return qt401_transfer(0x03). qt401_setTouchThreshold(10).byte qt401_driftCompensate(void) { qt401_waitForReady(). } void setup() { //setup the sensor qt401_init().arduino. } byte qt401_readSensor(void) { qt401_waitForReady(). printInteger(result). } void loop() { if(digitalRead(qt401_det)){ result = qt401_readSensor().

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

2006. OUTPUT). int speakerOut = 9. byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". int MAX_COUNT = 24. at 04:15 PM by Clay Shirky Changed line 169 from: [= to: [= Restore October 02. 'e'.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. int statePin = LOW. 1519. 'b'. 1700. 'd'.Show changes to markup October 02. it requires to know * about timing issues and about how to play tones. 1275. with volume control set using analogWrite() [= /* Play Melody * ----------* * Program to play melodies stored in an array. 1136. 'g'. Cuartielles for K3 */ int ledPin = 13. int count2 = 0. } . * * The calculation of the tones is made following the mathematical * operation: * * timeHigh = 1/(2 * toneFrequency) = period / 2 * * where the different tones are described as in the table: * * note frequency period PW (timeHigh) * c 261 Hz 3830 1915 * d 294 Hz 3400 1700 * e 329 Hz 3038 1519 * f 349 Hz 2864 1432 * g 392 Hz 2550 1275 * a 440 Hz 2272 1136 * b 493 Hz 2028 1014 * C 523 Hz 1912 956 * * (cleft) 2005 D. void setup() { pinMode(ledPin. byte names[] = {'c'. 'f'. 2006. int tones[] = {1915.PlayMelody History Hide minor edits . 1014. // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0. at 04:15 PM by Clay Shirky Added lines 165-234: =] Second version. 'C'}. 956}. 1432. 'a'. int count3 = 0.

Changed lines 26-33 from: * to: * Each note has a frequency. We'll use pulse-width * modulation (PWM) to create that vibration. 0).count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. at 04:10 PM by Clay Shirky .500).48) * 30. delayMicroseconds(tones[count2]). 0). to create signature frequencies. digitalWrite(ledPin. we pulse * the speaker HIGH for 'pulse-width' microseconds. 0). delayMicroseconds(tones[count2]). for (count = 0. * We calculate the pulse-width to be half the period. for (count3 = 0. then LOW * for 'pulse-width' microseconds. count3 <= (melody[count*2] .void loop() { analogWrite(speakerOut. to: * Program to play a simple melody Changed lines 23-24 from: * The calculation of the tones is made following the mathematical * operation: to: * Tones are created by quickly pulsing a speaker on and off * using PWM. Deleted lines 34-45: * * * * * * * where the different tones are described as in the table: note c d e f frequency 261 Hz 294 Hz 329 Hz 349 Hz period 3830 3400 3038 2864 PW (timeHigh) 1915 1700 1519 1432 timeHigh = 1/(2 * toneFrequency) = period / 2 . it requires to know * about timing issues and about how to play tones. } } } } } Restore October 02.count2<8. analogWrite(speakerOut. measured in microseconds. count3++) { for (count2=0. } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut. count++) { statePin = !statePin. count < MAX_COUNT. created by varying the period of * vibration. 2006. delayMicroseconds(500). * This pulsing creates a vibration of the desired frequency.Re-wrote Example #1 Changed lines 21-22 from: * Program to play melodies stored in an array. statePin).

See NOTES // Initialize core variables int tone = 0. to: // TONES ========================================== // Start by defining the relationship between // note. 8.edu * See NOTES in comments at end for possible improvements Changed lines 40-55 from: int ledPin = 13.* * * * * g a b C 392 440 493 523 Hz Hz Hz Hz 2550 2272 2028 1912 1275 1136 1014 956 Added lines 36-37: * Refactoring and comments 2006 clay. 1136. to represent a rest 1. C. // Set serial out if we want debugging } Added lines 67-112: // MELODY and TIMING ======================================= // melody[] is an array of notes. // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0. int beat = 0. int count2 = 0. 16. 8. // Loop variable to increase Rest length int rest_count = 100. 1014. OUTPUT). g. 3. long duration = 0. 'e'. 8. period.HIGH). int statePin = LOW.shirky@nyu. 'a'. 'R'. 'b'. // PLAY TONE ============================================== // Pulse the speaker to play a tone for a particular duration void playTone() { long elapsed_time = 0. OUTPUT). 'g'. 16. byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". define R 0 // SETUP ============================================ // Set up speaker on a PWM pin (digital 9. 10 or 11) int speakerOut = 9. 956}. int MAX_COUNT = 24. 2. 16. e. int beats[] = { 16. 'd'. for looping. // Set length of pause between notes int pause = 1000. 8 }. 'f'. if (tone > 0) { // if this isn't a Rest beat. 1432. 'C'}. pinMode(speakerOut. void setup() { pinMode(ledPin. 1275. byte names[] = {'c'. & frequency. if (DEBUG) { Serial. 7. 16. R. b. int count3 = 0. void setup() { pinMode(speakerOut. // which sets each note's relative length (higher #. // Do we want debugging on serial out? 1 for yes. 4. C }. int tones[] = {1915. define define define define define define define define c 3830 // 261 Hz d 3400 // 294 Hz e 3038 // 329 Hz f 2864 // 349 Hz g 2550 // 392 Hz a 2272 // 440 Hz b 2028 // 493 Hz C 1912 // 523 Hz // Define a special note. longer note) int melody[] = { C. . 1. //<-BLETCHEROUS HACK. 1700. int MAX_COUNT = sizeof(melody) / 2. 0 for no int DEBUG = 1. 16. 6. // Melody length. 5. c. a. g.begin(9600). 32. accompanied by beats[]. OUTPUT). int speakerOut = 9. 1519. 8. 16. while the tone has // played less long than 'duration'. C. b. pulse speaker HIGH and LOW while (elapsed_time < duration) { digitalWrite(speakerOut. // Set overall tempo long tempo = 10000.

delayMicroseconds(tones[count2]).print(" "). } } else { // Rest beat. Serial. // DOWN digitalWrite(speakerOut. j < rest_count. statePin). count3 <= (melody[count*2] .. Serial.count2++) { if (names[count2] == melody[count*2 + 1]) { digitalWrite(speakerOut. beat. if (DEBUG) { // If debugging. Serial. // Keep track of how long we pulsed elapsed_time += (tone). for (count = 0.print(beat).HIGH). LOW). digitalWrite(speakerOut. count3++) { for (count2=0.print(":"). } } } // LET THE WILD RUMPUS BEGIN ============================= Changed lines 114-131 from: digitalWrite(speakerOut. delayMicroseconds(tone / 2). count < MAX_COUNT. } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size digitalWrite(speakerOut. delayMicroseconds(tones[count2]).println(duration). // Set up timing playTone(). } } to: // Set up a counter to pull from melody[] and beats[] for (int i=0. // A pause between notes. Serial. report loop. tone. LOW). Serial. LOW). duration = beat * tempo.print(tone). delayMicroseconds(500). and duration Serial. 0). count++) { statePin = !statePin. i<MAX_COUNT.48) * 30. Changed lines 137-166 from: =] Example 2: Play Melody _ faded volume .delayMicroseconds(tone / 2). for (count3 = 0.print(i). i++) { tone = melody[i]. beat = beats[i]. loop times delay for (int j = 0. j++) { // See NOTE on rest_count delayMicroseconds(duration). Serial.print(" "). digitalWrite(ledPin.count2<8.. delayMicroseconds(pause).

1275. // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0. 956}. 1014.arduino. 'd'. int MAX_COUNT = 24. rest_count will be affected by chip architecture and speed. // maximum volume is 1000 byte names[] = {'c'.[= /* Play Melody . int count2 = 0. it requires to know about timing issues and about how to play tones. Cuartielles for K3 Deleted lines 164-205: int ledPin = 13. 'b'. 'e'. pause. int speakerOut = 9.' rest_count creates a loop variable to bring 'rest' beats in line with 'tone' beats of the same length.FV * * * * * * * * * * * * * * * * * * * * * * * * * to: /* * * * * * * * * * * * * * * * * * * * * * * * * * * NOTES The program purports to hold a tone for 'duration' microseconds. int statePin = LOW. 'a'. a tone of 'duration' plays much more slowly than a rest of 'duration. Past behavior is no guarantee of future performance. 1519. 'f'. as well as overhead from any program mods. int tones[] = {1915. Your mileage may vary. and rest_count to #define statements RE-WRITE to include volume. . 1700. using analogWrite.cc/en/Tutorial/PlayMelody ADD code to make the tempo settable by pot or other input device ADD code to take tempo or volume settable by serial communication (Requires 0005 or higher. _plus_ any overhead created by incremeting elapsed_time (could be in excess of 3K microseconds) _plus_ overhead of looping and two digitalWrites() As a result. byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". Light fuse and get away. 1432. int volume = 300. 'g'. 1136. The calculation of the tones is made following the mathematical operation: timeHigh = 1/(2 * toneFrequency) = period / 2 where the different tones are described as in the table: note c d e f g a b C frequency 261 Hz 294 Hz 329 Hz 349 Hz 392 Hz 440 Hz 493 Hz 523 Hz period 3830 3400 3038 2864 2550 2272 2028 1912 PW (timeHigh) 1915 1700 1519 1432 1275 1136 1014 956 We use the Pulse Width feature with analogWrite to change volume (cleft) 2005 D. This could use a number of enhancements: ADD code to let the programmer specify how many times the melody should loop before stopping ADD another octave MOVE tempo. int count3 = 0. as with the second program at http://www.) ADD code to create a tone offset (higer or lower) through pot etc REPLACE random melody with opening bars to 'Smoke on the Water' ---------------Program to play melodies stored in an array. Lies lies lies! It holds for at least 'duration' microseconds. 'C'}.

Changed line 63 from: analogWrite(speakerOut.25 Changed lines 5-6 from: A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones.48) * 30. In our example we are plugging the Piezo on the pin number 10. } void loop() { analogWrite(speakerOut. } } } } } Restore October 18. for (count = 0.229. LOW). to: digitalWrite(speakerOut. statePin). 0). that supports the functionality of writing a PWM signal to it. count3++) { for (count2=0. count++) { statePin = !statePin. OUTPUT). digitalWrite(ledPin. } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut.void setup() { pinMode(ledPin. OUTPUT).volume). for (count3 = 0. In our example we are plugging the Piezo on the pin number 9. Changed line 70 from: . The first example of the code will just send a square wave to the piezo. to: A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. delayMicroseconds(500). while the second one will make use of the PWM functionality to control the volume through changing the Pulse Width. delayMicroseconds(tones[count2]). Changed lines 13-14 from: Example of connection of a Piezo to pin 10 to: Example of connection of a Piezo to pin 9 Example 1: Play Melody Added line 59: pinMode(speakerOut. and not just a plain HIGH or LOW value.count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. 0). 2005.178. analogWrite(speakerOut. 0). delayMicroseconds(tones[count2]). and not just a plain HIGH or LOW value. 0). at 01:50 AM by 195. that supports the functionality of writing a PWM signal to it.count2<8. count < MAX_COUNT. count3 <= (melody[count*2] .

LOW). 956}. void setup() { pinMode(ledPin. int count2 = 0. int tones[] = {1915. to: digitalWrite(speakerOut. 1275. 1014. 1519. // maximum volume is 1000 byte names[] = {'c'. 0). int speakerOut = 9. // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0. 0). byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". 'e'. int count3 = 0. 0). int statePin = LOW. Changed line 77 from: analogWrite(speakerOut. 'a'. Cuartielles for K3 */ int ledPin = 13. 1700.500). OUTPUT). int volume = 300. to: digitalWrite(speakerOut. to: digitalWrite(speakerOut. } void loop() { . * * The calculation of the tones is made following the mathematical * operation: * * timeHigh = 1/(2 * toneFrequency) = period / 2 * * where the different tones are described as in the table: * * note frequency period PW (timeHigh) * c 261 Hz 3830 1915 * d 294 Hz 3400 1700 * e 329 Hz 3038 1519 * f 349 Hz 2864 1432 * g 392 Hz 2550 1275 * a 440 Hz 2272 1136 * b 493 Hz 2028 1014 * C 523 Hz 1912 956 * * We use the Pulse Width feature with analogWrite to change volume * * (cleft) 2005 D. int MAX_COUNT = 24. 'C'}. 'd'.FV * ---------------* * Program to play melodies stored in an array. 'g'. 'b'.analogWrite(speakerOut. 1136. 1432. 'f'. Changed line 72 from: analogWrite(speakerOut.HIGH). Added lines 85-157: =] Example 2: Play Melody _ faded volume [= /* Play Melody . it requires to know * about timing issues and about how to play tones.

229. that supports the functionality of writing a PWM signal to it. it requires to know about timing issues and about how to play tones. delayMicroseconds(tones[count2]).flickr.analogWrite(speakerOut. digitalWrite(ledPin. 0).jpg Example of connection of a Piezo to pin 10 Restore October 17.229.178. count++) { statePin = !statePin. 2005. then they will just look like a metallic disc.178. } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut. delayMicroseconds(tones[count2]). We connect the black one to ground and the red one to the output. 0). analogWrite(speakerOut. Sometimes it is possible to acquire Piezo elements without a plastic housing. statePin). /* * * * * * * * * * * * * Play Melody ----------Program to play melodies stored in an array.volume).25 Added lines 1-76: Play Melody This example makes use of a Piezo Speaker in order to play melodies.com/31/53523608_3d4268ba68. at 05:29 PM by 195.178.25 Changed lines 7-8 from: to: http://static.count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. at 05:32 PM by 195. Restore October 17. 0). commercial devices are usually having a red and a black wires indicating how to plug it to the board. for (count = 0.count2<8. at 05:21 PM by 195. and not just a plain HIGH or LOW value. delayMicroseconds(500). count < MAX_COUNT. count3++) { for (count2=0. 2005. for (count3 = 0. In our example we are plugging the Piezo on the pin number 10. There is more information about how PWM works written by David Cuartielles here and even at K3's old course guide A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones.48) * 30. } } } } } Restore October 17.229. count3 <= (melody[count*2] . 2005. The calculation of the tones is made following the mathematical operation: timeHigh = 1/(2 * toneFrequency) = period / 2 where the different tones are described as in the table: .25 Added lines 7-8: The other thing to remember is that Piezos have polarity. We are taking advantage of the processors capability to produde PWM signals in order to play music.

'a'. Cuartielles for K3 int ledPin = 13. for (count3 = 0. 'g'. 'b'. int speakerOut = 9. int statePin = LOW. int tones[] = {1915. int count3 = 0. 0). 1519. 'f'. statePin).* note * c * d * e * f * g * a * b * C * * (cleft) 2005 */ frequency 261 Hz 294 Hz 329 Hz 349 Hz 392 Hz 440 Hz 493 Hz 523 Hz period 3830 3400 3038 2864 2550 2272 2028 1912 PW (timeHigh) 1915 1700 1519 1432 1275 1136 1014 956 D. delayMicroseconds(tones[count2]). int MAX_COUNT = 24. analogWrite(speakerOut. 1700. count < MAX_COUNT. count++) { statePin = !statePin. int count2 = 0. count3++) { for (count2=0. OUTPUT). byte names[] = {'c'. delayMicroseconds(500). digitalWrite(ledPin. } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut.count2<8. } } } } } Restore Edit Page | Page History | Printable View | All Recent Site Changes . 'd'. 0). 'C'}. count3 <= (melody[count*2] .count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. 956}. delayMicroseconds(tones[count2]). 1014. 1432. 1275. // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0. 'e'. 0). byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p".48) * 30.500). for (count = 0. 1136. void setup() { pinMode(ledPin. } void loop() { analogWrite(speakerOut.

Each note has a frequency. The first example of the code will just send a square wave to the piezo. then they will just look like a metallic disc. while the second one will make use of the PWM functionality to control the volume through changing the Pulse Width. In our example we are plugging the Piezo on the pin number 9. We are taking advantage of the processors capability to produde PWM signals in order to play music. measured in microseconds. commercial devices are usually having a red and a black wires indicating how to plug it to the board. There is more information about how PWM works written by David Cuartielles here and even at K3's old course guide A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. to create signature frequencies. We'll use pulse-width . created by varying the period of vibration. and not just a plain HIGH or LOW value. The other thing to remember is that Piezos have polarity. Sometimes it is possible to acquire Piezo elements without a plastic housing. that supports the functionality of writing a PWM signal to it. Example of connection of a Piezo to pin 9 Example 1: Play Melody /* * * * * * * * * * Play Melody ----------Program to play a simple melody Tones are created by quickly pulsing a speaker on and off using PWM. We connect the black one to ground and the red one to the output.Arduino : Tutorial / Play Melody Learning Examples | Foundations | Hacking | Links Play Melody This example makes use of a Piezo Speaker in order to play melodies.

accompanied by beats[]. longer note) int melody[] = { C. then LOW * for 'pulse-width' microseconds. // Set serial out if we want debugging } } // MELODY and TIMING ======================================= // melody[] is an array of notes. LOW). // Loop variable to increase Rest length int rest_count = 100. See NOTES // Initialize core variables int tone = 0. // Do we want debugging on serial out? 1 for yes. * This pulsing creates a vibration of the desired frequency. c. j++) { // See NOTE on rest_count delayMicroseconds(duration). 8 }. // Keep track of how long we pulsed elapsed_time += (tone). 8. Cuartielles for K3 * Refactoring and comments 2006 clay. 10 or 11) int speakerOut = 9. for looping. // Set length of pause between notes int pause = 1000. //<-BLETCHEROUS HACK. we pulse * the speaker HIGH for 'pulse-width' microseconds. 16. R. & frequency.edu * See NOTES in comments at end for possible improvements */ // TONES ========================================== // Start by defining the relationship between // note. 32. 8. * We calculate the pulse-width to be half the period. } } else { // Rest beat. // Set overall tempo long tempo = 10000. C. pulse speaker HIGH and LOW while (elapsed_time < duration) { digitalWrite(speakerOut. g.HIGH). // DOWN digitalWrite(speakerOut. 16. 16. void setup() { pinMode(speakerOut. while the tone has // played less long than 'duration'. long duration = 0. 16. if (DEBUG) { Serial. 16. a. OUTPUT).begin(9600). j < rest_count. delayMicroseconds(tone / 2). // which sets each note's relative length (higher #. C. e.* modulation (PWM) to create that vibration. 8. b. int beats[] = { 16. 0 for no int DEBUG = 1. to represent a rest #define R 0 // SETUP ============================================ // Set up speaker on a PWM pin (digital 9. int MAX_COUNT = sizeof(melody) / 2. if (tone > 0) { // if this isn't a Rest beat. } . C }. int beat = 0. #define c 3830 // 261 Hz #define d 3400 // 294 Hz #define e 3038 // 329 Hz #define f 2864 // 349 Hz #define g 2550 // 392 Hz #define a 2272 // 440 Hz #define b 2028 // 493 Hz #define C 1912 // 523 Hz // Define a special note. delayMicroseconds(tone / 2).shirky@nyu. 16. 'R'. // PLAY TONE ============================================== // Pulse the speaker to play a tone for a particular duration void playTone() { long elapsed_time = 0. b. g. period. * * (cleft) 2005 D. // Melody length. loop times delay for (int j = 0.

it requires to know about timing issues and about how to play tones.print(i). // A pause between notes. Past behavior is no guarantee of future * performance. // Set up timing playTone(). delayMicroseconds(pause). using analogWrite.print(beat).arduino. beat = beats[i].print(" ").print(":"). Serial.print(" ").println(duration). Light fuse and get away. beat.) * ADD code to create a tone offset (higer or lower) through pot etc * REPLACE random melody with opening bars to 'Smoke on the Water' */ Second version. Serial. Serial. Your mileage may vary. as well as * overhead from any program mods. Serial. i<MAX_COUNT. with volume control set using analogWrite() /* * * * * * * * * * * * * * * * * * Play Melody ----------Program to play melodies stored in an array. a tone of 'duration' plays much more slowly than a rest * of 'duration. _plus_ * any overhead created by incremeting elapsed_time (could be in excess of * 3K microseconds) _plus_ overhead of looping and two digitalWrites() * * As a result. tone. and duration Serial. * Lies lies lies! It holds for at least 'duration' microseconds. as with the second program at * http://www. Serial. The calculation of the tones is made following the mathematical operation: timeHigh = 1/(2 * toneFrequency) = period / 2 where the different tones are described as in the table: note c d e f frequency 261 Hz 294 Hz 329 Hz 349 Hz period 3830 3400 3038 2864 PW (timeHigh) 1915 1700 1519 1432 . * * rest_count will be affected by chip architecture and speed. Serial..cc/en/Tutorial/PlayMelody * ADD code to make the tempo settable by pot or other input device * ADD code to take tempo or volume settable by serial communication * (Requires 0005 or higher.' rest_count creates a loop variable to bring 'rest' beats * in line with 'tone' beats of the same length. and rest_count to #define statements * RE-WRITE to include volume. report loop. if (DEBUG) { // If debugging. * * This could use a number of enhancements: * ADD code to let the programmer specify how many times the melody should * loop before stopping * ADD another octave * MOVE tempo.. duration = beat * tempo. pause. i++) { tone = melody[i]. } } } /* * NOTES * The program purports to hold a tone for 'duration' microseconds.} } // LET THE WILD RUMPUS BEGIN ============================= void loop() { // Set up a counter to pull from melody[] and beats[] for (int i=0.print(tone).

int count2 = 0. 1014. int MAX_COUNT = 24. 'g'. statePin). delayMicroseconds(tones[count2]). 'b'. int count3 = 0. 1519.cc/en/Tutorial/PlayMelody) . } void loop() { analogWrite(speakerOut. for (count3 = 0. int tones[] = {1915. 1432.count2<8. 'd'. analogWrite(speakerOut. 1275. 1700. count++) { statePin = !statePin. Cuartielles for K3 int ledPin = 13. OUTPUT). digitalWrite(ledPin. 0). for (count = 0. byte names[] = {'c'. 1136.count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. delayMicroseconds(500). void setup() { pinMode(ledPin. 956}.arduino. 'C'}. 0). count3 <= (melody[count*2] .* g * a * b * C * * (cleft) 2005 */ 392 440 493 523 Hz Hz Hz Hz 2550 2272 2028 1912 1275 1136 1014 956 D. } } } } } (Printable View of http://www. count3++) { for (count2=0. 0). 'a'. delayMicroseconds(tones[count2]). byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". int statePin = LOW. 'e'. int speakerOut = 9. 'f'. // count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 // 10 20 30 int count = 0. count < MAX_COUNT.500). } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut.48) * 30.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

pinMode(clock.178. 2005. at 02:00 PM by 195. clock = 10. There is more information about this microchip that you will find in its datasheet. oe = 11. // waits for a moment // waits for a second Restore November 10. An LED Driver has a shift register embedded that will take data in serial format and transfer it to parallel.LEDDriver History Hide minor edits . if dato is 255 all the LEDs will light up. The code example you will see here is taking a value stored in the variable dato and showing it as a decoded binary number.Show changes to markup November 11. Malmo University * @author: David Cuartielles. dato = 0. pinMode(data.105 Changed line 73 from: delay(100).flickr. at 01:45 AM by 81.128.25 Added lines 1-77: LED Driver This example makes use of an LED Driver in order to control an almost endless amount of LEDs with only 4 pins. http://static.com/30/61941877_d74eae045b.229.g. to: delay(100). stored in "dato" on a set of 8 LEDs * * (copyleft) 2005 K3. We use the 4794 from Philips. strob = 8. only the first LED will light up. OUTPUT). It is possible to daisy chain this chip increasing the total amount of LEDs by 8 each time. Marcos Yarza * @project: made for SMEE .jpg Example of connection of a 4794 /* Shift Out Data * -------------* * Shows a byte. E. if dato is 1.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. OUTPUT). 2005. count = 0.236.Experiential Vehicles */ int int int int int int data = 9. . Marcus Hannerstig * @hardware: David Cuartielles. pinMode(strob. void setup() { beginSerial(9600). OUTPUT).

for (count = 0. LOW). OUTPUT). count++) { digitalWrite(data. count < 8. digitalWrite(strob. delay(100). digitalWrite(clock. } // waits for a second Restore Edit Page | Page History | Printable View | All Recent Site Changes . HIGH). serialWrite(10). if (count == 7){ digitalWrite(oe. } PulseClock(). digitalWrite(strob. delayMicroseconds(50). serialWrite(13). HIGH).pinMode(oe. digitalWrite(oe. digitalWrite(clock. dato>>=1. LOW). LOW). delay(100). HIGH). delayMicroseconds(20). } void PulseClock(void) { digitalWrite(clock. } delayMicroseconds(20). } void loop() { dato = 5. dato & 01). LOW). //serialWrite((dato & 01) + 48).

. only the first LED will light up. if dato is 1. strob = 8. An LED Driver has a shift register embedded that will take data in serial format and transfer it to parallel. It is possible to daisy chain this chip increasing the total amount of LEDs by 8 each time.Experiential Vehicles */ int int int int int int data = 9. count = 0.Arduino : Tutorial / LED Driver Learning Examples | Foundations | Hacking | Links LED Driver This example makes use of an LED Driver in order to control an almost endless amount of LEDs with only 4 pins. clock = 10. We use the 4794 from Philips. Marcos Yarza * @project: made for SMEE . Marcus Hannerstig * @hardware: David Cuartielles.g. void setup() { beginSerial(9600). E. oe = 11. dato = 0. if dato is 255 all the LEDs will light up. pinMode(data. OUTPUT). Example of connection of a 4794 /* Shift Out Data * -------------* * Shows a byte. The code example you will see here is taking a value stored in the variable dato and showing it as a decoded binary number. Malmo University * @author: David Cuartielles. stored in "dato" on a set of 8 LEDs * * (copyleft) 2005 K3. There is more information about this microchip that you will find in its datasheet.

LOW). count < 8.cc/en/Tutorial/LEDDriver) . delayMicroseconds(50). } void loop() { dato = 5. HIGH). serialWrite(13). LOW). count++) { digitalWrite(data. digitalWrite(clock. LOW). dato>>=1. digitalWrite(strob.arduino. delay(100). digitalWrite(clock. OUTPUT). OUTPUT). delayMicroseconds(20). HIGH). } delayMicroseconds(20). if (count == 7){ digitalWrite(oe.pinMode(clock. serialWrite(10). for (count = 0. //serialWrite((dato & 01) + 48). } // waits for a moment (Printable View of http://www. dato & 01). digitalWrite(strob. pinMode(strob. } void PulseClock(void) { digitalWrite(clock. HIGH). } PulseClock(). LOW). OUTPUT). pinMode(oe. delay(100). digitalWrite(oe.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

DB[] = {3.com/25/53544993_3611fce234. http://static. 9.DB7. 4.8 bits This example shows the most basic action to be done with a LCD display: to show a welcome message. . 2005. RW. 8.. * * (cleft) 2005 DojoDave for K3 * */ int int int int DI = 12.25 Changed lines 1-121 from: http://static. The example * uses all the digital pins on the Arduino board.LCD8Bits History Hide minor edits . at 07:00 PM by 195.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. According to it there is a group of pins dedicated to sending data and locations of that data on the screen. The backdrop of this example is that we are using almost all the available pins on Arduino board in order to drive the display.flickr.jpg to: LCD Display . 7. for (i=DB[0]. 5. i++) { digitalWrite(i.229. i <= DI. void LcdCommandWrite(int value) { // poll all the pins int i = 0. the user can choose to use 4 or 8 pins to send data.DI.jpg Picture of a protoboard supporting the display and a potentiometer /* LCD Hola * -------* * This is the first example in how to use an LCD screen * configured with data transfers over 8 bits.value & 01). On top of that three more pins are needed to synchronize the communication towards the display. 10}. 6. LCD displays are most of the times driven using an industrial standard established by Hitachi.flickr. Therefore we will use a potentiometer to regulate the contrast. RW = 11. DB0.Show changes to markup October 17.com/25/53544993_3611fce234_o.178. Enable (11 in total) * * the pinout for LCD displays is standard and there is plenty * of documentation to be found on the internet. Enable = 2. but can * easily display data on the display * * There are the following pins to be considered: * * . In our case we have an LCD display with backlight and contrast control. but we have decided to show it this way for simplicity.

i++) { pinMode(i.OUTPUT). // send a pulse to enable digitalWrite(Enable.LOW).value & 01). cursor on. } delay(100). for (i=DB[0]. set cursor position to zero delay(100). i <= DI. cursor on. no display shift delay(20). i++) { digitalWrite(i. HIGH). 5x7 font delay(50). delayMicroseconds(1).LOW).HIGH). LcdCommandWrite(0x01). delayMicroseconds(1). delayMicroseconds(1). 1 display lines. delayMicroseconds(1). no blinking delay(20). i <= DB[7].LOW). digitalWrite(Enable. } digitalWrite(Enable. // pause 1 ms according to datasheet digitalWrite(Enable. LcdCommandWrite(0x80). LcdCommandWrite(0x06). // set cursor position to zero delay(10). // entry mode set: // increment automatically. // function set: // 8-bit interface. // display control: // turn display on. // initiatize lcd after a short pause // needed by the LCDs controller LcdCommandWrite(0x30). no blinking delay(20). LcdDataWrite('o'). LcdCommandWrite(0x30).LOW). delayMicroseconds(1). delayMicroseconds(1). // pause 1 ms according to datasheet } void setup (void) { int i = 0. LOW). 1 display lines. } void loop (void) { LcdCommandWrite(0x02). // Write the welcome message LcdDataWrite('H'). // display control: // turn display on. LcdCommandWrite(0x0E). 5x7 font delay(20). } digitalWrite(Enable. // send a pulse to enable digitalWrite(Enable. // clear display. . // function set: // 8-bit interface. digitalWrite(RW. value >>= 1. // pause 1 ms according to datasheet } void LcdDataWrite(int value) { // poll all the pins int i = 0. LcdCommandWrite(0x30). for (i=Enable. 1 display lines. // function set: // 8-bit interface. digitalWrite(DI.HIGH).value >>= 1. 5x7 font delay(64).

178. LcdDataWrite('l'). LcdDataWrite('a').com/25/53544993_3611fce234_o. LcdDataWrite('r'). LcdDataWrite('o').25 Added line 1: http://static. LcdDataWrite('a'). delay(500).jpg Restore Edit Page | Page History | Printable View | All Recent Site Changes . LcdDataWrite('c'). LcdDataWrite('a'). at 06:53 PM by 195.229. LcdDataWrite('a'). } Restore October 17. LcdDataWrite(' ').LcdDataWrite('l').flickr. LcdDataWrite('C'). 2005.

In our case we have an LCD display with backlight and contrast control. the user can choose to use 4 or 8 pins to send data.8 bits This example shows the most basic action to be done with a LCD display: to show a welcome message. Picture of a protoboard supporting the display and a potentiometer /* LCD Hola * -------* * This is the first example in how to use an LCD screen * configured with data transfers over 8 bits. DB0. The backdrop of this example is that we are using almost all the available pins on Arduino board in order to drive the display.. On top of that three more pins are needed to synchronize the communication towards the display. * * (cleft) 2005 DojoDave for K3 * */ . Enable (11 in total) * * the pinout for LCD displays is standard and there is plenty * of documentation to be found on the internet.DB7. According to it there is a group of pins dedicated to sending data and locations of that data on the screen. Therefore we will use a potentiometer to regulate the contrast. The example * uses all the digital pins on the Arduino board. but can * easily display data on the display * * There are the following pins to be considered: * * . LCD displays are most of the times driven using an industrial standard established by Hitachi. RW.Arduino : Tutorial / LCD 8 Bits Learning Examples | Foundations | Hacking | Links LCD Display . but we have decided to show it this way for simplicity.DI.

delayMicroseconds(1). 7. // send a pulse to enable digitalWrite(Enable. LcdDataWrite('a'). delayMicroseconds(1).LOW). } digitalWrite(Enable.LOW). // pause 1 ms according to datasheet } void setup (void) { int i = 0. // display control: // turn display on. LcdDataWrite('a'). LcdDataWrite(' '). LcdDataWrite('C'). digitalWrite(Enable. delayMicroseconds(1). i++) { digitalWrite(i. LcdDataWrite('o'). RW = 11. void LcdCommandWrite(int value) { // poll all the pins int i = 0.LOW). 5x7 font delay(50). LcdCommandWrite(0x30). LcdCommandWrite(0x01). for (i=Enable. 5x7 font delay(20). LcdCommandWrite(0x80). 1 display lines. } digitalWrite(Enable. for (i=DB[0]. digitalWrite(DI. LcdDataWrite('l'). // pause 1 ms according to datasheet digitalWrite(Enable. delayMicroseconds(1). // function set: // 8-bit interface.HIGH). // display control: // turn display on. // pause 1 ms according to datasheet } void LcdDataWrite(int value) { // poll all the pins int i = 0. digitalWrite(RW.HIGH). } void loop (void) { LcdCommandWrite(0x02). i++) { pinMode(i. // initiatize lcd after a short pause // needed by the LCDs controller LcdCommandWrite(0x30). LcdDataWrite('r'). 6. 5x7 font delay(64). no blinking delay(20). 1 display lines.int int int int DI = 12. 4.LOW). . no blinking delay(20). // entry mode set: // increment automatically. Enable = 2. // set cursor position to zero delay(10). delayMicroseconds(1). 9. LcdCommandWrite(0x30). cursor on. for (i=DB[0]. 5. value >>= 1. DB[] = {3. // function set: // 8-bit interface. LcdCommandWrite(0x06). set cursor position to zero delay(100). HIGH). 8. // send a pulse to enable digitalWrite(Enable. i++) { digitalWrite(i. // clear display. 10}. // Write the welcome message LcdDataWrite('H'). i <= DB[7]. i <= DI. } delay(100). delayMicroseconds(1). 1 display lines. i <= DI. value >>= 1. // function set: // 8-bit interface. no display shift delay(20).OUTPUT). LcdCommandWrite(0x0E). LOW). cursor on.value & 01).value & 01).

} (Printable View of http://www.LcdDataWrite('a'). LcdDataWrite('o'). delay(500).cc/en/Tutorial/LCD8Bits) . LcdDataWrite('c'). LcdDataWrite('l'). LcdDataWrite('a').arduino.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

2006. //repeat forever to: delay(1000). //create and initialize a LiquidCrystal object to control an LCD to: LiquidCrystal lcd = LiquidCrystal(). 2006.HIGH).LCDLibrary History Hide minor edits . //turn on an LED for debugging to: lcd.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.HIGH). at 02:07 PM by Heather Dewey-Hagborg Restore August 09.init(). //turn on an LED for debugging . LCD interface library and tutorial by Heather Dewey-Hagborg Restore August 23. 2006. Changed lines 66-67 from: LiquidCrystal lcd = LiquidCrystal(). at 11:03 AM by Heather Dewey-Hagborg Changed line 17 from: Download the LiquidCrystal library here. to: Download the LiquidCrystal library here.Show changes to markup September 05. //create a LiquidCrystal object to control an LCD Changed lines 91-92 from: digitalWrite(13. //create and initialize a LiquidCrystal object to control an LCD to: LiquidCrystal lcd = LiquidCrystal(). //turn on an LED for debugging Changed line 74 from: delay(1000). //create a LiquidCrystal object to control an LCD Changed lines 69-70 from: digitalWrite(13. //initialize the LCD digitalWrite(13.HIGH). //repeat forever Changed lines 88-89 from: LiquidCrystal lcd = LiquidCrystal(). to: To interface an LCD directly in Arduino code see this example. at 12:54 PM by Heather Dewey-Hagborg Changed lines 155-157 from: To interface an LCD directly in Arduino code see this example.

Restore August 09. to: Download the LiquidCrystal library Restore August 09. //turn on an LED for debugging Added line 130: Changed line 138 from: LiquidCrystal lcd = LiquidCrystal(). at 10:03 AM by Heather Dewey-Hagborg Changed lines 66-67 from: LiquidCrystal lcd = LiquidCrystal(). //turn on an LED for debugging Restore August 09.init(). 2006.HIGH).init(). 2006. at 10:05 AM by Heather Dewey-Hagborg Changed line 17 from: Download the LiquidCrystal library here. //initialize the LCD digitalWrite(13. at 10:04 AM by Heather Dewey-Hagborg Changed line 17 from: Download the LiquidCrystal library here. //create a LiquidCrystal object to control an LCD .HIGH). //create a LiquidCrystal object to control an LCD Changed lines 120-121 from: digitalWrite(13. //turn on an LED for debugging Changed line 116 from: LiquidCrystal lcd = LiquidCrystal(). 2006. //turn on an LED for debugging to: lcd. Restore August 09. 2006.to: lcd. //create a LiquidCrystal object to control an LCD Changed lines 142-143 from: digitalWrite(13.init(). //create and initialize a LiquidCrystal object to control an LCD to: LiquidCrystal lcd = LiquidCrystal(). //create and initialize a LiquidCrystal object to control an LCD to: LiquidCrystal lcd = LiquidCrystal(). //initialize the LCD digitalWrite(13.HIGH). //initialize the LCD digitalWrite(13. //turn on an LED for debugging to: lcd. to: Download the LiquidCrystal library here. at 10:04 AM by Heather Dewey-Hagborg Changed line 17 from: Download the LiquidCrystal library to: Download the LiquidCrystal library here.HIGH).HIGH).

zip Δ . at 01:24 PM by Heather Dewey-Hagborg Changed line 17 from: Download the LiquidCrystal library Attach:LiquidCrystal.to: LiquidCrystal lcd = LiquidCrystal(). Restore August 02. //create and initialize a LiquidCrystal object to control an LCD Deleted line 137: lcd.init().init(). to: Download the LiquidCrystal library Attach:LiquidCrystal. //create a LiquidCrystal object to control an LCD to: LiquidCrystal lcd = LiquidCrystal(). 2006. //initialize the LCD Restore August 02. //initialize the LCD Added line 126: Changed line 134 from: LiquidCrystal lcd = LiquidCrystal().init(). //create a LiquidCrystal object to control an LCD to: LiquidCrystal lcd = LiquidCrystal(). . at 01:23 PM by Heather Dewey-Hagborg Changed line 17 from: Download the LiquidCrystal library here. //create and initialize a LiquidCrystal object to control an LCD Deleted line 68: lcd. to: Download the LiquidCrystal libraryhere. 2006.zip Δ . to: Download the LiquidCrystal library here. Restore August 02. 2006. //create a LiquidCrystal object to control an LCD to: LiquidCrystal lcd = LiquidCrystal(). //create and initialize a LiquidCrystal object to control an LCD Deleted line 89: lcd. //initialize the LCD Changed line 114 from: LiquidCrystal lcd = LiquidCrystal().init(). //create and initialize a LiquidCrystal object to control an LCD Deleted line 117: lcd. at 01:25 PM by Heather Dewey-Hagborg Changed line 17 from: Download the LiquidCrystal libraryhere. //initialize the LCD Added line 75: Changed lines 87-88 from: LiquidCrystal lcd = LiquidCrystal().

at 12:08 PM by Heather Dewey-Hagborg Changed line 146 from: To interface an LCD directly in Arduino code see . Unzip the files and place the whole LiquidCrystal folder inside your arduino-0004\lib\targets\libraries folder. Download the LiquidCrystal library . Start the Arduino program and check to make sure LiquidCrystal is now available as an option in the Sketch menu under "import library". at 12:08 PM by Heather Dewey-Hagborg Added lines 145-146: To interface an LCD directly in Arduino code see . include <LiquidCrystal. 2006. //create a LiquidCrystal object to control an LCD char string1[] = "Hello!". . Restore August 02.zip Restore August 02. 2006. 2006.zip Download the LiquidCrystal library . at 12:20 PM by Heather Dewey-Hagborg Changed lines 17-18 from: Attach:LiquidCrystal.init().h> LiquidCrystal lcd = LiquidCrystal().h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). to: Unzip the files and place the whole LiquidCrystal folder inside your arduino-0004\lib\targets\libraries folder. to: Download the LiquidCrystal library here. at 12:14 PM by Heather Dewey-Hagborg Added lines 14-19: Install the Library For a basic explanation of how libraries work in Arduino read the library page. to: 1. 2006. Restore August 02. 2006. //variable to store the string "Hello!" Changed lines 133-134 from: lcd. at 12:16 PM by Heather Dewey-Hagborg Added line 17: Attach:LiquidCrystal.HIGH). digitalWrite(13. include <LiquidCrystal. char string1[] = "Hello!".Restore August 02. 2006. to: To interface an LCD directly in Arduino code see this example. Start the Arduino program and check to make sure LiquidCrystal is now available as an option in the Sketch menu under "Import Library". at 12:04 PM by Heather Dewey-Hagborg Changed lines 127-131 from: 1. 2006. Restore August 02. Restore August 02. at 12:22 PM by Heather Dewey-Hagborg Changed lines 18-19 from: Unzip the files and place the whole LiquidCrystal folder inside your arduino-0004\lib\targets\libraries folder. Start the Arduino program and check to make sure LiquidCrystal is now available as an option in the Sketch menu under "import library". Restore August 02.

//delay 1000 ms to view change lcd.HIGH).HIGH).h> LiquidCrystal lcd = LiquidCrystal(). at 12:02 PM by Heather Dewey-Hagborg Changed lines 107-111 from: 1.init().printIn(string1). include <LiquidCrystal. //delay 1000 ms to view change } //repeat forever the to the to cursor to the starting position view change string to the LCD view change . //send the string to the LCD delay(1000). } to: lcd.commandWrite(2).init(). delay(1000). include <LiquidCrystal. //turn on an LED for debugging Changed lines 137-141 from: lcd.init(). //create a LiquidCrystal object to control an LCD char string1[] = "Hello!".commandWrite(2). delay(1000).printIn(string1). to: 1. lcd. to: lcd. //delay 1000 ms lcd. //variable to store the string "Hello!" Changed lines 113-114 from: lcd.to: lcd. Restore August 02.h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). //delay 1000 ms } //repeat forever Changed lines 144-145 from: Using this code makes the cursor jump back and forth between the end of the message an the home position.HIGH). //turn on an LED for debugging Changed lines 117-121 from: lcd. delay(1000). //clear the display delay(1000). lcd. //initialize the LCD digitalWrite(13. char string1[] = "Hello!".printIn(string1). to: This code makes the cursor jump back and forth between the end of the message an the home position. //bring delay(1000).printIn(string1).clear(). //send delay(1000). digitalWrite(13. //initialize the LCD digitalWrite(13. 2006. delay(1000). } to: lcd.clear().

clear().print('a'). include <LiquidCrystal. at 11:45 AM by Heather Dewey-Hagborg Changed lines 58-61 from: 1. } to: delay(1000). //send individual letters to the LCD Changed lines 94-95 from: delay(1000). to: 1. digitalWrite(13. //initialize the LCD digitalWrite(13. //clear the display delay(1000).HIGH). //turn on an LED for debugging Changed line 68 from: .init(). 2006. include <LiquidCrystal. at 11:59 AM by Heather Dewey-Hagborg Changed lines 79-82 from: 1.init().h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal().//delay 1000 ms to view change } //repeat forever Restore August 02.HIGH).HIGH).print('a'). to: 1.HIGH). to: lcd. //create a LiquidCrystal object to control an LCD Changed lines 84-85 from: lcd. //initialize the LCD digitalWrite(13. include <LiquidCrystal.init(). //turn on an LED for debugging Changed lines 89-91 from: lcd.Restore August 02. delay(1000).clear(). //delay 1000 ms to view change lcd. 2006.init(). to: lcd. //create a LiquidCrystal object to control an LCD Changed lines 63-64 from: lcd.h> LiquidCrystal lcd = LiquidCrystal(). digitalWrite(13.h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). lcd.h> LiquidCrystal lcd = LiquidCrystal(). to: lcd. include <LiquidCrystal.

If you turn the potentiometer too far in one direction black blocks will appear. at 11:27 AM by Heather Dewey-Hagborg Changed lines 50-51 from: First start by opening a new sketch in Arduino and saving it. Changed lines 26-37 from: Arduino LCD 2 Enable 3 Data Bit 0 (DB0) 4 (DB1) 5 (DB2) 6 (DB3) 7 (DB4) 8 (DB5) 9 (DB6) 10 (DB7) 11 Read/Write (RW) 12 Register Select (RS) to: Arduino LCD 2 Enable 3 Data Bit 0 (DB0) 4 (DB1) 5 (DB2) 6 (DB3) 7 (DB4) 8 (DB5) 9 (DB6) 10 (DB7) 11 Read/Write (RW) 12 Register Select (RS) Restore August 02. to: If all went as planned both the LCD and the LED should turn on. use the 5V and any of the ground connections. On the Arduino module. at 11:32 AM by Heather Dewey-Hagborg Restore August 02. Look at the datasheet for your LCD board to figure out which pins are where. On the Arduino module. Make sure to take note of whether the pin view is from the front or back side of the LCD board. 2006. The phrase #include should pop up at the top of your sketch. 2006. at 11:25 AM by Heather Dewey-Hagborg Changed lines 20-21 from: Insert the LCD header into the breadboard and connect power and ground on the breadboard to power and ground from the microcontroller. and choose "LiquidCrystal". Now you can use the potentiometer to adjust the contrast on the LCD until you can clearly see a cursor at the beginning of the first line. to: First start by opening a new sketch in Arduino and saving it. 2006. Restore August 02. It is a lot of wires. The pinout is as follows: to: Connect wires from the breadboard to the arduino input sockets. at 11:19 AM by Heather Dewey-Hagborg Changed lines 80-81 from: . you don't want to get your pins reversed! The pinout is as follows: Added line 56: Changed lines 72-73 from: If all went as planned both the LCD and the LED should turn on. Restore August 02. The phrase #include <LiquidCrystal. There should be a small spot in the middle where the cursor appears crisp and dark. 2006. Now you can use the potentiometer to adjust the contrast on the LCD until you can clearly see a cursor at the beginning of the first line. 2006. //repeat forever Restore August 02. scroll down to "import library". and choose "LiquidCrystal". scroll down to "import library". Now go to the Sketch menu. Look at the datasheet for your LCD board to figure out which pins are where. to: delay(1000). at 11:39 AM by Heather Dewey-Hagborg Changed lines 24-27 from: Connect wires from the breadboard to the arduino input sockets. Now go to the Sketch menu. so keep them as short and tidy as possible.delay(1000).h> should pop up at the top of your sketch. use the 5V and any of the ground connections: to: Insert the LCD header into the breadboard and connect power and ground on the breadboard to power and ground from the microcontroller. Too far in the other direction everything will fade from the display.

print('b'). to: lcd. Added line 83: Changed lines 85-90 from: lcd. lcd.clear().print('a'). digitalWrite(13. to: lcd.print('c'). delay(1000). lcd.init(). to: lcd. lcd. to: lcd.print('c'). Changed lines 116-118 from: . lcd. delay(1000). delay(1000). delay(1000). lcd.HIGH).print('b'). digitalWrite(13.clear(). Changed lines 111-114 from: lcd. lcd.printIn(string1).clear().print('a'). digitalWrite(13. delay(1000).HIGH).clear().init(). Added lines 96-97: Added line 100: [@ Added line 102: Added line 105: Changed lines 107-108 from: lcd. delay(1000). lcd. digitalWrite(13. lcd.init().HIGH).init(). delay(1000).lcd. delay(1000).printIn(string1).HIGH).

If you are feeling ambitious glance over the datasheet and try out some of the direct commands using the commandWrite() function. include to: Now let's try something a little more interesting. For example. 2006. 1. include <LiquidCrystal. Here is an example: Added line 122: Added line 125: Changed line 138 from: Using this code makes the cursorjump back and forth between the end of the message an the home position.h> Added line 57: Changed lines 70-72 from: Now letÕs try something a little more interesting. you should know there is a lot of functionality in the HD44780 chip interface that is not drawn out into Arduino functions. If you are feeling ambitious glance over the datasheet and try out some of the direct commands using the commandWrite() function.} Finally. commandWrite(2) tells the board to move the cursor back to starting position. [@ 1. at 11:17 AM by Heather Dewey-Hagborg Changed lines 54-55 from: 1. Restore August 02. to: @] Finally. Compile and upload the following code to the Arduino.h> Added line 78: . For example. Compile and upload the following code to the Arduino. commandWrite(2) tells the board to move the cursor back to starting position. include <LiquidCrystal. include to: 1. to: Using this code makes the cursor jump back and forth between the end of the message an the home position. you should know there is a lot of functionality in the HD44780 chip interface that is not drawn out into Arduino functions.

include <LiquidCrystal. include to: 1. It currently implements 8-bit control and one line display of 5x7 characters. to: lcd. include <LiquidCrystal.HIGH). to: In this tutorial you will control a Liquid Crystal Display (LCD) using the Arduino LiquidCrystal library. Added line 25: [@ Changed lines 38-39 from: to: @] Changed line 53 from: to: [@ Changed lines 57-58 from: lcd. This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions. and to send commands directly to the HD44780 chip. include to: 1. to clear the screen. The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset.init(). and to send commands directly to the HD44780 chip. Functions are provided to initialize the screen. It currently implements 8-bit control and one line display of 5x7 characters.HIGH). to: delay(1000).h> Restore August 02. digitalWrite(13. Functions are provided to initialize the screen. to print characters and strings. to print characters and strings. to clear the screen. such as those available from Sparkfun. such as those available from Sparkfun. digitalWrite(13. 2006. at 11:14 AM by Heather Dewey-Hagborg Changed lines 3-4 from: In this tutorial you will control a Liquid Crystal Display (LCD) using the Arduino LiquidCrystal library. This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions.init(). The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset.h> Changed line 114 from: 1. Changed lines 64-65 from: .Changed lines 91-92 from: } to: @] Changed line 97 from: 1. Added line 60: Changed line 62 from: delay(1000).

at 11:12 AM by Heather Dewey-Hagborg Changed lines 1-2 from: Arduino Liquid Crystal Display Interface to: Arduino Liquid Crystal Library LCD Interface Changed lines 7-15 from: * * * * * * Solderless breadboard Hookup wire Arduino Microcontoller Module Potentiometer Liquid Crystal Display (LCD) with HD44780 chip interface Light emitting Diode (LED) .optional. for debugging Prepare the breadboard to: Solderless breadboard Hookup wire Arduino Microcontoller Module Potentiometer Liquid Crystal Display (LCD) with HD44780 chip interface Light emitting Diode (LED) .optional. 2006. for debugging Prepare the breadboard Added lines 22-23: Added lines 38-39: .} to: @] Restore August 02.

HIGH). to: Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground. scroll down to "import library". and choose "LiquidCrystal". digitalWrite(13. Now go to the Sketch menu. Restore August 02.Changed lines 42-45 from: Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground. to: . 2006. The phrase #include should pop up at the top of your sketch. Program the Arduino First start by opening a new sketch in Arduino and saving it. and choose ÒLiquidCrystalÓ. Now go to the Sketch menu. Program the Arduino First start by opening a new sketch in Arduino and saving it.init(). scroll down to Òimport libraryÓ. The phrase #include should pop up at the top of your sketch. at 10:45 AM by Heather Dewey-Hagborg Changed line 95 from: to: [@ Changed lines 100-101 from: lcd.

Changed lines 109-110 from: } to: @] Restore August 02. to: lcd.optional. use the 5V and any of the ground connections: Connect wires from the breadboard to the arduino input sockets. lcd. Insert the LCD header into the breadboard and connect power and ground on the breadboard to power and ground from the microcontroller. to print characters and strings. The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset.commandWrite(2). at 10:42 AM by Heather Dewey-Hagborg Added lines 1-111: Arduino Liquid Crystal Display Interface In this tutorial you will control a Liquid Crystal Display (LCD) using the Arduino LiquidCrystal library. On the Arduino module. lcd. This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions. Ground. Changed lines 104-107 from: lcd. delay(1000).HIGH). Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground. to clear the screen. digitalWrite(13. Program the Arduino . for debugging Prepare the breadboard Solder a header to the LCD board if one is not present already. delay(1000). The pinout is as follows: Arduino LCD 2 Enable 3 Data Bit 0 (DB0) 4 (DB1) 5 (DB2) 6 (DB3) 7 (DB4) 8 (DB5) 9 (DB6) 10 (DB7) 11 Read/Write (RW) 12 Register Select (RS) Connect a potentiometer a a voltage divider between 5V. and to send commands directly to the HD44780 chip.commandWrite(2).init(). Look at the datasheet for your LCD board to figure out which pins are where.lcd. such as those available from Sparkfun. and the contrast adjustment pin on your LCD. It currently implements 8-bit control and one line display of 5x7 characters. 2006. delay(1000).printIn(string1). delay(1000). Functions are provided to initialize the screen. Materials needed: * * * * * * Solderless breadboard Hookup wire Arduino Microcontoller Module Potentiometer Liquid Crystal Display (LCD) with HD44780 chip interface Light emitting Diode (LED) .printIn(string1).

and now we have ourselves a proper hello world program.commandWrite(2). } void loop(void){ lcd. digitalWrite(13. digitalWrite(13.clear(). void setup(void){ lcd. delay(1000). commandWrite(2) tells the board to move the cursor back to starting position. } } If all went as planned both the LCD and the LED should turn on. and choose ÒLiquidCrystalÓ.printIn(string1).print('b'). Restore Edit Page | Page History | Printable View | All Recent Site Changes . Now go to the Sketch menu. For example. } } This time you should see the letters a b and c appear and clear from the display in an endless loop. delay(1000). Now you can use the potentiometer to adjust the contrast on the LCD until you can clearly see a cursor at the beginning of the first line.init(). lcd. digitalWrite(13. delay(1000).HIGH). include LiquidCrystal lcd = LiquidCrystal(). pass it to printIn().print('c'). Now letÕs try something a little more interesting. Simply initialize a string. void setup(void){ lcd.printIn(string1). } } Using this code makes the cursorjump back and forth between the end of the message an the home position.init(). The phrase #include should pop up at the top of your sketch. but who really wants to type out each letter of a message indivually? Enter the printIn() function.print('a'). Copy the following code into your sketch.First start by opening a new sketch in Arduino and saving it. 1. compile and upload to the Arduino. scroll down to Òimport libraryÓ. include LiquidCrystal lcd = LiquidCrystal(). lcd. void setup(void){ lcd. char string1[] = "Hello!".HIGH). you should know there is a lot of functionality in the HD44780 chip interface that is not drawn out into Arduino functions. This is all great fun. digitalWrite(13. delay(1000).init(). include LiquidCrystal lcd = LiquidCrystal().clear(). } void loop(void){ lcd. lcd. delay(1000). 1. char string1[] = "Hello!".HIGH). lcd.init(). void setup(void){ lcd. 1. Compile and upload the following code to the Arduino. 1. include LiquidCrystal lcd = LiquidCrystal(). delay(1000). } void loop(void){ delay(1000). lcd.HIGH). If you are feeling ambitious glance over the datasheet and try out some of the direct commands using the commandWrite() function. } } Finally. The first program we are going to try is simply for calibration and debugging. } void loop(void){ lcd.

On the Arduino module. It currently implements 8-bit control and one line display of 5x7 characters. This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions.Arduino : Tutorial / LCD Library Learning Examples | Foundations | Hacking | Links Arduino Liquid Crystal Library LCD Interface In this tutorial you will control a Liquid Crystal Display (LCD) using the Arduino LiquidCrystal library.optional. . Prepare the breadboard Solder a header to the LCD board if one is not present already. The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset. Start the Arduino program and check to make sure LiquidCrystal is now available as an option in the Sketch menu under "Import Library". Insert the LCD header into the breadboard and connect power and ground on the breadboard to power and ground from the microcontroller. and to send commands directly to the HD44780 chip. to print characters and strings. to clear the screen. such as those available from Sparkfun. Materials needed: Solderless breadboard Hookup wire Arduino Microcontoller Module Potentiometer Liquid Crystal Display (LCD) with HD44780 chip interface Light emitting Diode (LED) . Download the LiquidCrystal library here. use the 5V and any of the ground connections. Functions are provided to initialize the screen. for debugging Install the Library For a basic explanation of how libraries work in Arduino read the library page. Unzip the files and place the whole LiquidCrystal folder inside your arduino-0004\lib\targets\libraries folder.

you don't want to get your pins reversed! The pinout is as follows: Arduino 2 3 4 5 6 7 8 9 10 11 12 LCD Enable Data Bit 0 (DB0) (DB1) (DB2) (DB3) (DB4) (DB5) (DB6) (DB7) Read/Write (RW) Register Select (RS) Connect a potentiometer a a voltage divider between 5V.Connect wires from the breadboard to the arduino input sockets. Make sure to take note of whether the pin view is from the front or back side of the LCD board. . Ground. so keep them as short and tidy as possible. and the contrast adjustment pin on your LCD. Look at the datasheet for your LCD board to figure out which pins are where. It is a lot of wires.

#include <LiquidCrystal. //initialize the LCD digitalWrite(13. Too far in the other direction everything will fade from the display.init(). The first program we are going to try is simply for calibration and debugging. and choose "LiquidCrystal". scroll down to "import library". If you turn the potentiometer too far in one direction black blocks will appear.Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground. . //create a LiquidCrystal object to control an LCD void setup(void){ lcd.h> should pop up at the top of your sketch.HIGH). Copy the following code into your sketch. Now you can use the potentiometer to adjust the contrast on the LCD until you can clearly see a cursor at the beginning of the first line. The phrase #include <LiquidCrystal. //turn on an LED for debugging } void loop(void){ delay(1000). Program the Arduino First start by opening a new sketch in Arduino and saving it. //repeat forever } If all went as planned both the LCD and the LED should turn on. compile and upload to the Arduino. Now go to the Sketch menu. There should be a small spot in the middle where the cursor appears crisp and dark.h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal().

#include <LiquidCrystal.print('a').Now let's try something a little more interesting.clear(). //clear the display delay(1000). but who really wants to type out each letter of a message indivually? Enter the printIn() . //turn on an LED for debugging } void loop(void){ lcd. delay(1000).HIGH).//delay 1000 ms to view change } //repeat forever This time you should see the letters a b and c appear and clear from the display in an endless loop. //create a LiquidCrystal object to control an LCD void setup(void){ lcd. //delay 1000 ms to view change lcd. lcd.init(). This is all great fun.print('b').print('c'). Compile and upload the following code to the Arduino. //send individual letters to the LCD lcd.h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). //initialize the LCD digitalWrite(13.

//initialize the LCD digitalWrite(13.cc/en/Tutorial/LCDLibrary) . //clear the display delay(1000).function. #include <LiquidCrystal. commandWrite(2) tells the board to move the cursor back to starting position.init(). you should know there is a lot of functionality in the HD44780 chip interface that is not drawn out into Arduino functions. //create a LiquidCrystal object to control an LCD char string1[] = "Hello!". Here is an example: #include <LiquidCrystal. //delay 1000 ms to view change lcd. //initialize the LCD digitalWrite(13. //turn on an LED for debugging } void loop(void){ lcd.h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). //delay 1000 ms to view change } //repeat forever Finally. Simply initialize a string.HIGH). //create a LiquidCrystal object to control an LCD char string1[] = "Hello!".commandWrite(2). //variable to store the string "Hello!" void setup(void){ lcd. //variable to store the string "Hello!" void setup(void){ lcd.init().printIn(string1). //send the string to the LCD delay(1000). If you are feeling ambitious glance over the datasheet and try out some of the direct commands using the commandWrite() function.HIGH). //send the string to the LCD delay(1000). //bring the cursor to the starting position delay(1000). LCD interface library and tutorial by Heather Dewey-Hagborg (Printable View of http://www. //turn on an LED for debugging } void loop(void){ lcd. //delay 1000 ms to view change lcd. pass it to printIn().printIn(string1).arduino. For example.clear().h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). //delay 1000 ms to view change } //repeat forever This code makes the cursor jump back and forth between the end of the message an the home position. and now we have ourselves a proper hello world program. To interface an LCD directly in Arduino code see this example.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Show changes to markup December 16.229. 2005. The one we use has 6 connectors of which one is power (VCC) and the other four are used to drive the motor sending synchronous signals.178.178.25 Changed lines 3-4 from: This page shows two examples on how to drive a bipolar stepper motor.StepperUnipolar History Hide minor edits . to: This page shows two examples on how to drive a unipolar stepper motor. 2005. at 12:55 PM by 195.178. Changed line 25 from: * It is a bipolar stepper motor with 5 wires: to: * It is a unipolar stepper motor with 5 wires: Changed lines 76-77 from: Example 2: Stepper Bipolar Advanced to: Example 2: Stepper Unipolar Advanced Changed lines 79-80 from: /* Stepper Bipolar Advanced * -----------------------to: /* Stepper Unipolar Advanced * ------------------------Changed line 88 from: * It is a bipolar stepper motor with 5 wires: to: * It is a unipolar stepper motor with 5 wires: Restore October 21.25 Deleted line 107: pinMode(ledPin. These motors can be found in old floppy drives and are easy to control.229.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. at 05:38 AM by 195.25 Added lines 1-160: . These motors can be found in old floppy drives and are easy to control. The one we use has 6 connectors of which one is power (VCC) and the other four are used to drive the motor sending synchronous signals. Restore October 21. OUTPUT). 2005. at 05:37 AM by 195.229.

OUTPUT). pinMode(motorPin4.com/32/54357295_756c131217. pinMode(motorPin2. digitalWrite(motorPin1. It allows the connection of devices and components that need much higher current than the ones that the ATMEGA8 from our Arduino board can offer.. I have it at 5V and works fine * . } OUTPUT).de * * @author: David Cuartielles * @date: 20 Oct.red: power connector. pinMode(motorPin3.Unipolar Stepper Motor This page shows two examples on how to drive a bipolar stepper motor. http://static.uiowa.flickr. delay(delayTime). The one we use has 6 connectors of which one is power (VCC) and the other four are used to drive the motor sending synchronous signals.. 10. void setup() { pinMode(motorPin1. It is aiming those that have no knowledge in how to control stepper motors. . These motors can be found in old floppy drives and are easy to control. digitalWrite(motorPin3.]" * [http://www. LOW). LOW). 500. HIGH).berlios. 2005 */ int int int int int motorPin1 motorPin2 motorPin3 motorPin4 delayTime = = = = = 8. The second example is coded in a more complex way. The first example is the basic code to make the motor spin in one direction. LOW). digitalWrite(motorPin3.. void loop() { digitalWrite(motorPin1. LOW). This chip has a bunch of transistors embedded in a single housing.cs. with 1. digitalWrite(motorPin4. LOW). LOW). The prototyping board has been populated with a 10K potentiomenter that we connect to an analog input.orange and black: coil 1 * . 11.html] * * It is a bipolar stepper motor with 5 wires: * * . and controlling both from a potentiometer.jpg Picture of a protoboard supporting the ULN2003A and a potentiometer Example 1: Simple example /* Stepper Copal * ------------* * Program to drive a stepper motor coming from a 5'25 disk drive * according to the documentation I found.org | http://arduino.brown and yellow: coil 2 * * (cleft) 2005 DojoDave for K3 * http://www. and a ULN2003A driver. this stepper: "[. but allows to make the motor spin at different speeds. OUTPUT). with center taps brought out to separate leads [. digitalWrite(motorPin2.edu/~jones/step/example. digitalWrite(motorPin4.0j0. OUTPUT).] motor * made by Copal Electronics. in both directions. 9..8 degrees per step and 96 ohms * per winding. HIGH). digitalWrite(motorPin2.

html] * * It is a bipolar stepper motor with 5 wires: * * . digitalWrite(motorPin3. 9. delay(delayTime). LOW)..brown and yellow: coil 2 * * (cleft) 2005 DojoDave for K3 * http://www. LOW).0j0. LOW). Example 2: Stepper Bipolar Advanced /* Stepper Bipolar Advanced * -----------------------* * Program to drive a stepper motor coming from a 5'25 disk drive * according to the documentation I found.8 degrees per step and 96 ohms * per winding. this stepper: "[. LOW). } LOW). digitalWrite(motorPin1. digitalWrite(motorPin2. OUTPUT). digitalWrite(motorPin3. count--) { digitalWrite(motorPins[count]. digitalWrite(motorPin1.uiowa.. with center taps brought out to separate leads [. I have it at 5V and works fine * .orange and black: coil 1 * . OUTPUT). count2 = 0. count++) { pinMode(motorPins[count]. } count2>>=1. } void moveBackward() { .. delay(delayTime). digitalWrite(motorPin4.delay(delayTime). void setup() { pinMode(ledPin. 10.cs. digitalWrite(motorPin2. for (count = 0. count >= 0. } delay(delayTime). digitalWrite(motorPin4. for (count = 3. with 1. count = 0. 2005 */ int int int int int motorPins[] = {8. } } void moveForward() { if ((count2 == 0) || (count2 == 1)) { count2 = 16. LOW). count < 4. delayTime = 500. HIGH)..berlios.edu/~jones/step/example.red: power connector. val = 0.] motor * made by Copal Electronics. 11}.]" * [http://www.org | http://arduino. count2>>count&0x01).de * * @author: David Cuartielles * @date: 20 Oct. HIGH).

we have been looking into quite a lot of documentation. count--) { digitalWrite(motorPins[3 . } count2>>=1. count2>>count&0x01).basic explanation about steppers . for (count = 3.if ((count2 == 0) || (count2 == 1)) { count2 = 16.here . } delay(delayTime).1024 * val / 512 + 1. if (val > 540) { // move faster the higher the value from the potentiometer delayTime = 2048 . moveForward().here Restore Edit Page | Page History | Printable View | All Recent Site Changes .information about the motor we are using . } else { delayTime = 1024. } else if (val < 480) { // move faster the lower the value from the potentiometer delayTime = 1024 * val / 512 + 1. } } References In order to work out this example.count]. } void loop() { val = analogRead(0). moveBackward().good PDF with basic information . count >= 0. The following links may be useful for you to visit in order to understand the theory underlying behind stepper motors: .here .

I have it at 5V and works fine . with center taps brought out to separate leads [. Picture of a protoboard supporting the ULN2003A and a potentiometer Example 1: Simple example /* * * * * * * * * * * * * * Stepper Copal ------------Program to drive a stepper motor coming from a 5'25 disk drive according to the documentation I found.8 degrees per step and 96 ohms per winding.] motor made by Copal Electronics. and a ULN2003A driver.cs.orange and black: coil 1 .uiowa.html] It is a unipolar stepper motor with 5 wires: .. These motors can be found in old floppy drives and are easy to control..]" [http://www. The second example is coded in a more complex way. The one we use has 6 connectors of which one is power (VCC) and the other four are used to drive the motor sending synchronous signals. It allows the connection of devices and components that need much higher current than the ones that the ATMEGA8 from our Arduino board can offer.Arduino : Tutorial / Stepper Unipolar Learning Examples | Foundations | Hacking | Links Unipolar Stepper Motor This page shows two examples on how to drive a unipolar stepper motor.edu/~jones/step/example. This chip has a bunch of transistors embedded in a single housing. with 1.. and controlling both from a potentiometer.. but allows to make the motor spin at different speeds. The first example is the basic code to make the motor spin in one direction. The prototyping board has been populated with a 10K potentiomenter that we connect to an analog input. in both directions. this stepper: "[.brown and yellow: coil 2 .red: power connector. It is aiming those that have no knowledge in how to control stepper motors.

digitalWrite(motorPin2.brown and yellow: coil 2 * * (cleft) 2005 DojoDave for K3 * http://www.* * (cleft) 2005 DojoDave for K3 * http://www.8 degrees per step and 96 ohms * per winding. count = 0. OUTPUT). digitalWrite(motorPin1.berlios. pinMode(motorPin2.html] * * It is a unipolar stepper motor with 5 wires: * * . count2 = 0.. digitalWrite(motorPin4. LOW). LOW).org | http://arduino.berlios. 9. Example 2: Stepper Unipolar Advanced /* Stepper Unipolar Advanced * ------------------------* * Program to drive a stepper motor coming from a 5'25 disk drive * according to the documentation I found. LOW). } void loop() { digitalWrite(motorPin1. HIGH).red: power connector... count++) { . LOW). 10. digitalWrite(motorPin1. 11. val = 0. LOW). digitalWrite(motorPin4. LOW). digitalWrite(motorPin2. digitalWrite(motorPin3. void setup() { pinMode(motorPin1.]" * [http://www. count < 4. digitalWrite(motorPin3.. HIGH). OUTPUT). } HIGH). I have it at 5V and works fine * . OUTPUT).edu/~jones/step/example. LOW). 500. delay(delayTime).0j0. 10. LOW). HIGH). void setup() { for (count = 0. 2005 */ int int int int int motorPin1 motorPin2 motorPin3 motorPin4 delayTime = = = = = 8. 2005 */ int int int int int motorPins[] = {8. digitalWrite(motorPin2. digitalWrite(motorPin4. with center taps brought out to separate leads [. LOW). delay(delayTime). LOW). digitalWrite(motorPin3. digitalWrite(motorPin1.cs. LOW). this stepper: "[.orange and black: coil 1 * . with 1. OUTPUT). delayTime = 500.] motor * made by Copal Electronics. pinMode(motorPin4. delay(delayTime).org | http://arduino. 11}.de * * @author: David Cuartielles * @date: 20 Oct.de * * @author: David Cuartielles * @date: 20 Oct. 9. delay(delayTime).uiowa. pinMode(motorPin3. digitalWrite(motorPin3. digitalWrite(motorPin2.0j0. LOW). digitalWrite(motorPin4.

for (count = 3. } void moveBackward() { if ((count2 == 0) || (count2 == 1)) { count2 = 16. moveBackward(). } else { delayTime = 1024. OUTPUT). } } References In order to work out this example. count2>>count&0x01).cc/en/Tutorial/StepperUnipolar) .here . count--) { digitalWrite(motorPins[count]. } else if (val < 480) { // move faster the lower the value from the potentiometer delayTime = 1024 * val / 512 + 1.here (Printable View of http://www. The following links may be useful for you to visit in order to understand the theory underlying behind stepper motors: .good PDF with basic information .information about the motor we are using . for (count = 3. } void loop() { val = analogRead(0). count >= 0. if (val > 540) { // move faster the higher the value from the potentiometer delayTime = 2048 .1024 * val / 512 + 1. moveForward(). we have been looking into quite a lot of documentation.pinMode(motorPins[count]. } } void moveForward() { if ((count2 == 0) || (count2 == 1)) { count2 = 16.basic explanation about steppers . } count2>>=1.here . } count2>>=1.count]. } delay(delayTime).arduino. count2>>count&0x01). count >= 0. } delay(delayTime). count--) { digitalWrite(motorPins[3 .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Cuartielles and Tomek Ness * @acknowledgements: Johny Lowgren for his DMX devices * */ int sig = 3. _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). at 03:35 PM by David A. Cuartielles * K3 . int count = 0. * Disables interrupts.cc> * <http://www. It may be also // high from before _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). int pinNumber = digitalPinToBit(pin). Assumes a 16 MHz clock. */ void shiftDmxOut(int pin. int iPinNumber = digitalPinToBit(ipin). // the first thing we do is to write te pin to high // it will be the mark between bytes. we need to turn it off .arduino. which will disrupt the millis() function if used * too frequently. if (digitalPinToPort(pin) != NOT_A_PIN) { // If the pin that support PWM output. int theByte) { int theDelay = 1. Mellis Changed lines 2-176 from: full tutorial coming soon /* DMX Shift Out * ------------* * Shifts data in DMX format out to DMX enabled devices * it is extremely restrictive in terms of timing. // signal (plus / dmx pin 3) // signal inversion (minus / dmx pin 2) /* Sends a DMX byte out on a pin.DMXMaster History Hide minor edits . int iPortNumber = port_to_output[digitalPinToPort(ipin)]. int count = 0. 2007. int sigI = 2. Therefore * the program will stop the interrupts when sending data * * (cleft) 2006 by Tomek Ness and D. int portNumber = port_to_output[digitalPinToPort(pin)]. delayMicroseconds(20).School of Arts and Communication * <http://www.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.Show changes to markup January 30. int ipin.se/k3> * * @date: 2006-01-19 * @idea: Tomek Ness * @code: D.mah.

_SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). cli(). // DMX starts with a start-bit that must always be zero _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). } delayMicroseconds(theDelay). theByte>>=1. delayMicroseconds(theDelay).// before doing a digital write. _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). } // disable interrupts. _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). theByte>>=1. _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). if (analogOutPinToBit(pin) == 1) timer1PWMAOff(). delayMicroseconds(theDelay). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). if (analogOutPinToBit(pin) == 2) timer1PWMBOff(). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). theByte>>=1. otherwise the timer 0 overflow interrupt that // tracks milliseconds will make us delay longer than we want. _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). . } delayMicroseconds(theDelay). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). } delayMicroseconds(theDelay). } delayMicroseconds(theDelay). theByte>>=1. } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber).

sei(). } delayMicroseconds(theDelay). // reenable interrupts._SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber).0). //set all adresses/channels to 60% for (count = 1. _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). delay(10). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). } void loop() { digitalWrite(sig. } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). theByte>>=1. if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). theByte>>=1. // the last thing we do is to write te pin to high // it will be the mark between bytes. LOW). HIGH). OUTPUT). } delayMicroseconds(theDelay). } } to: . } delayMicroseconds(theDelay). theByte>>=1. } delayMicroseconds(theDelay). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber).2. _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). theByte>>=1.155). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). //sending the start byte shiftDmxOut(3. _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). digitalWrite(sigI. OUTPUT). } void setup() { pinMode(sig. count<=512. _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). count++){ shiftDmxOut(3.2. pinMode(sigI. _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber).

It may be also // high from before _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). which will disrupt the millis() function if used * too frequently. otherwise the timer 0 overflow interrupt that . // signal (plus / dmx pin 3) // signal inversion (minus / dmx pin 2) /* Sends a DMX byte out on a pin. if (digitalPinToPort(pin) != NOT_A_PIN) { // If the pin that support PWM output. } // disable interrupts. delayMicroseconds(20). Therefore * the program will stop the interrupts when sending data * * (cleft) 2006 by Tomek Ness and D.229. * Disables interrupts. Restore January 19. Assumes a 16 MHz clock. int iPinNumber = digitalPinToBit(ipin). int pinNumber = digitalPinToBit(pin). int count = 0. _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber).se/k3> * * @date: 2006-01-19 * @idea: Tomek Ness * @code: D. if (analogOutPinToBit(pin) == 2) timer1PWMBOff().cc> * <http://www.178.School of Arts and Communication * <http://www. 2006. int theByte) { int theDelay = 1. // the first thing we do is to write te pin to high // it will be the mark between bytes. at 05:03 PM by 195. int iPortNumber = port_to_output[digitalPinToPort(ipin)].101 Added lines 1-176: DMX Master Device full tutorial coming soon /* DMX Shift Out * ------------* * Shifts data in DMX format out to DMX enabled devices * it is extremely restrictive in terms of timing. we need to turn it off // before doing a digital write. Cuartielles and Tomek Ness * @acknowledgements: Johny Lowgren for his DMX devices * */ int sig = 3. int ipin. int portNumber = port_to_output[digitalPinToPort(pin)]. int count = 0. int sigI = 2. */ void shiftDmxOut(int pin.Please see this updated tutorial on the playground. if (analogOutPinToBit(pin) == 1) timer1PWMAOff(). Cuartielles * K3 .arduino.mah.

} else { SFR BYTE( SFR IO8(portNumber)) &= ~ BV(pinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). // DMX starts with a start-bit that must always be zero _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). } delayMicroseconds(theDelay). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). theByte>>=1. } delayMicroseconds(theDelay). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). theByte>>=1. } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). theByte>>=1. . } delayMicroseconds(theDelay). cli(). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). theByte>>=1. _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). delayMicroseconds(theDelay). } delayMicroseconds(theDelay). delayMicroseconds(theDelay). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). } delayMicroseconds(theDelay). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). theByte>>=1.// tracks milliseconds will make us delay longer than we want.

OUTPUT). // the last thing we do is to write te pin to high // it will be the mark between bytes.2. if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). OUTPUT). } delayMicroseconds(theDelay). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). digitalWrite(sigI. pinMode(sigI. theByte>>=1. // reenable interrupts. _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). count<=512. //set all adresses/channels to 60% for (count = 1.0). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). HIGH). } void loop() { digitalWrite(sig. sei().2. LOW). theByte>>=1._SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber).155). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). //sending the start byte shiftDmxOut(3. theByte>>=1. count++){ shiftDmxOut(3. } } Restore Edit Page | Page History | Printable View | All Recent Site Changes . } delayMicroseconds(theDelay). } void setup() { pinMode(sig. } delayMicroseconds(theDelay). delay(10).

arduino.Arduino : Tutorial / DMX Master Learning Examples | Foundations | Hacking | Links DMX Master Device Please see this updated tutorial on the playground. (Printable View of http://www.cc/en/Tutorial/DMXMaster) .

} void loop() { for (mask = 00000001.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Bit masks are used to access specific bits in a byte of data. //define our transmit pin data = 170. Bitwise operations perform logical functions that take affect on the bit level. In this example the pin needs to change it's state from high to low for each bit in the byte to be transmitted. For example: x: y: x & y: 10001101 01010111 00000101 The OR (|) operator (also known as Inclusive Or) will result in a 1 at each bit position where either input values were 1. Standard bitwise operations include AND (&) OR (|) Left Shift (<<) and Right Shift (>>). For a practical example. This is accomplished using what are known as bitwise operations and a bit mask. //value to transmit. mask>0. The AND (&) operator will result in a 1 at each bit position where both input values were 1.HIGH). This is often useful as a method of iteration.OUTPUT). binary 10101010 mask = 1. For example: x: y: x | y: 10001101 01010111 11011111 The Left Shift (<<) operator will shift a value to the left the specified number of times. mask <<= 1) { //iterate through bit mask if (data & mask){ // if bitwise AND resolves to true digitalWrite(transmit. // send 1 } . void setup() { pinMode(transmit. for example when sending a byte of data serially out a single pin. The Right Shift (>>) operator works identically to left shift except that it shifts the value to the right the specified number of times For example: y = 1010 x = y >> 1 yields: x = 0101 All the bits in the byte get shifted one position to the right and the bit on the right end drops off. let's take the value 170. binary 10101010. //our bitmask bitDelay = 100. For example: y = 1010 x = y << 1 yields: x = 0100 All the bits in the byte get shifted one position to the left and the bit on the left end drops off. To pulse this value out of pin 7 the code might look as follows: byte byte byte byte transmit = 7.

Second time throught he loop the mask = 00000010. In this example we use the <<= operator which is exactly like the << operator except that it compacts the statement mask = mask << 1 into a shorter line. first time through the loop the mask = 00000001 and the value = 10101010 so our operation looks like: 00000001 & 10101010 ________ 00000000 And our output pin gets set to 0. // send 0 } delayMicroseconds(bitDelay). We then perform a bitwise AND operation on the value and the bitmask. The loop will continue to iterate through each bit in the mask until the 1 gets shifted left off the end of the 8 bits and our mask =0. shifting the value one position left each time through the loop. so our operation looks like: 00000010 & 10101010 ________ 00000010 And our output pin gets set to 1. //delay } } Here we use a FOR loop to iterate through a bit mask value. So in this example. Edit Page | Page History | Printable View | All Recent Site Changes .LOW).else{ //if bitwise and resolves to false digitalWrite(transmit. Then all 8 bits have been sent and our loop exits. This way as the bitmask shifts left through each position in the byte it will be compared against each bit in the byte we are sending sequentially and can then be used to set our output pin either high or low accordingly.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 2006. 2007. at 10:40 AM by David A. Restore September 05.SoftwareSerial History Hide minor edits . at 12:46 PM by Heather Dewey-Hagborg Changed lines 53-54 from: to: . 2006. see the SoftwareSerial library included with Arduino 0007 and later. Read on if you'd like to know how that library works. Mellis Added lines 3-4: Note: If you just want to use a software serial interface. at 12:55 PM by Heather Dewey-Hagborg Changed lines 214-216 from: }@] to: }@] code and tutorial by Heather Dewey-Hagborg Restore August 29.Show changes to markup February 26.

at 12:34 PM by Heather Dewey-Hagborg - .Changed lines 57-58 from: to: Restore August 29. 2006.

to: SWread(). Added line 32: Definitions Needed: Changed lines 34-37 from: SWprint(). SWprint(TXval2). define halfBit9600Delay 42 . define bit9600Delay 84 2. Changed line 20 from: SWprint(). to: 1. byte TXval2 = 126. 2006. RXval = SWread(). to: byte TXval = 'h'. Sends a byte long integer value out the software serial connection Added line 24: Changed lines 26-27 from: byte RXval. SWprint(TXval). at 12:25 PM by Heather Dewey-Hagborg Changed line 10 from: SWread(). RXval = SWread().Changed lines 11-12 from: Returns a byte long integer value to: Returns a byte long integer value from the software serial connection Restore August 29. to: byte RXval. Returns a byte long integer value Example: Changed lines 15-16 from: SWread(). Restore August 29. Changed lines 18-19 from: Returns a byte long integer value to: SWprint(). to: SWprint(). 2006. at 12:19 PM by Heather Dewey-Hagborg Added lines 10-13: SWread().

byte TXval2 = 126. This should be used when multiple serial connections are necessary. A tutorial on . at 12:15 PM by Heather Dewey-Hagborg Changed lines 5-6 from: other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. at 12:18 PM by Heather Dewey-Hagborg Added line 10: [@ Added line 12: @] Added line 16: [@ Changed lines 19-21 from: to: @] [@ Added line 23: @] Added lines 27-28: [@ Changed lines 33-34 from: to: @] Changed line 36 from: to: [@ Changed line 41 from: to: @] Restore August 29. SWprint(TXval). NOT a specific device tutorial. Definitions Needed: #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 Restore August 29. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial. 2006. 2006. SWprint(TXval2).3. define halfBit4800Delay 94 Deleted lines 38-55: Sends a byte long integer value out the software serial connection Example: byte TXval = 'h'. define bit4800Delay 188 4.

2006. This library is part of the Arduino install. 2006. If only one serial connection is necessary the hardware serial port should be used. SWprint(TXval2). to: First we include the file ctype. These are preprocessor directives that define the delays for different baudrates. Returns a byte long integer value Example: byte RXval. For a good explanation of serial communication see Wikipedia. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". 3. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". at 08:16 PM by Tom Igoe Changed lines 38-39 from: First we include the file ctype. . 2006.arduino. so you don't need to do anything other than type the #include line in order to use it. Restore August 23. This is a general purpose software tutorial. Device specific tutorials are on the Tutorial Page. Definitions Needed: 1.communicating with a computer is here. A tutorial on communicating with a computer is here. This should be used when multiple serial connections are necessary. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip.h in our application. to: delayMicroseconds(halfBit9600Delay). SWprint(). to: other serial devices. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. For a good explanation of serial communication see Wikipedia. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. Next we establish our baudrate delay definitions. Sends a byte long integer value out the software serial connection Example: byte TXval = 'h'. define define define define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 These definitions set the delays necessary for 9600 baud and 4800 baud software serial operation.h in our application. Device specific tutorials are on the Tutorial Page. at 02:08 PM by Heather Dewey-Hagborg Added lines 113-116: //Created July 2006 //Heather Dewey-Hagborg //http://www. Changed line 86 from: delayMicroseconds(halfbit9600Delay). Functions Available: SWread().cc Restore August 15. at 02:09 PM by Heather Dewey-Hagborg Changed line 113 from: //Created July 2006 to: //Created August 15 2006 Restore August 23. SWprint(TXval). Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip. 2. byte TXval2 = 126. These are pre-processor directives that define the delays for different baudrates. NOT a specific device tutorial. 4. Next we establish our baudrate delay definitions. RXval = SWread(). The software serial connection can run at 4800 baud or 9600 baud reliably.

2006. 2006. to: delayMicroseconds(halfBit9600Delay). Restore August 15. at 02:30 PM by Heather Dewey-Hagborg Changed lines 19-20 from: picture of device with connections to: . at 02:32 PM by Heather Dewey-Hagborg Changed lines 19-20 from: Attach: pwr_wires_web.Changed line 160 from: delayMicroseconds(halfbit9600Delay).jpg to: Restore August 15.jpg to: Changed lines 23-24 from: Attach: ser_wires_web.

at 11:40 AM by Heather Dewey-Hagborg Restore August 15. This is a general purpose software tutorial. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. For each bit we transmit we hold the line high or low for the specified delay. to: other serial devices. For a good explanation of serial communication see Wikipedia. Changed lines 27-28 from: Now we will write the code to enable serial data transmission. We will walk through the code in small sections. Finally we pull the line high again to signal a stop bit. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port.jpg Changed lines 23-24 from: picture of device with serial connections to: Attach: ser_wires_web. at 11:37 AM by Heather Dewey-Hagborg Changed line 3 from: In this tutorial you will learn how to implement serial to: In this tutorial you will learn how to implement Asynchronous serial Changed lines 5-6 from: other serial devices. 2006. In this example we are using a 9600 baudrate. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. For each bit we transmit we hold the line high or low for the specified delay. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. We will walk through the code in small sections. If only one serial connection is necessary the hardware serial port should be used. at 11:22 AM by Heather Dewey-Hagborg - . Device specific tutorials are on the Tutorial Page. at 11:42 AM by Heather Dewey-Hagborg Changed lines 78-79 from: This is the SWprint function. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page. To use 4800 simply replace the variable bit9600Delay with bit4800Delay . First the transmit line is pulled low to signal a start bit. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. NOT a specific device tutorial. Finally we pull the line high again to signal a stop bit. Restore August 15. 2006. In this example we are using a 9600 baudrate. to: Now we will write the code to enable serial data communication. If only one serial connection is necessary the hardware serial port should be used. This should be used when multiple serial connections are necessary. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. at 11:44 AM by Heather Dewey-Hagborg Restore August 15.jpg Restore August 15.Attach: pwr_wires_web. 2006. This should be used when multiple serial connections are necessary. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. 2006. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. 2006. To use 4800 simply replace the variable bit9600Delay with bit4800Delay . This is a general purpose software tutorial. NOT a specific device tutorial. A tutorial on communicating with a computer is here. to: This is the SWprint function. Restore August 15.

These are preprocessor directives that define the delays for different baudrates. to: SWprint(toupper(SWval)). First we include the file ctype. chnge them to uppercase and send them back. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. 2006. Pre-processor directives are processed before the actual compilation begins. Restore August 15. This is always a good program to run when you want to make sure a serial connection is working properly. These are pre-processor directives that define the delays for different baudrates. 2006. change them to uppercase and send them back. 2006.h to our application. This gives us access to the toupper() function from the Character Operations C library. to: Finally we implement our main program loop. Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip. Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip. at 11:19 AM by Heather Dewey-Hagborg Changed line 101 from: SWprint(to_upper(SWval)). The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Changed line 173 from: SWprint(to_upper(SWval)). First we include the file ctype. These are pre-processor directives that define the delays for different baudrates. Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip. They start with a "#" and do not end with semi-colons. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". First we include the file ctype.h in our application. Pre-processor directives are processed before the actual compilation begins. Restore August 15. These are pre-processor directives that define the delays for different baudrates. They start with a "#" and do not end with semi-colons. to: SWprint(toupper(SWval)). at 10:57 AM by Heather Dewey-Hagborg Changed lines 104-105 from: Finally we implement our main program loop. In this program we simply wait for characters to arrive. Next we establish our baudrate delay definitions. Restore August 13. to: Here we set up our pre-processor directives. to: Here we set up our pre-processor directives. Pre-processor directives are processed before the actual compilation begins. Next we establish our baudrate delay definitions. Next we establish our baudrate delay definitions. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. This is always a good program to run when you want to make sure a serial connection is working properly.h in our application. . In this program we simply wait for characters to arrive.Changed lines 36-37 from: Here we set up our pre-processor directives.h in our application. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. Next we establish our baudrate delay definitions. at 11:21 AM by Heather Dewey-Hagborg Changed lines 36-37 from: Here we import the file ctype. They start with a "#" and do not end with semi-colons.

If only one serial connection is necessary the hardware serial port should be used. //turn on debugging LED Changed lines 54-55 from: Here we initialize the lines and print a debugging message to confirm all is working as planned. to: Here we import the file ctype. at 11:03 AM by Heather Dewey-Hagborg Changed lines 5-6 from: other serial devices. to: byte tx = 7.@] byte SWval. etc. These are pre-processor directives that define the delays for different baudrates. We can pass inidvidual characters or numbers to the SWprint function. at 11:00 AM by Heather Dewey-Hagborg Changed lines 39-41 from: byte tx = 7. A tutorial on communicating with a computer is here. LCDs. Added line 126: digitalWrite(13. 2006. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. They have lots of easy to use serial modules for GPS. Device specific tutorials are on the Tutorial Page. Device specific tutorials are on the Tutorial Page. This should be used when multiple serial connections are necessary. chnge them to uppercase and send them back. NOT a specific device tutorial. This is a general purpose software tutorial. For easy copy and pasting the full program text of this tutorial is below: #include <ctype. In this program we simply wait for characters to arrive. //turn on debugging LED Restore August 13. Next we establish our baudrate delay definitions. This gives us access to the toupper() function from the Character Operations C library. This is always a good program to run when you want to make sure a serial connection is working properly.h> #define bit9600Delay 84 . This should be used when multiple serial connections are necessary.@] Added lines 102-172: Finally we implement our main program loop. to: other serial devices. NOT a specific device tutorial.h to our application. 2006. Restore August 13.h to our application. A tutorial on communicating with a computer is here. turn on our debugging LED and print a debugging message to confirm all is working as planned.HIGH). If only one serial connection is necessary the hardware serial port should be used. 2006. Added line 48: digitalWrite(13. byte SWval. Next we establish our baudrate delay definitions. For lots of fun serial devices check out the Sparkfun online catalog.Restore August 13. wi-fi. to: Here we initialize the lines. We can pass inidvidual characters or numbers to the SWprint function. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This is a general purpose software tutorial. This gives us access to the toupper() function from the standard C library.HIGH). These are pre-processor directives that define the delays for different baudrates. at 11:12 AM by Heather Dewey-Hagborg Changed lines 36-37 from: Here we import the file ctype. bluetooth.

OUTPUT). delayMicroseconds(bit9600Delay). //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfbit9600Delay). digitalWrite(tx.#define halfBit9600Delay 42 #define bit4800Delay 188 #define halfBit4800Delay 94 byte rx = 6. } //wait for stop bit + extra delayMicroseconds(bit9600Delay). //carriage return } void SWprint(int data) { byte mask. for (mask = 0x01. SWprint(10). offset < 8. } int SWread() { byte val = 0. return val. mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx. while (digitalRead(rx)). // send 1 } else{ digitalWrite(tx. SWprint('h'). //debugging hello SWprint('i'). 2006. delayMicroseconds(bit9600Delay).LOW). val |= digitalRead(rx) << offset.INPUT).LOW). } //stop bit digitalWrite(tx. byte tx = 7.HIGH).HIGH). HIGH). pinMode(tx. offset++) { delayMicroseconds(bit9600Delay). mask>0. byte SWval. } Restore August 13. } } void loop() { SWval = SWread(). // send 0 } delayMicroseconds(bit9600Delay). void setup() { pinMode(rx. SWprint(to_upper(SWval)). delayMicroseconds(bit9600Delay). //startbit digitalWrite(tx. for (int offset = 0. at 10:55 AM by Heather Dewey-Hagborg Changed lines 29-31 from: .

[@#define bit9600Delay 84 to: [@#include <ctype.h> 1. define bit9600Delay 84 Changed lines 36-37 from: Here we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. to: Here we import the file ctype.h to our application. This gives us access to the toupper() function from the standard C library. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. Changed lines 40-42 from: Here we set our transmit (tx) and recieve (rx) pins. Change the pin numbers to suit your application. to: byte SWval; Here we set our transmit (tx) and recieve (rx) pins. Change the pin numbers to suit your application. We also allocate a variable to store our recieved data in, SWval . Added lines 96-101: void loop() { SWval = SWread(); SWprint(to_upper(SWval)); } Restore August 13, 2006, at 10:48 AM by Heather Dewey-Hagborg Changed lines 78-79 from: // confirm that this is a real start bit, not line noise to: //wait for start bit Deleted lines 79-80: // frame start indicated by a falling edge and low start bit // jump to the middle of the low start bit Deleted lines 80-81: // offset of the bit in the byte: from 0 (LSB) to 7 (MSB) Deleted line 81: // jump to middle of next bit Deleted lines 82-83: // read bit Changed line 85 from: //pause for stop bit to: //wait for stop bit + extra Added line 93: Restore

August 13, 2006, at 10:47 AM by Heather Dewey-Hagborg Changed lines 5-6 from: other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. And device specific tutorials are on the Tutorial Page. to: other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page. Added lines 73-101: int SWread() { byte val = 0; while (digitalRead(rx)); // confirm that this is a real start bit, not line noise if (digitalRead(rx) == LOW) { // frame start indicated by a falling edge and low start bit // jump to the middle of the low start bit delayMicroseconds(halfbit9600Delay); // offset of the bit in the byte: from 0 (LSB) to 7 (MSB) for (int offset = 0; offset < 8; offset++) { // jump to middle of next bit delayMicroseconds(bit9600Delay); // read bit val |= digitalRead(rx) << offset; } //pause for stop bit delayMicroseconds(bit9600Delay); delayMicroseconds(bit9600Delay); return val; } } This is the SWread function. This will wait for a byte to arrive on the recieve pin and then return it to the allocated variable. First we wait for the recieve line to be pulled low. We check after a half bit delay to make sure the line is still low and we didn't just recieve line noise. Then we iterate through a bit mask and shift 1s or 0s into our output byte based on what we recieve. Finally we allow a pause for the stop bit and then return the value. Restore August 13, 2006, at 10:38 AM by Heather Dewey-Hagborg Changed lines 72-73 from: This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable "bit9600Delay" with "bit4800Delay". to: This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable bit9600Delay with bit4800Delay . Restore August 13, 2006, at 10:38 AM by Heather Dewey-Hagborg Changed line 29 from:

[@#define bit9600Delay 84 //total 104us to: [@#define bit9600Delay 84 Changed line 31 from: 1. define bit4800Delay 188 //total 208us to: 1. define bit4800Delay 188 Changed lines 34-35 from: to: Here we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. byte rx = 6; byte tx = 7; Here we set our transmit (tx) and recieve (rx) pins. Change the pin numbers to suit your application. void setup() { pinMode(rx,INPUT); pinMode(tx,OUTPUT); digitalWrite(tx,HIGH); SWprint('h'); //debugging hello SWprint('i'); SWprint(10); //carriage return } Here we initialize the lines and print a debugging message to confirm all is working as planned. We can pass inidvidual characters or numbers to the SWprint function. void SWprint(int data) { byte mask; //startbit digitalWrite(tx,LOW); delayMicroseconds(bit9600Delay); for (mask = 0x01; mask>0; mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx,HIGH); // send 1 } else{ digitalWrite(tx,LOW); // send 0 } delayMicroseconds(bit9600Delay); } //stop bit digitalWrite(tx, HIGH); delayMicroseconds(bit9600Delay); } This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable "bit9600Delay" with "bit4800Delay". Restore August 13, 2006, at 10:27 AM by Heather Dewey-Hagborg Added lines 22-36:

picture of device with serial connections
Program the Arduino

Now we will write the code to enable serial data transmission. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. We will walk through the code in small sections. #define #define #define #define bit9600Delay 84 halfBit9600Delay bit4800Delay 188 halfBit4800Delay //total 104us 42 //total 208us 94

Restore August 13, 2006, at 10:19 AM by Heather Dewey-Hagborg Changed lines 17-19 from: Insert the device you want to communicate with in the breadboard. Connect ground on the breadboard to ground from the microcontroller. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Make any other connections necessary for your device.

picture of device with connections
to: Insert the device you want to communicate with in the breadboard. Connect ground on the breadboard to ground from the microcontroller. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Make any other connections necessary for your device. Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground.

picture of device with connections
Decide which pins you want to use for transmitting and receiving. In this example we will use pin 7 for transmitting and pin 6 for receiving, but any of the digital pins should work. Restore August 13, 2006, at 10:05 AM by Heather Dewey-Hagborg Changed lines 17-19 from: Insert the device you want to communicate with in the breadboard. to: Insert the device you want to communicate with in the breadboard. Connect ground on the breadboard to ground from the microcontroller. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Make any other connections necessary for your device.

picture of device with connections
Restore August 13, 2006, at 09:51 AM by Heather Dewey-Hagborg Added lines 1-17:

Arduino Software Serial Interface
In this tutorial you will learn how to implement serial communication on the Arduino in software to communicate with other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. And device specific tutorials are on the Tutorial Page. Materials needed: Device to communicate with Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) - optional, for debugging

Prepare the breadboard

Insert the device you want to communicate with in the breadboard. Restore

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino : Tutorial / Software Serial
Learning Examples | Foundations | Hacking | Links

Arduino Software Serial Interface
Note: If you just want to use a software serial interface, see the SoftwareSerial library included with Arduino 0007 and later. Read on if you'd like to know how that library works. In this tutorial you will learn how to implement Asynchronous serial communication on the Arduino in software to communicate with other serial devices. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. This should be used when multiple serial connections are necessary. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial, NOT a specific device tutorial. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page. For a good explanation of serial communication see Wikipedia. The software serial connection can run at 4800 baud or 9600 baud reliably. Functions Available: SWread(); Returns a byte long integer value from the software serial connection Example: byte RXval; RXval = SWread(); SWprint(); Sends a byte long integer value out the software serial connection Example: byte TXval = 'h'; byte TXval2 = 126; SWprint(TXval); SWprint(TXval2); Definitions Needed: #define bit9600Delay 84 #define halfBit9600Delay 42 #define bit4800Delay 188 #define halfBit4800Delay 94 These definitions set the delays necessary for 9600 baud and 4800 baud software serial operation. Materials needed: Device to communicate with Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) - optional, for debugging

Prepare the breadboard
Insert the device you want to communicate with in the breadboard. Connect ground on the breadboard to ground from the microcontroller. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Make any other connections necessary for your device. Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground.

Decide which pins you want to use for transmitting and receiving. In this example we will use pin 7 for transmitting and pin 6 for receiving, but any of the digital pins should work.

Program the Arduino
Now we will write the code to enable serial data communication. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. We will walk through the code in small sections. #include <ctype.h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94

Here we set up our pre-processor directives. Pre-processor directives are processed before the actual compilation begins. They start with a "#" and do not end with semi-colons. First we include the file ctype.h in our application. This gives us access to the toupper() function from the Character Operations C library which we will use later in our main loop. This library is part of the Arduino install, so

you don't need to do anything other than type the #include line in order to use it. Next we establish our baudrate delay definitions. These are pre-processor directives that define the delays for different baudrates. The #define bit9600Delay 84 line causes the compiler to substitute the number 84 where ever it encounters the label "bit9600Delay". Pre-processor definitions are often used for constants because they don't take up any program memory space on the chip. byte rx = 6; byte tx = 7; byte SWval; Here we set our transmit (tx) and recieve (rx) pins. Change the pin numbers to suit your application. We also allocate a variable to store our recieved data in, SWval . void setup() { pinMode(rx,INPUT); pinMode(tx,OUTPUT); digitalWrite(tx,HIGH); digitalWrite(13,HIGH); //turn on debugging LED SWprint('h'); //debugging hello SWprint('i'); SWprint(10); //carriage return } Here we initialize the lines, turn on our debugging LED and print a debugging message to confirm all is working as planned. We can pass inidvidual characters or numbers to the SWprint function. void SWprint(int data) { byte mask; //startbit digitalWrite(tx,LOW); delayMicroseconds(bit9600Delay); for (mask = 0x01; mask>0; mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx,HIGH); // send 1 } else{ digitalWrite(tx,LOW); // send 0 } delayMicroseconds(bit9600Delay); } //stop bit digitalWrite(tx, HIGH); delayMicroseconds(bit9600Delay); } This is the SWprint function. First the transmit line is pulled low to signal a start bit. Then we itterate through a bit mask and flip the output pin high or low 8 times for the 8 bits in the value to be transmitted. Finally we pull the line high again to signal a stop bit. For each bit we transmit we hold the line high or low for the specified delay. In this example we are using a 9600 baudrate. To use 4800 simply replace the variable bit9600Delay with bit4800Delay . int SWread() { byte val = 0; while (digitalRead(rx)); //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay); for (int offset = 0; offset < 8; offset++) { delayMicroseconds(bit9600Delay); val |= digitalRead(rx) << offset; } //wait for stop bit + extra delayMicroseconds(bit9600Delay); delayMicroseconds(bit9600Delay); return val; } } This is the SWread function. This will wait for a byte to arrive on the recieve pin and then return it to the allocated variable. First we wait for the recieve line to be pulled low. We check after a half bit delay to make sure the line is

still low and we didn't just recieve line noise. Then we iterate through a bit mask and shift 1s or 0s into our output byte based on what we recieve. Finally we allow a pause for the stop bit and then return the value. void loop() { SWval = SWread(); SWprint(toupper(SWval)); } Finally we implement our main program loop. In this program we simply wait for characters to arrive, change them to uppercase and send them back. This is always a good program to run when you want to make sure a serial connection is working properly. For lots of fun serial devices check out the Sparkfun online catalog. They have lots of easy to use serial modules for GPS, bluetooth, wi-fi, LCDs, etc. For easy copy and pasting the full program text of this tutorial is below: //Created August 15 2006 //Heather Dewey-Hagborg //http://www.arduino.cc #include <ctype.h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94

byte rx = 6; byte tx = 7; byte SWval; void setup() { pinMode(rx,INPUT); pinMode(tx,OUTPUT); digitalWrite(tx,HIGH); digitalWrite(13,HIGH); //turn on debugging LED SWprint('h'); //debugging hello SWprint('i'); SWprint(10); //carriage return } void SWprint(int data) { byte mask; //startbit digitalWrite(tx,LOW); delayMicroseconds(bit9600Delay); for (mask = 0x01; mask>0; mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx,HIGH); // send 1 } else{ digitalWrite(tx,LOW); // send 0 } delayMicroseconds(bit9600Delay); } //stop bit digitalWrite(tx, HIGH); delayMicroseconds(bit9600Delay); } int SWread() { byte val = 0; while (digitalRead(rx)); //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay); for (int offset = 0; offset < 8; offset++) { delayMicroseconds(bit9600Delay); val |= digitalRead(rx) << offset; } //wait for stop bit + extra delayMicroseconds(bit9600Delay);

delayMicroseconds(bit9600Delay); return val; } } void loop() { SWval = SWread(); SWprint(toupper(SWval)); } code and tutorial by Heather Dewey-Hagborg
(Printable View of http://www.arduino.cc/en/Tutorial/SoftwareSerial)

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Tutorial.ArduinoSoftwareRS232 History
Hide minor edits - Show changes to markup September 05, 2006, at 12:56 PM by Heather Dewey-Hagborg Changed lines 144-145 from: code and tutorial by Heather Dewey-Hagborg Photos by Thomas Dexter to: code and tutorial by Heather Dewey-Hagborg, photos by Thomas Dexter Restore September 05, 2006, at 12:56 PM by Heather Dewey-Hagborg Added line 144: code and tutorial by Heather Dewey-Hagborg Restore August 29, 2006, at 12:07 PM by Heather Dewey-Hagborg Changed lines 3-4 from: In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. A general purpose software serial tutorial can be found http://www.arduino.cc/en/Tutorial/SoftwareSerial?. to: In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. A general purpose software serial tutorial can be found here. Restore August 29, 2006, at 12:06 PM by Heather Dewey-Hagborg Changed lines 3-4 from: In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. to: In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. A general purpose software serial tutorial can be found http://www.arduino.cc/en/Tutorial/SoftwareSerial?. Restore August 29, 2006, at 12:03 PM by Heather Dewey-Hagborg Changed lines 57-58 from: to: TX wires Green, RX wires Blue, +5v wires are red, GND wires are black Restore August 29, 2006, at 12:01 PM by Heather Dewey-Hagborg Changed lines 23-24 from: "+5v wires are red, GND wires are black" to: +5v wires are red, GND wires are black

Changed lines 28-29 from: to: +5v wires are red, GND wires are black Changed lines 33-34 from: to: TX wire Green, RX wire Blue, +5v wires are red, GND wires are black Restore August 29, 2006, at 11:59 AM by Heather Dewey-Hagborg Changed lines 23-24 from: to: "+5v wires are red, GND wires are black" Changed lines 59-60 from: Now we will write the code to enable serial data communication. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. Upload the follwoing code into the Arduino microcontroller module: to: Now we will write the code to enable serial data communication. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. Upload the following code into the Arduino microcontroller module: Restore August 29, 2006, at 11:55 AM by Heather Dewey-Hagborg Changed lines 22-23 from:

to:

Changed lines 26-27 from:

to:

Changed lines 30-31 from:

to: Changed lines 53-55 from: to: .

congratulations! Your serial connection is working as planned. 2006. at 02:05 PM by Heather Dewey-Hagborg Changed lines 135-137 from: If this works. 2006. You can now use your new serial/computer connection to print debugging statements from your code.cc Restore August 23. Photos by Thomas Dexter Restore August 23. You can now use your new serial/computer connection to print debugging statements from your code. 2006. and to send commands to your microcontroller.arduino.Restore August 23. at 02:09 PM by Heather Dewey-Hagborg Added lines 61-64: //Created August 23 2006 //Heather Dewey-Hagborg //http://www. at 02:03 PM by Heather Dewey-Hagborg Changed lines 35-36 from: DB9 Serial Connector Pin Diagram to: (DB9 Serial Connector Pin Diagram) Restore August 23. congratulations! Your serial connection is working as planned. to: If this works. at 02:02 PM by Heather Dewey-Hagborg Changed lines 32-33 from: Cables to: Cables Changed lines 35-36 from: ("DB9 Serial Connector Pins") to: DB9 Serial Connector Pin Diagram Changed lines 55-56 from: . and to send commands to your microcontroller. 2006.

2006. at 02:00 PM by Heather Dewey-Hagborg Added lines 34-36: ("DB9 Serial Connector Pins") Deleted lines 48-51: .Program the Arduino to: Program the Arduino Restore August 23.

at 01:58 PM by Heather Dewey-Hagborg Added lines 43-44: Added line 48: Added line 55: Restore August 23. 2006. 2006.Restore August 23. at 01:55 PM by Heather Dewey-Hagborg Changed lines 22-23 from: PICTURE to: Changed lines 26-27 from: PICTURE to: .

. Connect the ground line from your computer to ground on the breadboard. PICTURE to: Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT).Changed lines 30-31 from: PICTURE to: Changed lines 48-52 from: Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT).

Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Added lines 24-27: Connect a 1uF capacitor across pins 1 and 3. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground). PICTURE Restore August 23. If you are using an LED connect it between pin 13 and ground. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground).Restore August 23. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller.11 to 5V. Changed lines 9-10 from: MAX233 chip (or similar) 1uf polarized capacitor to: MAX3323 chip (or similar) 4 1uf capacitors Changed lines 18-21 from: . to: Insert the MAX3323 chip in the breadboard. 2006. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 . to: In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. at 01:01 PM by Heather Dewey-Hagborg Changed lines 3-4 from: In this tutorial you will learn how to communicate with a computer using a MAX233 multichannel RS-232 driver/receiver and a software serial connection on the Arduino. another between pin 1 and ground. and the last between pin 6 and ground. Connect a 1uF capacitor across pins 1 and 3. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 . another across pins 4 and 5. at 01:11 PM by Heather Dewey-Hagborg Changed lines 20-21 from: Insert the MAX3323 chip in the breadboard. 2006.11 to 5V. another between pin 1 and ground. and the last between pin 6 and ground. another across pins 4 and 5.

Connect your TX pin (7) to MAX233 pin 2 (T1IN).11 to 5V. Connect the 1uF capacitor across pins 6 and 7 so that the negative pin connects to pin 6 and the positive pin to pin 7. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Changed lines 24-27 from: The MAX233 chip has two sets of RS-232 line shifters built in and can handle two simultaneous duplex serial ports. R1IN and R1OUT in the MAX233 schematic. another across pins 4 and 5. Connect your RX pin . to: Insert the MAX3323 chip in the breadboard. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. Connect pin 10 to pin 16 pin 11 to pin 15 and pin 12 to pin 17 on the breadboard. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. with corresponding pins referred to as T1IN. For the purposes of this tutorial we will only being using one port. T1OUT. Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. and the last between pin 6 and ground. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground). Connect a 1uF capacitor across pins 1 and 3.Insert the MAX233 chip in the breadboard. Connect pin 6 and pin 9 on the MAX233 chip to ground and pin 7 to 5V. another between pin 1 and ground. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 .

Changed lines 44-45 from: Connect the TX line from your computer to pin 4 (R1IN) on the MAX233 and the RX line to pin 5 (T1OUT). Pick three different colors of wire. Added lines 35-37: Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Added lines 39-40: Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port. . you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. one for RX. Heatshrink the wire connections to avoid accidental shorts. Connect your RX pin (6) to MAX3323 pin 9 (R1OUT). 2006. 2006. one for RX. Solder your TX wire to pin 2 of the DB9 connector. Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port.(6) to MAX233 pin 3 (R1OUT). at 01:06 PM by Heather Dewey-Hagborg Restore August 17. To do this. Heatshrink the wire connections to avoid accidental shorts. Solder your TX wire to pin 2 of the DB9 connector. RX wire to pin 3 and Ground to pin 5. To do this. to: Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. Pick three different colors of wire. to: If you do not have one already. Connect your TX pin (7) to MAX3323 pin 10 (T1IN). pick up a female DB9 connector from radioshack. one for TX. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. at 01:05 PM by Heather Dewey-Hagborg Changed lines 32-34 from: If you do not have one already. Restore August 17. to: Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT). pick up a female DB9 connector from radioshack. one for TX. and one for ground. you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. RX wire to pin 3 and Ground to pin 5. and one for ground. Connect pins 1 and 6 to pin 4 and pin 7 to pin 8.

at 01:02 PM by Heather Dewey-Hagborg Added lines 30-31: Cables Changed lines 35-36 from: PICTURE connector soldered.Changed lines 42-44 from: PICTURE in back shell to: Restore August 17. to: . 2006.

the free pre-installed windows terminal application. Here are two shots of what it might look like. Here is a shot of what it should look like in Hyperterminal. no hardware flow control. Press the reset button on the arduino board. The word "hi" should appear in the terminal window followed by an advancement to the next line. one in Hyperterminal the free pre-installed windows terminal application. another free application with more advanced options. Changed lines 115-116 from: . to: Open up your serial terminal program and set it to 9600 baud. 1 stop bit. Press the reset button on the arduino board. in back shell to: PICTURE connector soldered. 8 data bits. at 10:45 AM by Heather Dewey-Hagborg Changed lines 112-113 from: Open up your serial terminal program and set it to 9600 baud. 2006. 2006. 8 data bits. 1 stop bit.Restore August 17. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. and one in Realterm. no parity. at 01:01 PM by Heather Dewey-Hagborg Changed lines 34-35 from: PICTURE connector soldered. no parity. PICTURE in back shell Restore August 17. no hardware flow control.

You should see the letter you typed return to you in uppercase. and one in Realterm. Press the reset button on the arduino board. no parity. try typing a lowercase character into the terminal window. and one in Realterm. to: Open up your serial terminal program and set it to 9600 baud. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. no hardware flow control. at 10:43 AM by Heather Dewey-Hagborg Changed lines 112-113 from: Open up your serial terminal program and set it to 9600 baud. no hardware flow control. 2006. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. Here are two shots of what it might look like. 8 data bits. 8 data bits. Press the reset button on the arduino board. 1 stop bit. one in Hyperterminal the free pre-installed windows terminal application. . 1 stop bit.to: Restore August 17. another free application with more options. Here are two shots of what it might look like. another free application with more advanced options. Added lines 117-121: Now. no parity. one in Hyperterminal the free pre-installed windows terminal application.

You can now use your new serial/computer connection to print debugging statements from your code. 1 stop bit. no hardware flow control. no hardware flow control. The word "hi" should appear in the terminal window followed by a line feed character and an advancement to the next line. to: Open up your serial terminal program and set it to 9600 baud. and one in Realterm. at 10:26 AM by Heather Dewey-Hagborg Changed lines 112-116 from: Open up your serial terminal program and set it to 9600 baud. Press the reset button on the arduino board. and to send commands to your microcontroller. Here are two shots of what it might look like. 8 data bits. 2006. no parity. Restore August 17. one in Hyperterminal the free pre-installed windows terminal application. 1 stop bit.If this works. another free application with more options. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. no parity. . 8 data bits. congratulations! Your serial connection is working as planned. Press the reset button on the arduino board.

no hardware flow control. one for TX. RX wire to pin 3 and Ground to pin 5. Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port. Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Solder your TX wire to pin 2 of the DB9 connector. Restore August 17. Restore August 17. Solder your TX wire to pin 2 of the DB9 connector. pick up a female DB9 connector from radioshack. Heatshrink the wire connections to avoid accidental shorts. at 10:01 AM by Heather Dewey-Hagborg Changed line 9 from: . 8 data bits. Press the reset button on the arduino board. Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Pick three different colors of wire. 2006. and one for ground. To do this. 1 stop bit. one for TX. Heatshrink the wire connections to avoid accidental shorts. Pick three different colors of wire. you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. pick up a female DB9 connector from radioshack.Restore August 17. no parity. at 10:02 AM by Heather Dewey-Hagborg Changed lines 30-31 from: If you do not have one already. to: If you do not have one already. and one for ground. 2006. one for RX. you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. 2006. at 10:19 AM by Heather Dewey-Hagborg Changed line 34 from: PICTURE connector soldered to: PICTURE connector soldered. one for RX. in back shell Changed lines 110-112 from: @] to: @] Open up your serial terminal program and set it to 9600 baud. To do this. The word "hi" should appear in the terminal window followed by a line feed character and an advancement to the next line. RX wire to pin 3 and Ground to pin 5.

//wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay). digitalWrite(tx. HIGH). digitalWrite(13. offset < 8. This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port. // send 0 } delayMicroseconds(bit9600Delay). } //stop bit digitalWrite(tx. //startbit digitalWrite(tx. // send 1 } else{ digitalWrite(tx. SWprint(10).HIGH).LOW). offset++) { delayMicroseconds(bit9600Delay). .INPUT). byte tx = 7.HIGH).HIGH). void setup() { pinMode(rx. while (digitalRead(rx)). This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs.OUTPUT).MAX233 chip to: MAX233 chip (or similar) Added lines 40-110: Program the Arduino Now we will write the code to enable serial data communication. pinMode(tx. val |= digitalRead(rx) << offset. for (int offset = 0. delayMicroseconds(bit9600Delay). Upload the follwoing code into the Arduino microcontroller module: #include <ctype. //carriage return } void SWprint(int data) { byte mask. //turn on debugging LED SWprint('h'). //debugging hello SWprint('i'). mask>0. for (mask = 0x01. delayMicroseconds(bit9600Delay). } int SWread() { byte val = 0. mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx. byte SWval.LOW).h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 byte rx = 6.

you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard.} //wait for stop bit + extra delayMicroseconds(bit9600Delay). Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. Solder your TX wire to pin 2 of the DB9 connector. PICTURE connector soldered Restore August 15. one for RX. Instructions for doing this can be found . you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. return val. at 04:17 PM by Heather Dewey-Hagborg Changed lines 18-19 from: . } } void loop() { SWval = SWread(). SWprint(toupper(SWval)). Heatshrink the wire connections to avoid accidental shorts. and one for ground. RX wire to pin 3 and Ground to pin 5. } Restore August 15. one for TX. To do this. at 04:37 PM by Heather Dewey-Hagborg Changed lines 30-31 from: If you do not have one already. 2006. delayMicroseconds(bit9600Delay). 2006. Pick three different colors of wire. to: If you do not have one already. pick up a female DB9 connector from radioshack.

2006.jpg Δ to: PICTURE Changed lines 28-29 from: Attach:rs232ttl_web.to: Restore August 15.jpg Δ . at 03:53 PM by Heather Dewey-Hagborg Changed lines 22-23 from: Attach:rs232pwr_web.

In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. Connect pin 10 to pin 16 pin 11 to pin 15 and pin 12 to pin 17 on the breadboard. Attach:rs232pwr_web.optional.jpg Δ The MAX233 chip has two sets of RS-232 line shifters built in and can handle two simultaneous duplex serial ports. with corresponding pins referred to as T1IN. For the purposes of this tutorial we will only being using one port. for debugging to: Light emitting Diode (LED) . Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. for debugging Prepare the breadboard Insert the MAX233 chip in the breadboard. Connect your RX pin (6) to MAX233 pin 3 (R1OUT).to: PICTURE Added lines 32-35: Connect the TX line from your computer to pin 4 (R1IN) on the MAX233 and the RX line to pin 5 (T1OUT). R1IN and R1OUT in the MAX233 schematic. Connect the 1uF capacitor across pins 6 and 7 so that the negative pin connects to pin 6 and the positive pin to pin 7. at 03:49 PM by Heather Dewey-Hagborg Added line 6: Added line 8: Serial-Breadboard cable Changed lines 14-31 from: Light emitting Diode (LED) . T1OUT.optional. Connect pin 6 and pin 9 on the MAX233 chip to ground and pin 7 to 5V. 2006. PICTURE Restore August 15. Connect your TX pin (7) to MAX233 pin 2 (T1IN). Attach:rs232ttl_web.jpg Δ .

HyperTerminal or RealTerm on the PC. Zterm on Mac) MAX233 chip 1uf polarized capacitor Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . for debugging Restore Edit Page | Page History | Printable View | All Recent Site Changes . 2006.optional. Instructions for doing this can be found . 2006. you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. Zterm on Mac) MAX233 chip 1uf polarized capacitor Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . Restore August 15. HyperTerminal or RealTerm on the PC.optional. at 03:23 PM by Heather Dewey-Hagborg Changed lines 6-13 from: * * * * * * * to: Computer with a terminal program installed (ie. Materials needed: * * * * * * * Computer with a terminal program installed (ie. at 03:22 PM by Heather Dewey-Hagborg Added lines 1-13: Computer with a terminal program installed (ie. for debugging Restore August 15. for debugging RS-232 In this tutorial you will learn how to communicate with a computer using a MAX233 multichannel RS-232 driver/receiver and a software serial connection on the Arduino.optional. HyperTerminal or RealTerm on the PC.If you do not have one already. Zterm on Mac) MAX233 chip 1uf polarized capacitor Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) .

11 to 5V.optional. for debugging Prepare the breadboard Insert the MAX3323 chip in the breadboard.Arduino : Tutorial / Arduino Software RS 232 Learning Examples | Foundations | Hacking | Links RS-232 In this tutorial you will learn how to communicate with a computer using a MAX3323 single channel RS-232 driver/receiver and a software serial connection on the Arduino. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 . Materials needed: Computer with a terminal program installed (ie. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. A general purpose software serial tutorial can be found here. If you are using an LED connect it between pin 13 and ground. HyperTerminal or RealTerm on the PC. Zterm on Mac) Serial-Breadboard cable MAX3323 chip (or similar) 4 1uf capacitors Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . .

GND wires are black Connect a 1uF capacitor across pins 1 and 3. +5v wires are red. GND wires are black Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. Connect your RX pin (6) to MAX3323 pin 9 (R1OUT). another across pins 4 and 5. Connect your TX pin (7) to MAX3323 pin 10 (T1IN).+5v wires are red. and the last between pin 6 and ground. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. . another between pin 1 and ground. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground).

and one for ground. RX wire to pin 3 and Ground to pin 5. pick up a female DB9 connector from radioshack. you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. one for RX. +5v wires are red. GND wires are black Cables (DB9 Serial Connector Pin Diagram) If you do not have one already. Pick three different colors of wire. . RX wire Blue. Solder your TX wire to pin 2 of the DB9 connector.TX wire Green. one for TX. To do this.

Connect the ground line from your computer to ground on the breadboard. Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT). . Heatshrink the wire connections to avoid accidental shorts. Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port.Connect pins 1 and 6 to pin 4 and pin 7 to pin 8.

byte SWval. delayMicroseconds(bit9600Delay).INPUT). // send 1 } else{ digitalWrite(tx.TX wires Green. void setup() { pinMode(rx. This is a good general purpose serial debugging program and you should be able to extrapolate from this example to cover all your basic serial needs. //startbit digitalWrite(tx. +5v wires are red. //carriage return } void SWprint(int data) { byte mask. Upload the following code into the Arduino microcontroller module: //Created August 23 2006 //Heather Dewey-Hagborg //http://www.HIGH).HIGH).HIGH). HIGH). for (mask = 0x01. } //stop bit digitalWrite(tx. byte tx = 7. RX wires Blue. // send 0 } delayMicroseconds(bit9600Delay). GND wires are black Program the Arduino Now we will write the code to enable serial data communication. digitalWrite(tx. . mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx.cc #include <ctype. delayMicroseconds(bit9600Delay).LOW). digitalWrite(13. mask>0. pinMode(tx.LOW).h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 byte rx = 6. //turn on debugging LED SWprint('h'). This program will simply wait for a character to arrive in the serial recieving port and then spit it back out in uppercase out the transmit port.arduino.OUTPUT). SWprint(10). //debugging hello SWprint('i').

SWprint(toupper(SWval)).} int SWread() { byte val = 0. offset++) { delayMicroseconds(bit9600Delay). } } void loop() { SWval = SWread(). try typing a lowercase character into the terminal window. return val. val |= digitalRead(rx) << offset. You should see the letter you typed return to you in uppercase. } Open up your serial terminal program and set it to 9600 baud. 8 data bits. The word "hi" should appear in the terminal window followed by an advancement to the next line. 1 stop bit. . delayMicroseconds(bit9600Delay). no parity. Press the reset button on the arduino board. Here is a shot of what it should look like in Hyperterminal. for (int offset = 0. the free preinstalled windows terminal application. no hardware flow control. } //wait for stop bit + extra delayMicroseconds(bit9600Delay). Now. while (digitalRead(rx)). //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay). offset < 8.

code and tutorial by Heather Dewey-Hagborg.arduino. congratulations! Your serial connection is working as planned. photos by Thomas Dexter (Printable View of http://www.cc/en/Tutorial/ArduinoSoftwareRS232) . You can now use your new serial/computer connection to print debugging statements from your code. and to send commands to your microcontroller.If this works.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

The Master line for sending data to the peripherals. at 11:30 AM by Heather Dewey-Hagborg Changed lines 16-17 from: Master In Slave Out (MISO) . Arduino Microcontroller Module to: AT25HP512 Serial EEPROM chip (or similar) Hookup wire Arduino Microcontroller Module Restore September 05. and the steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. Restore September 06. so follow this tutorial only if you need more space than it provides. Master Out Slave In (MOSI) . Master Out Slave In (MOSI) . at 12:57 PM by Heather Dewey-Hagborg Changed lines 329-331 from: @] to: @] code and tutorial by Heather Dewey-Hagborg. and the steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. AT25HP512 Serial EEPROM chip (or similar) 2. at 01:19 PM by Heather Dewey-Hagborg Changed lines 70-71 from: . EEPROM chips such as this are very useful for data storage.The Master line for sending data to the peripherals. Mellis . 2006.SPIEEPROM History Hide minor edits .adding note about internal eeprom on arduino Changed lines 3-4 from: In this tutorial you will learn how to interface with an AT25HP512 Atmel serial EEPROM using the Serial Peripheral Interface (SPI) protocol.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. Hookup wire 3. 2006. EEPROM chips such as this are very useful for data storage. to: In this tutorial you will learn how to interface with an AT25HP512 Atmel serial EEPROM using the Serial Peripheral Interface (SPI) protocol.The Slave line for sending data to the master. at 03:38 PM by Heather Dewey-Hagborg Changed lines 7-10 from: 1. at 04:30 PM by David A.The Slave line for sending data to the master. 2006. 2006.Show changes to markup October 07. photos by Thomas Dexter Restore August 31. Restore September 06. 2006. to: Master In Slave Out (MISO) . Note that the chip on the Arduino board contains an internal EEPROM.

to: Connect EEPROM pin 1 to Arduino pin 10 (Slave Select . MOSI wire is blue. SCK wire is green Restore August 31. Restore August 31. and EEPROM pin 6 to Arduino pin 13 (Serial Clock). 2006. GND wires are black Changed lines 73-74 from: to: SS wire is white. at 01:13 PM by Heather Dewey-Hagborg Changed lines 67-68 from: PICTURE of pwr wires to: Changed lines 71-72 from: PICTURE of SPI wires to: . MISO wire is yellow.MISO).MOSI).SCK). EEPROM pin 5 to Arduino pin 11 (Master Out Slave In .SS). EEPROM pin 2 to Arduino pin 12 (Master In Slave Out). at 01:17 PM by Heather Dewey-Hagborg Changed lines 68-69 from: to: +5v wires are red. 2006. EEPROM pin 2 to Arduino pin 12 (Master In Slave Out . EEPROM pin 5 to Arduino pin 11 (Master Out Slave In). and EEPROM pin 6 to Arduino pin 13 (Serial Clock .Connect EEPROM pin 1 to Arduino pin 10 (Slave Select).

Most Significant Bit first. up to 128 times for a full page of data: Restore . at 11:05 AM by Heather Dewey-Hagborg Changed lines 180-182 from: This function simply fills our data array with numbers 0 .127 for each index in the array. First we set the SLAVESELECT line low to enable the device.Restore August 30. Most Significant Bit first. It then returns any data that has been shifted in to the data register by the EEPROM: to: The spi_transfer function loads the output data into the data transmission register. at 11:08 AM by Heather Dewey-Hagborg Changed lines 2-3 from: (IN PROGRESS) to: Restore August 30. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). Finally we pull the SLAVESELECT line high again to release the device after reading one byte. and return the data. thus starting the SPI transmission. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. Then we transmit a READ instruction. An explanation of bit masks can be found here. thus starting the SPI transmission. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. up to 128 times for a full page of data: to: The read_eeprom function allows us to read data back out of the EEPROM. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. followed by the 16-bit address we wish to read from. Then we transmit a READ instruction. It then returns any data that has been shifted in to the data register by the EEPROM: Changed lines 203-204 from: This function allows us to read data back out of the EEPROM. 2006. An explanation of bit masks can be found here. and return the data. First we set the SLAVESELECT line low to enable the device. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. followed by the 16-bit address we wish to read from. 2006. SPIF.127 for each index in the array. This function could easily be changed to fill the array with data relevant to your application: Changed lines 191-192 from: This function loads the output data into the data transmission register. SPIF. This function could easily be changed to fill the array with data relevant to your application: to: The fill_buffer function simply fills our data array with numbers 0 .

After setting our control register up we read the SPI status register (SPSR) and data register (SPDR) in to the junk clr variable to clear out any spurious data from past runs: Changed lines 131-133 from: Now we set the SPI Control register (SPCR) to the binary value 01010000. To send the instruction we pull the SLAVESELECT line low. the sixth bit chooses transmission with the most significant bit going first. Note that we use the WREN opcode we defined at the beginning of the program. The EEPROM MUST be write enabled before every write instruction. The EEPROM MUST be write enabled before every write instruction. Then we define our opcodes for the EEPROM. They start with a "#" and do not end with semi-colons. Note that we use the WREN opcode we defined at the beginning of the program. enabling the device. this is a 128 byte array we will be using to store the data for the EEPROM write: Changed lines 106-107 from: Here we allocate the global variables we will be using later in the program. the sixth bit chooses transmission with the most significant bit going first. Finally we pull the SLAVESELECT line high again to release it: Changed lines 141-142 from: Here we fill our data array with numbers and send a write enable instruction to the EEPROM. Opcodes are control commands. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). This deselects the device and avoids any false transmission messages due to line noise: Changed lines 119-120 from: First we initialize our serial connection. In the control register each bit sets a different functionality. Finally we pull the SLAVESELECT line high again to release it. set our input and output pin modes and set the SLAVESELECT line high to start. to: First we initialize our serial connection. 2006. SPICLOCK and SLAVESELECT. After setting our control register up we read the SPI status register (SPSR) and data register (SPDR) in to the junk clr variabl to clear out any spurious data from past runs. to: Now we pull the SLAVESELECT line low to select the device again after a brief delay. We define the pins we will be using for our SPI connection. this is a 128 byte array we will be using to store the data for the EEPROM write. The eighth bit disables the SPI interrupt. the fourth bit sets the data clock idle when it is low. . the fourth bit sets the data clock idle when it is low. . Opcodes are control commands: Changed lines 96-99 from: Here we set up our pre-processor directives. to: Now we set the SPI Control register (SPCR) to the binary value 01010000. set our input and output pin modes and set the SLAVESELECT line high to start. to: Here we allocate the global variables we will be using later in the program. DATAOUT. the third bit sets the SPI to sample data on the rising edge of the data clock. at 11:05 AM by Heather Dewey-Hagborg Added lines 78-81: The first step is setting up our pre-processor directives. DATAIN. To send the instruction we pull the SLAVESELECT line low. DATAIN.August 30. The eighth bit disables the SPI interrupt. the seventh bit enables the SPI. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). Then we define our opcodes for the EEPROM. and then send the instruction using the spi_transfer function. In the control register each bit sets a different functionality. Pre-processor directives are processed before the actual compilation begins. Note char buffer [128]. and then send the instruction using the spi_transfer function. This deselects the device and avoids any false transmission messages due to line noise. First we define the pins we will be using for our SPI connection. the third bit sets the SPI to sample data on the rising edge of the data clock. to: Here we fill our data array with numbers and send a write enable instruction to the EEPROM. SPICLOCK and SLAVESELECT. DATAOUT. the fifth bit puts the Arduino in Master mode. Pre-processor directives are processed before the actual compilation begins. the fifth bit puts the Arduino in Master mode. We send a WRITE instruction to tell the . They start with a "#" and do not end with semi-colons. the seventh bit enables the SPI. enabling the device. Note char buffer [128].

Each time through the loop we increment the eeprom address to read. We send a WRITE instruction to tell the EEPROM we will be sending data to record into memory. and return the data. to: This function loads the output data into the data transmission register. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. We add a line feed and a pause for readability. Next we send our 128 bytes of data from our buffer array. Most Significant Bit first. one byte after another without pause. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. This way if our data comes out looking funny later on we can tell it isn't just the serial port acting up: Changed lines 168-169 from: We end the setup function by sending the word "hi" plus a line feed out the built in serial port for debugging purposes. This way if our data comes out looking funny later on we can tell it isn't just the serial port acting up. Most Significant Bit first. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). up to 128 times for a full page of data: Changed lines 220-222 from: This function allows us to read data back out of the EEPROM. to: In our main loop we just read one byte at a time from the EEPROM and print it out the serial port. Most Significant Bit first. to: This function allows us to read data back out of the EEPROM. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). to: . Then we transmit a READ instruction. one byte after another without pause. SPIF. When the address increments to 128 we turn it back to 0 because we have only filled 128 addresses in the EEPROM with data: Changed lines 181-182 from: In our main loop we just read one byte at a time from the EEPROM and print it out the serial port. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. up to 128 times for a full page of data. Next we send our 128 bytes of data from our buffer array. We send the 16 bit address to begin writing at in two bytes. When the address increments to 128 we turn it back to 0 because we have only filled 128 addresses in the EEPROM with data. Each time through the loop we increment the eeprom address to read. An explanation of bit masks can be found here. First we set the SLAVESELECT line low to enable the device. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. SPIF. Finally we set the SLAVESELECT pin high to release the device and pause to allow the EEPROM to write the data: Changed lines 159-160 from: Now we pull the SLAVESELECT line low to select the device again after a brief delay. It then returns any data that has been shifted in to the data register by the EEPROM: Changed lines 204-205 from: This function loads the output data into the data transmission register. to: This function simply fills our data array with numbers 0 . An explanation of bit masks can be found here. thus starting the SPI transmission. and return the data. It then returns any data that has been shifted in to the data register by the EEPROM.127 for each index in the array. We add a line feed and a pause for readability. First we set the SLAVESELECT line low to enable the device. thus starting the SPI transmission. to: We end the setup function by sending the word "hi" plus a line feed out the built in serial port for debugging purposes. Finally we set the SLAVESELECT pin high to release the device and pause to allow the EEPROM to write the data. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. Most Significant Bit first. followed by the 16-bit address we wish to read from. This function could easily be changed to fill the array with data relevant to your application: Changed lines 192-193 from: This function simply fills our data array with numbers 0 . Then we transmit a READ instruction. This function could easily be changed to fill the array with data relevant to your application. followed by the 16-bit address we wish to read from.127 for each index in the array. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask.EEPROM we will be sending data to record into memory. We send the 16 bit address to begin writing at in two bytes.

DEC). The following setup function is long so we will take it in parts. SPIF.I<128. . // return the received byte } This function loads the output data into the data transmission register. }@] Changed line 169 from: byte read_eeprom(int EEPROM_address) to: void loop() Changed lines 171-179 from: //READ EEPROM int data. Serial. to: eeprom_output_data = read_eeprom(address). [@ void setup() { Changed lines 163-164 from: delay(1000).LOW). at 11:01 AM by Heather Dewey-Hagborg Changed line 107 from: void fill_buffer() to: void setup() Deleted lines 108-132: for (int I=0. thus starting the SPI transmission. //send MSByte address first spi_transfer((char)(EEPROM_address)). char spi_transfer(volatile char data) { SPDR = data. It then returns any data that has been shifted in to the data register by the EEPROM. } } @] This function simply fills our data array with numbers 0 .Restore August 30. signal end transfer return data.I++) { buffer[I]=I. //send LSByte address data = spi_transfer(0xFF). An explanation of bit masks can be found here. spi_transfer(READ). digitalWrite(SLAVESELECT. 2006.127 for each index in the array.HIGH). return SPDR. This function could easily be changed to fill the array with data relevant to your application. //transmit read opcode spi_transfer((char)(EEPROM_address>>8)). //release chip. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait for the end of the transmission { }. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask.print(eeprom_output_data. //get data byte digitalWrite(SLAVESELECT.@] to: delay(1000).

Each time through the loop we increment the eeprom address to read. When the address increments to 128 we turn it back to 0 because we have only filled 128 addresses in the EEPROM with data. When the address increments to 128 we turn it back to 0 because we have only filled 128 addresses in the EEPROM with data. 6. address++. For easy copy and pasting the full program text of this tutorial is below: to: This function simply fills our data array with numbers 0 . 4. int address=0. .Serial. 2. Changed lines 192-212 from: 1.DEC). Serial. byte eeprom_input_data=0. 2. delay(500). 3. //pause for readability Changed lines 178-179 from: This function allows us to read data back out of the EEPROM.I<128. Changed line 181 from: void loop() to: void fill_buffer() Changed lines 183-187 from: eeprom_output_data = read_eeprom(address). Serial. to: In our main loop we just read one byte at a time from the EEPROM and print it out the serial port.BYTE). 4. and return the data. We add a line feed and a pause for readability.I++) { buffer[I]=I. address++.BYTE). Each time through the loop we increment the eeprom address to read. delay(500). We add a line feed and a pause for readability. //data buffer char buffer [128]. Then we transmit a READ instruction.print('\n'. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). the simplest function in the program! Here we just read one byte at a time from the EEPROM and print it out the serial port. followed by the 16-bit address we wish to read from. First we set the SLAVESELECT line low to enable the device.print(eeprom_output_data.127 for each index in the array.print('\n'. byte clr. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. define define define define define define WREN 6 WRDI 4 RDSR 5 WRSR 1 READ 3 WRITE 2 byte eeprom_output_data. define define define define DATAOUT 11//MOSI DATAIN 12//MISO SPICLOCK 13//sck SLAVESELECT 10//ss //opcodes 1. This function could easily be changed to fill the array with data relevant to your application. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. 3. Most Significant Bit first. 5. //pause for readability to: for (int I=0. } Changed lines 189-193 from: Finally we get to our main loop. up to 128 times for a full page of data.

OUTPUT). //write enable // Start the transmission // Wait the end of the transmission // Start the transmission // Wait for the end of the transmission . pinMode(SPICLOCK. INPUT). pinMode(DATAOUT. thus starting the SPI transmission.I++) to: SPDR = data. clr=SPSR. digitalWrite(SLAVESELECT. [@ byte read_eeprom(int EEPROM_address) Changed lines 206-222 from: Serial. //fill eeprom w/ buffer to: //READ EEPROM int data.msb 1st. clr=SPDR. pinMode(SLAVESELECT.system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR). SPIF. An explanation of bit masks can be found here. while (!(SPSR & (1<<SPIF))) { Changed lines 199-201 from: } void setup() to: }@] This function loads the output data into the data transmission register. It then returns any data that has been shifted in to the data register by the EEPROM. } } char spi_transfer(volatile char data) { SPDR = data.clk low when idle. //disable device // SPCR = 01010000 //interrupt disabled.void fill_buffer() to: char spi_transfer(volatile char data) Changed lines 194-195 from: for (int I=0. while (!(SPSR & (1<<SPIF))) Deleted lines 196-204: buffer[I]=I. //fill buffer with data fill_buffer(). OUTPUT).HIGH). //sample on leading edge of clk.I<128.spi enabled. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. Deleted lines 208-234: spi_transfer(WREN).begin(9600). delay(10).OUTPUT).master. pinMode(DATAIN.

Serial. 5. //release chip //wait for eeprom to finish writing delay(3000).DEC). //write data byte } digitalWrite(SLAVESELECT.print('\n'. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. Serial.digitalWrite(SLAVESELECT. delay(500). spi_transfer(WRITE). delay(10). Serial.BYTE).LOW). and return the data. address++. 2.I<128. spi_transfer((char)(address>>8)). Serial. //write instruction address=0.print('h'. //send MSByte address first spi_transfer((char)(address)). Changed lines 215-228 from: } void loop() { eeprom_output_data = read_eeprom(address).print('i'.I++) { spi_transfer(buffer[I]).print('\n'. 4. digitalWrite(SLAVESELECT.BYTE). If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). define define define define DATAOUT 11//MOSI DATAIN 12//MISO SPICLOCK 13//sck SLAVESELECT 10//ss //opcodes 1. 3. First we set the SLAVESELECT line low to enable the device. digitalWrite(SLAVESELECT. Most Significant Bit first.print(eeprom_output_data.LOW). Serial. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. followed by the 16-bit address we wish to read from. define define define define define WREN 6 WRDI 4 RDSR 5 WRSR 1 READ 3 . up to 128 times for a full page of data.//debug delay(1000).BYTE). //send LSByte address //write 128 bytes for (int I=0. //pause for readability } @] to: } @] This function allows us to read data back out of the EEPROM.HIGH). Then we transmit a READ instruction.HIGH). if (address == 128) address = 0. 3. For easy copy and pasting the full program text of this tutorial is below: Added lines 223-327: 1.BYTE). } byte read_eeprom(int EEPROM_address) { //READ EEPROM int data. 4. 2.

OUTPUT).I++) { buffer[I]=I. spi_transfer((char)(address>>8)).6.I<128. //release chip //wait for eeprom to finish writing delay(3000). //write data byte } digitalWrite(SLAVESELECT. delay(10). int address=0. spi_transfer(WRITE). pinMode(SLAVESELECT. digitalWrite(SLAVESELECT. spi_transfer(WREN).LOW). clr=SPSR.OUTPUT). OUTPUT). byte eeprom_input_data=0. //sample on leading edge of clk. void fill_buffer() { for (int I=0.print('\n'.HIGH). return SPDR.BYTE).BYTE). INPUT).HIGH).I++) { spi_transfer(buffer[I]).begin(9600). } } char spi_transfer(volatile char data) { SPDR = data. //fill eeprom w/ buffer digitalWrite(SLAVESELECT.print('h'.system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR). digitalWrite(SLAVESELECT. delay(10).LOW).BYTE). clr=SPDR.//debug delay(1000). } byte read_eeprom(int EEPROM_address) { //READ EEPROM // Start the transmission // Wait the end of the transmission // return the received byte . byte clr. //send LSByte address //write 128 bytes for (int I=0.master. Serial. //fill buffer with data fill_buffer(). pinMode(DATAOUT. while (!(SPSR & (1<<SPIF))) { }. pinMode(DATAIN. Serial. //write instruction address=0. //write enable digitalWrite(SLAVESELECT. } void setup() { Serial.clk low when idle.print('i'.spi enabled.I<128.msb 1st. Serial. //disable device // SPCR = 01010000 //interrupt disabled. pinMode(SPICLOCK.HIGH). define WRITE 2 byte eeprom_output_data. //data buffer char buffer [128]. //send MSByte address first spi_transfer((char)(address)).

Instructions are sent as 8 bit operational codes (opcodes) and are shifted in on the rising edge of the data clock. let's take a look at the details of the EEPROM chip.print('\n'. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. let's take a look at the EEPROM chip. Serial. //send LSByte address data = spi_transfer(0xFF). Changed lines 154-155 from: After setting our control register up we clear any spurious data from the Status and Control registers.DEC). Changed lines 127-128 from: This function loads the output data into the data transmission register. to: The device is enabled by pulling the Chip Select (CS) pin low. Serial. 2006. //transmit read opcode spi_transfer((char)(EEPROM_address>>8)). so a 10ms pause should follow each EEPROM write routine. Instructions are 8 bit opcodes and are shifted in on the rising edge of the data clock. //pause for readability } @] [@ Restore August 30.print(eeprom_output_data. so a 10ms pause should follow each EEPROM write routine. to: After setting our control register up we read the SPI status register (SPSR) and data register (SPDR) in to the junk clr variabl to clear out any spurious data from past runs. at 10:57 AM by Heather Dewey-Hagborg Changed lines 53-54 from: Once you have your SPI Control Register set correctly you just need to figure out how long you need to pause between instructions and you are ready to go. Now that you have a feel for how SPI works. } void loop() { eeprom_output_data = read_eeprom(address).LOW). thus starting the SPI transmission.HIGH). to: This function loads the output data into the data transmission register. SPIF. digitalWrite(SLAVESELECT. thus starting the SPI transmission. address++. Now that you have a feel for how SPI works. //get data byte digitalWrite(SLAVESELECT. An explanation of bit masks can be found here.BYTE). It takes the EEPROM about 10 milliseconds to write a page (128 bytes) of data. Changed lines 62-63 from: The device is enabled by pulling the Chip Select (CS) pin low. //release chip. It takes the EEPROM about 10 milliseconds to write a page (128 bytes) of data. Restore . spi_transfer(READ). signal end transfer return data. if (address == 128) address = 0. //send MSByte address first spi_transfer((char)(EEPROM_address)). It then returns any data that has been shifted in to the data register by the EEPROM. delay(500). It then returns any data that has been shifted in to the data register by the EEPROM. to: Once you have your SPI Control Register set correctly you just need to figure out how long you need to pause between instructions and you are ready to go. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete.int data.

Typically there are three lines common to all the devices. let's take a look at the EEPROM chip. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. at 10:44 AM by Heather Dewey-Hagborg Changed lines 24-32 from: All SPI settings are determined by the Arduino SPI Control Register (SPCR). Master Out Slave In (MOSI) . The SPI control register (SPCR) has 8 bits. 2006. For example. Status registers change their state based on various microcontroller conditions. Usually each bit in a control register effects a particular setting. The SPCR has 8 bits each of which control a particular SPI setting. Data registers simply hold bytes. data and status.The Master line for sending data to the peripherals. Typically there are three lines common to all the devices. and the data which has just been shifted in the MISO line. For example.The clock pulses which synchronize data transmission generated by the master. such as speed or polarity. Restore August 30.The Slave line for sending data to the master. Master In Slave Out (MISO) . the SPI data register (SPDR) holds the byte which is about to be shifted out the MOSI line. to: Once you have your SPI Control Register set correctly you just need to figure out how long you need to pause between instructions and you are ready to go. Master In Slave Out (MISO) .August 30.allocated on each device which the master can use to enable and disable specific devices and avoid false transmissions due to line noise. 2006. It can also be used for communication between two microcontrollers. .The Master line for sending data to the peripherals. Serial Clock (SCK) . to: All SPI settings are determined by the Arduino SPI Control Register (SPCR). A register is just a byte of microcontroller memory that can be read from or written to.The clock pulses which synchronize data transmission generated by the master. each of which control a particular SPI setting. 2006. and Slave Select pin . the seventh bit of the SPI status register (SPSR) gets set to 1 when a value is shifted in or out of the SPI. Now that you have a feel for how SPI works. Registers generally serve three purposes.The Slave line for sending data to the master. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. control. to: Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by Microcontrollers for communicating with one or more peripheral devices quickly over short distances. It can also be used for communication between two microcontrollers. and Serial Clock (SCK) . at 10:51 AM by Heather Dewey-Hagborg Changed lines 53-54 from: Once you have your SPI Control Register set correctly you just need to figure out how long you need to pause between instructions and you are ready to go. Changed lines 48-52 from: -Is data shifted in MSB or LSB first? -Is the data clock idle when high or low? -Are samples on the rising or falling edge of clock pulses? -What speed is the SPI running at? to: Is data shifted in MSB or LSB first? Is the data clock idle when high or low? Are samples on the rising or falling edge of clock pulses? What speed is the SPI running at? Restore August 30. Additionally there is generally a Slave Select pin allocated on each device which the master can use to enable and disable specific devices and avoid false transmissions due to line noise. Master Out Slave In (MOSI) . Control registers code control settings for various microcontroller functionalities. at 09:58 AM by Tom Igoe Changed lines 14-15 from: Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by Microcontrollers for communicating with one or more peripheral devices quickly over short distances.

the third bit sets the SPI to sample data on the rising edge of the data clock. It's memory is organized as 512 pages of 128 bytes each. It supports SPI modes 0 and 3. The difficult part about SPI is that the standard is loose and each device implements it a little differently.Restore August 29.3. Generally speaking there are three modes of transmission numbered 0 . Changed lines 33-35 from: The eighth bit sets the SPI interrupt. to: This means that to write code for a new SPI device you need to note several things and set the SPCR accordingly: -Is data shifted in MSB or LSB first? -Is the data clock idle when high or low? -Are samples on the rising or falling edge of clock pulses? -What speed is the SPI running at? Once you have your SPI Control Register set correctly you just need to figure out how long you need to pause between instructions and you are ready to go. With an SPI connection to: Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by Microcontrollers for communicating with one or more peripheral devices quickly over short distances.3. the fifth bit puts the Arduino in Master mode. the seventh bit enables the SPI. Restore August 29. It can only be written 128 bytes at a time. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal. . at 06:51 PM by Heather Dewey-Hagborg Added lines 46-49: The AT25HP512 is a 65. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal. but it can be read 1-128 bytes at a time. at 05:46 PM by Heather Dewey-Hagborg Changed lines 16-17 from: The difficult part about SPI is that the standard is loose and each device implements it a little differently.536 byte serial EEPROM. It takes the EEPROM about 10 milliseconds to write a page (128 bytes) of data. Restore August 29. and whether the clock is idle when high or low. This means you have to pay special attention to the datasheet when writing your interface code. The device is enabled by pulling the Chip Select (CS) pin low. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). but we won't be covering those in this tutorial. Master In Slave Out (MISO) . at 04:07 PM by Heather Dewey-Hagborg Changed lines 14-15 from: Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by Microcontrollers for communicating with peripheral devices quickly over short distances.The Slave line for sending data to the master.The Master line for sending data to the peripherals. to: The difficult part about SPI is that the standard is loose and each device implements it a little differently. and Serial Clock (SCK) . and whether the clock is idle when high or low. Generally speaking there are three modes of transmission numbered 0 .3. Additionally there is generally a Slave Select pin allocated on each device which the master can use to enable and disable specific devices and avoid false transmissions due to line noise. Typically there are three lines common to all the devices. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. runs at up to 10MHz at 5v and can run at slower speeds down to 1. Instructions are 8 bit opcodes and are shifted in on the rising edge of the data clock. All SPI settings are determined by the Arduino SPI Control Register (SPCR). Generally speaking there are three modes of transmission numbered 0 . the sixth bit chooses transmission with the most significant bit going first or Least Significant. and whether the clock is idle when high or low.The clock pulses which synchronize data transmission generated by the master. It can also be used for communication between two microcontrollers. 2006. Master Out Slave In (MOSI) . It can also be used for communication between two microcontrollers. 2006.8v. The device also offers various degerees of write protection and a hold pin. so a 10ms pause should follow each EEPROM write routine. the fourth bit sets the data clock idle when it is low. The SPCR has 8 bits each of which control a particular SPI setting. 2006. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal.

00 is fastest (4MHz) 11 is slowest (250KHz) The eighth bit sets the SPI interrupt. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). With an SPI connection Restore August 29. It can also be used for communication between two microcontrollers.SPCR | 7 | 6 | SPIE | SPE | 5 | 4 | 3 | 2 | 1 | 0 | | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 | SPIE .Sets the Arduino in master mode when 1. the seventh bit enables the SPI. slave mode when 0 CPOL .Enables the SPI interrupt when 1 SPE . at 02:45 PM by Heather Dewey-Hagborg Changed lines 33-34 from: [@#define DATAOUT 11//MOSI to: [@ 1.Samples data on the falling edge of the data clock when 1. rising edge when 0 SPR1 and SPR0 . the fourth bit sets the data clock idle when it is low. most Significant Bit first when 0 MSTR . 2006.Sets the SPI speed.Sets the data clock to be idle when high if set to 1. Restore August 29.Enables the SPI when 1 DORD . Changed lines 61-62 from: [@void fill_buffer() to: [@ void fill_buffer() Changed lines 72-73 from: [@char spi_transfer(volatile char data) to: [@ char spi_transfer(volatile char data) Changed lines 86-87 from: [@void setup() to: [@ void setup() Changed lines 99-100 from: [@ // SPCR = 01010000 . 2006. idle when low if set to 0 CPHA . to: [@ byte eeprom_output_data. define DATAOUT 11//MOSI Changed lines 51-52 from: [@byte eeprom_output_data. the sixth bit chooses transmission with the most significant bit going first or Least Significant. at 02:56 PM by Heather Dewey-Hagborg Added lines 14-15: Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by Microcontrollers for communicating with peripheral devices quickly over short distances. the third bit sets the SPI to sample data on the rising edge of the data clock. the fifth bit puts the Arduino in Master mode.Sends data least Significant Bit First when 1.

BYTE).print('h'. the simplest function in the program! Here we just read one byte at a time from the EEPROM and print it out the serial port. Changed lines 139-140 from: [@Serial. When the address increments to 128 we turn it back to 0 because we have only filled . When the address increments to 128 we turn it back to 0 since we have only filled 128 addresses in the EEPROM with data. Each time through the loop we increment the eeprom address to read. to: [@ delay(10).BYTE). to: [@ Serial.to: [@ // SPCR = 01010000 Changed lines 111-112 from: [@//fill buffer with data to: [@ //fill buffer with data Changed lines 121-122 from: [@delay(10). to: Finally we get to our main loop. We add a line feed and a pause for readability. at 02:43 PM by Heather Dewey-Hagborg Changed lines 162-164 from: Finally we get to our main loop. Each time through the loop we increment the eeprom address to read.print('h'. 2006. the simplest function in the program! Here we just read one byte at a time from the EEPROM and print it out the serial port plus a line feed and a pause for readability. define DATAOUT 11//MOSI Restore August 29. Changed lines 147-148 from: [@byte read_eeprom(int EEPROM_address) to: [@ byte read_eeprom(int EEPROM_address) Changed lines 163-164 from: [@void loop() to: [@ void loop() Changed lines 178-179 from: [@#define DATAOUT 11//MOSI to: [@ 1.

// SPCR = 01010000 //interrupt disabled. at 02:42 PM by Heather Dewey-Hagborg Added lines 59-164: void fill_buffer() { for (int I=0. //fill buffer with data fill_buffer(). In the control register each bit sets a different functionality. pinMode(DATAOUT.I++) { buffer[I]=I. the fifth bit puts the Arduino in Master mode.HIGH).OUTPUT). pinMode(SLAVESELECT. //write enable digitalWrite(SLAVESELECT.I<128. and . After setting our control register up we clear any spurious data from the Status and Control registers. char spi_transfer(volatile char data) { SPDR = data. It then returns any data that has been shifted in to the data register by the EEPROM. return SPDR. 2006. //sample on leading edge of clk. spi_transfer(WREN). //fill eeprom w/ buffer digitalWrite(SLAVESELECT.system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR). This function could easily be changed to fill the array with data relevant to your application. set our input and output pin modes and set the SLAVESELECT line high to start. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait for the end of the transmission { }.HIGH).clk low when idle.begin(9600). the sixth bit chooses transmission with the most significant bit going first. the third bit sets the SPI to sample data on the rising edge of the data clock. Restore August 29. the seventh bit enables the SPI. Here we fill our data array with numbers and send a write enable instruction to the EEPROM.spi enabled. } } This function simply fills our data array with numbers 0 . pinMode(DATAIN. The EEPROM MUST be write enabled before every write instruction. clr=SPSR.127 for each index in the array. the fourth bit sets the data clock idle when it is low. void setup() { Serial. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete. enabling the device. //disable device First we initialize our serial connection.128 addresses in the EEPROM with data. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). delay(10). This deselects the device and avoids any false transmission messages due to line noise. // return the received byte } This function loads the output data into the data transmission register. To send the instruction we pull the SLAVESELECT line low. thus starting the SPI transmission. Now we set the SPI Control register (SPCR) to the binary value 01010000.msb 1st.master. The eighth bit disables the SPI interrupt.OUTPUT). The following setup function is long so we will take it in parts. pinMode(SPICLOCK. clr=SPDR.LOW). INPUT). digitalWrite(SLAVESELECT. OUTPUT).

BYTE). //send MSByte address first spi_transfer((char)(address)).HIGH). Serial. //write data byte } digitalWrite(SLAVESELECT. When the address increments to 128 we turn it back to 0 since we have only filled 128 addresses in the EEPROM with data. We send a WRITE instruction to tell the EEPROM we will be sending data to record into memory. Then we transmit a READ instruction.print('\n'. We end the setup function by sending the word "hi" plus a line feed out the built in serial port for debugging purposes.then send the instruction using the spi_transfer function.I<128. delay(500). the simplest function in the program! Here we just read one byte at a time from the EEPROM and print it out the serial port plus a line feed and a pause for readability. and return the data. up to 128 times for a full page of data. followed by the 16-bit address we wish to read from.print('\n'. spi_transfer((char)(address>>8)). //transmit read opcode spi_transfer((char)(EEPROM_address>>8)). //send LSByte address //write 128 bytes for (int I=0.print('h'.//debug delay(1000). //release chip //wait for eeprom to finish writing delay(3000). Finally we pull the SLAVESELECT line high again to release it. Serial.LOW). Note that we use the WREN opcode we defined at the beginning of the program. void loop() { eeprom_output_data = read_eeprom(address). Finally we set the SLAVESELECT pin high to release the device and pause to allow the EEPROM to write the data.HIGH). address++.LOW). //get data byte digitalWrite(SLAVESELECT. spi_transfer(READ). spi_transfer(WRITE). delay(10). //send LSByte address data = spi_transfer(0xFF).BYTE).I++) { spi_transfer(buffer[I]). signal end transfer return data. //pause for readability } Finally we get to our main loop. This way if our data comes out looking funny later on we can tell it isn't just the serial port acting up. Each time through the loop we increment the eeprom address to read. one byte after another without pause. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. } This function allows us to read data back out of the EEPROM. byte read_eeprom(int EEPROM_address) { //READ EEPROM int data. //release chip. Serial. Added lines 166-270: #define DATAOUT 11//MOSI #define DATAIN 12//MISO . Now we pull the SLAVESELECT line low to select the device again after a brief delay. Next we send our 128 bytes of data from our buffer array.DEC). Most Significant Bit first. Most Significant Bit first. //send MSByte address first spi_transfer((char)(EEPROM_address)). digitalWrite(SLAVESELECT.print('i'. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). First we set the SLAVESELECT line low to enable the device. Serial.BYTE). Serial.print(eeprom_output_data. //write instruction address=0. digitalWrite(SLAVESELECT.BYTE). We send the 16 bit address to begin writing at in two bytes. Finally we pull the SLAVESELECT line high again to release the device after reading one byte.

//disable device // SPCR = 01010000 //interrupt disabled.HIGH). pinMode(DATAIN. pinMode(DATAOUT. int address=0.spi enabled.msb 1st. //send MSByte address first spi_transfer((char)(address)). //send LSByte address //write 128 bytes for (int I=0. spi_transfer(WREN). delay(10). INPUT). pinMode(SLAVESELECT. //data buffer char buffer [128]. //fill eeprom w/ buffer digitalWrite(SLAVESELECT.HIGH). clr=SPDR.system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR). // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }.LOW). OUTPUT). //sample on leading edge of clk. } } char spi_transfer(volatile char data) { SPDR = data. pinMode(SPICLOCK. delay(10).OUTPUT). clr=SPSR.I<128.OUTPUT).clk low when idle. void fill_buffer() { for (int I=0.LOW).begin(9600).#define SPICLOCK 13//sck #define SLAVESELECT 10//ss //opcodes #define WREN #define WRDI #define RDSR #define WRSR #define READ #define WRITE 6 4 5 1 3 2 byte eeprom_output_data.I++) . byte eeprom_input_data=0. // return the received byte } void setup() { Serial. return SPDR. byte clr. digitalWrite(SLAVESELECT. //fill buffer with data fill_buffer(). spi_transfer(WRITE). //write enable digitalWrite(SLAVESELECT.master. digitalWrite(SLAVESELECT.I++) { buffer[I]=I.I<128. spi_transfer((char)(address>>8)). //write instruction address=0.

if (address == 128) address = 0. #define #define #define #define DATAOUT 11//MOSI DATAIN 12//MISO SPICLOCK 13//sck SLAVESELECT 10//ss //opcodes #define WREN #define WRDI #define RDSR #define WRSR #define READ #define WRITE 6 4 5 1 3 2 Here we set up our pre-processor directives. In the setup routine this program fills 128 bytes. Serial. //release chip //wait for eeprom to finish writing delay(3000). //get data byte digitalWrite(SLAVESELECT. //release chip. 2006. //transmit read opcode spi_transfer((char)(EEPROM_address>>8)). We will walk through the code in small sections.//debug delay(1000).print(eeprom_output_data.BYTE). Serial.print('i'. //send LSByte address data = spi_transfer(0xFF). Serial. byte eeprom_output_data.print('\n'. Opcodes are control commands. Then we define our opcodes for the EEPROM. //send MSByte address first spi_transfer((char)(EEPROM_address)).BYTE). signal end transfer return data. } void loop() { eeprom_output_data = read_eeprom(address). Pre-processor directives are processed before the actual compilation begins. //write data byte } digitalWrite(SLAVESELECT.HIGH). .print('\n'. First we define the pins we will be using for our SPI connection.LOW). address++. spi_transfer(READ). delay(500). SPICLOCK and SLAVESELECT. Serial. or one page of the EEPROM with data. //pause for readability } Restore August 29. digitalWrite(SLAVESELECT. } byte read_eeprom(int EEPROM_address) { //READ EEPROM int data.BYTE). Serial. byte eeprom_input_data=0.HIGH).DEC). In the main loop it reads that data back out. at 01:15 PM by Heather Dewey-Hagborg Added lines 30-61: Now we will write the code to enable SPI communication between the EEPROM and the Arduino.print('h'. one byte at a time and prints that byte out the built in serial port. They start with a "#" and do not end with semi-colons.{ spi_transfer(buffer[I]). DATAIN. DATAOUT.BYTE).

and EEPROM pin 6 to Arduino pin 13 (Serial Clock).byte clr. 2006. //data buffer char buffer [128]. Connect EEPROM pins 3. Note char buffer [128]. EEPROM pin 2 to Arduino pin 12 (Master In Slave Out). EEPROM pin 5 to Arduino pin 11 (Master Out Slave In). PICTURE of pwr wires Connect EEPROM pin 1 to Arduino pin 10 (Slave Select). Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. this is a 128 byte array we will be using to store the data for the EEPROM write. Here we allocate the global variables we will be using later in the program. PICTURE of SPI wires Restore August 27. int address=0. at 01:14 PM by Heather Dewey-Hagborg Added lines 14-18: Atmel 25HP512 EEPROM chip . 7 and 8 to 5v and pin 4 to ground. at 01:17 PM by Heather Dewey-Hagborg Changed line 1 from: Interfacing a serial EEPROM using SPI to: Interfacing a Serial EEPROM Using SPI Changed lines 12-15 from: Serial Peripheral Interface Atmel 25HP512 EEPROM chip to: Introduction to the Serial Peripheral Interface Introduction to Serial EEPROM Restore August 27. 2006. For easy copy and pasting the full program text of this tutorial is below: Restore August 29. at 12:58 PM by Heather Dewey-Hagborg Added lines 21-28: Insert the AT25HP512 chip into the breadboard. 2006. .

EEPROM chips such as this are very useful for data storage. Arduino Microcontroller Module Serial Peripheral Interface Restore Edit Page | Page History | Printable View | All Recent Site Changes . and the steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. Materials Needed: 1. at 01:09 PM by Heather Dewey-Hagborg Added lines 1-11: Interfacing a serial EEPROM using SPI In this tutorial you will learn how to interface with an AT25HP512 Atmel serial EEPROM using the Serial Peripheral Interface (SPI) protocol.Restore August 27. 2006. Hookup wire 3. at 01:11 PM by Heather Dewey-Hagborg Changed lines 2-3 from: to: (IN PROGRESS) Added lines 13-16: Prepare the Breadboard Program the Arduino Restore August 27. AT25HP512 Serial EEPROM chip (or similar) 2. 2006.

and whether the clock is idle when high or low. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal. the SPI data register (SPDR) holds the byte which is about to be shifted out the MOSI line.The Master line for sending data to the peripherals. A register is just a byte of microcontroller memory that can be read from or written to. Serial Clock (SCK) . Registers generally serve three purposes.Enables the SPI interrupt when 1 SPE . The difficult part about SPI is that the standard is loose and each device implements it a little differently. The SPI control register (SPCR) has 8 bits. and the steps we will cover for implementing SPI communication can be modified for use with most other SPI devices.3. data and status. such as speed or polarity. most Significant Bit first when 0 MSTR . the seventh bit of the SPI status register (SPSR) gets set to 1 when a value is shifted in or out of the SPI. For example.Arduino : Tutorial / SPIEEPROM Learning Examples | Foundations | Hacking | Links Interfacing a Serial EEPROM Using SPI In this tutorial you will learn how to interface with an AT25HP512 Atmel serial EEPROM using the Serial Peripheral Interface (SPI) protocol. control. All SPI settings are determined by the Arduino SPI Control Register (SPCR).allocated on each device which the master can use to enable and disable specific devices and avoid false transmissions due to line noise. Master Out Slave In (MOSI) . idle when low if set to 0 . Data registers simply hold bytes. slave mode when 0 CPOL .The Slave line for sending data to the master. Generally speaking there are three modes of transmission numbered 0 . Materials Needed: AT25HP512 Serial EEPROM chip (or similar) Hookup wire Arduino Microcontroller Module Introduction to the Serial Peripheral Interface Serial Peripheral Interface (SPI) is a synchronous serial data protocol used by Microcontrollers for communicating with one or more peripheral devices quickly over short distances. SPCR | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | SPIE | SPE | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 | SPIE . and the data which has just been shifted in the MISO line.Sets the Arduino in master mode when 1. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. Master In Slave Out (MISO) .Sends data least Significant Bit First when 1. It can also be used for communication between two microcontrollers. Status registers change their state based on various microcontroller conditions. Usually each bit in a control register effects a particular setting.The clock pulses which synchronize data transmission generated by the master.Enables the SPI when 1 DORD . Typically there are three lines common to all the devices. EEPROM chips such as this are very useful for data storage. This means you have to pay special attention to the datasheet when writing your interface code.Sets the data clock to be idle when high if set to 1. For example. each of which control a particular SPI setting. Control registers code control settings for various microcontroller functionalities. so follow this tutorial only if you need more space than it provides. and Slave Select pin . Note that the chip on the Arduino board contains an internal EEPROM.

so a 10ms pause should follow each EEPROM write routine. The device also offers various degerees of write protection and a hold pin. runs at up to 10MHz at 5v and can run at slower speeds down to 1. The device is enabled by pulling the Chip Select (CS) pin low. Prepare the Breadboard Insert the AT25HP512 chip into the breadboard. It supports SPI modes 0 and 3.Sets the SPI speed. It takes the EEPROM about 10 milliseconds to write a page (128 bytes) of data. let's take a look at the details of the EEPROM chip.CPHA . 00 is fastest (4MHz) 11 is slowest (250KHz) This means that to write code for a new SPI device you need to note several things and set the SPCR accordingly: Is data shifted in MSB or LSB first? Is the data clock idle when high or low? Are samples on the rising or falling edge of clock pulses? What speed is the SPI running at? Once you have your SPI Control Register set correctly you just need to figure out how long you need to pause between instructions and you are ready to go. but we won't be covering those in this tutorial. . but it can be read 1-128 bytes at a time. Instructions are sent as 8 bit operational codes (opcodes) and are shifted in on the rising edge of the data clock. Introduction to Serial EEPROM The AT25HP512 is a 65. Now that you have a feel for how SPI works.Samples data on the falling edge of the data clock when 1.8v.536 byte serial EEPROM. rising edge when 0 SPR1 and SPR0 . It's memory is organized as 512 pages of 128 bytes each. Connect EEPROM pins 3. 7 and 8 to 5v and pin 4 to ground. It can only be written 128 bytes at a time. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller.

Then we define our opcodes for the EEPROM. Opcodes are control commands: #define DATAOUT 11//MOSI .SCK). We will walk through the code in small sections. In the main loop it reads that data back out. DATAOUT.+5v wires are red. EEPROM pin 5 to Arduino pin 11 (Master Out Slave In . They start with a "#" and do not end with semi-colons. SPICLOCK and SLAVESELECT. The first step is setting up our pre-processor directives. Pre-processor directives are processed before the actual compilation begins. SCK wire is green Program the Arduino Now we will write the code to enable SPI communication between the EEPROM and the Arduino. We define the pins we will be using for our SPI connection. MOSI wire is blue. In the setup routine this program fills 128 bytes. one byte at a time and prints that byte out the built in serial port. MISO wire is yellow. and EEPROM pin 6 to Arduino pin 13 (Serial Clock . GND wires are black Connect EEPROM pin 1 to Arduino pin 10 (Slave Select . DATAIN. SS wire is white.MISO).MOSI). or one page of the EEPROM with data. EEPROM pin 2 to Arduino pin 12 (Master In Slave Out .SS).

INPUT). the seventh bit enables the SPI. the sixth bit chooses transmission with the most significant bit going first. digitalWrite(SLAVESELECT.HIGH). Next we send our 128 bytes of data from our buffer array.system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR). enabling the device. To send the instruction we pull the SLAVESELECT line low. The EEPROM MUST be write enabled before every write instruction. the fourth bit sets the data clock idle when it is low. //fill eeprom w/ buffer digitalWrite(SLAVESELECT. OUTPUT). In the control register each bit sets a different functionality.OUTPUT). We send the 16 bit address to begin writing at in two bytes. pinMode(DATAOUT. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). byte eeprom_input_data=0. Finally we set the SLAVESELECT pin high to release the device and pause to allow the EEPROM to write the data: . delay(10). the third bit sets the SPI to sample data on the rising edge of the data clock. //write enable digitalWrite(SLAVESELECT. set our input and output pin modes and set the SLAVESELECT line high to start.#define DATAIN 12//MISO #define SPICLOCK 13//sck #define SLAVESELECT 10//ss //opcodes #define WREN #define WRDI #define RDSR #define WRSR #define READ #define WRITE 6 4 5 1 3 2 Here we allocate the global variables we will be using later in the program. After setting our control register up we read the SPI status register (SPSR) and data register (SPDR) in to the junk clr variable to clear out any spurious data from past runs: // SPCR = 01010000 //interrupt disabled. pinMode(DATAIN. First we initialize our serial connection. int address=0. pinMode(SPICLOCK.spi enabled. spi_transfer(WREN). //disable device Now we set the SPI Control register (SPCR) to the binary value 01010000.begin(9600).LOW). clr=SPSR. Note that we use the WREN opcode we defined at the beginning of the program. Note char buffer [128]. one byte after another without pause. //data buffer char buffer [128]. pinMode(SLAVESELECT. This deselects the device and avoids any false transmission messages due to line noise: void setup() { Serial.OUTPUT).clk low when idle. Finally we pull the SLAVESELECT line high again to release it: //fill buffer with data fill_buffer(). Now we pull the SLAVESELECT line low to select the device again after a brief delay. The eighth bit disables the SPI interrupt. and then send the instruction using the spi_transfer function. Most Significant Bit first.master.msb 1st.. clr=SPDR. byte clr. Here we fill our data array with numbers and send a write enable instruction to the EEPROM.HIGH). We send a WRITE instruction to tell the EEPROM we will be sending data to record into memory. //sample on leading edge of clk. the fifth bit puts the Arduino in Master mode. this is a 128 byte array we will be using to store the data for the EEPROM write: byte eeprom_output_data.

//write instruction address=0. followed by the 16-bit address we wish to read from. First we set the SLAVESELECT line low to enable the device.BYTE). } } The spi_transfer function loads the output data into the data transmission register.print('h'. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait for the end of the transmission { }. It then returns any data that has been shifted in to the data register by the EEPROM: char spi_transfer(volatile char data) { SPDR = data.127 for each index in the array. Then we transmit a READ instruction.BYTE).I++) { spi_transfer(buffer[I]). Serial. // return the received byte } The read_eeprom function allows us to read data back out of the EEPROM.I<128.HIGH). //send MSByte address first spi_transfer((char)(address)). //pause for readability } The fill_buffer function simply fills our data array with numbers 0 . digitalWrite(SLAVESELECT. //write data byte } digitalWrite(SLAVESELECT.LOW). Next we send a dummy byte to the EEPROM for the purpose of shifting the data out.I<128. //release chip //wait for eeprom to finish writing delay(3000). This function could easily be changed to fill the array with data relevant to your application: void fill_buffer() { for (int I=0.print('i'. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. SPIF. When the address increments to 128 we turn it back to 0 because we have only filled 128 addresses in the EEPROM with data: void loop() { eeprom_output_data = read_eeprom(address). spi_transfer((char)(address>>8)). } In our main loop we just read one byte at a time from the EEPROM and print it out the serial port. spi_transfer(WRITE).print('\n'. thus starting the SPI transmission. delay(500). Most Significant Bit first. Serial. and return the data.BYTE). address++. An explanation of bit masks can be found here. up to 128 times for a full page of data: byte read_eeprom(int EEPROM_address) { . It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. //send LSByte address //write 128 bytes for (int I=0. Serial.delay(10). We end the setup function by sending the word "hi" plus a line feed out the built in serial port for debugging purposes. Serial.//debug delay(1000).I++) { buffer[I]=I. return SPDR. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF).print(eeprom_output_data.print('\n'.BYTE). We add a line feed and a pause for readability.DEC). This way if our data comes out looking funny later on we can tell it isn't just the serial port acting up: Serial. Each time through the loop we increment the eeprom address to read.

//transmit read opcode spi_transfer((char)(EEPROM_address>>8)). //get data byte digitalWrite(SLAVESELECT. void fill_buffer() { for (int I=0. spi_transfer(READ). spi_transfer((char)(address>>8)). return SPDR. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. //send LSByte address data = spi_transfer(0xFF).system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR).clk low when idle.OUTPUT). //send MSByte address first spi_transfer((char)(EEPROM_address)). //send LSByte address //write 128 bytes . digitalWrite(SLAVESELECT.OUTPUT).//READ EEPROM int data.I<128. //disable device // SPCR = 01010000 //interrupt disabled. //write instruction address=0. pinMode(SPICLOCK. INPUT). //send MSByte address first spi_transfer((char)(address)). int address=0. byte clr. //data buffer char buffer [128]. } } char spi_transfer(volatile char data) { SPDR = data.HIGH).begin(9600). spi_transfer(WRITE). //fill eeprom w/ buffer digitalWrite(SLAVESELECT. delay(10).LOW). //write enable digitalWrite(SLAVESELECT. // return the received byte } void setup() { Serial.I++) { buffer[I]=I.HIGH).HIGH). OUTPUT). pinMode(DATAIN. //fill buffer with data fill_buffer(). digitalWrite(SLAVESELECT. digitalWrite(SLAVESELECT. signal end transfer return data. //sample on leading edge of clk.spi enabled.master. pinMode(SLAVESELECT. spi_transfer(WREN). pinMode(DATAOUT. delay(10). } For easy copy and pasting the full program text of this tutorial is below: #define #define #define #define DATAOUT 11//MOSI DATAIN 12//MISO SPICLOCK 13//sck SLAVESELECT 10//ss 6 4 5 1 3 2 //opcodes #define WREN #define WRDI #define RDSR #define WRSR #define READ #define WRITE byte eeprom_output_data. clr=SPSR. byte eeprom_input_data=0.msb 1st.LOW).LOW). //release chip. clr=SPDR.

//send MSByte address first spi_transfer((char)(EEPROM_address)).HIGH).DEC).LOW). signal end transfer return data. //send LSByte address data = spi_transfer(0xFF). delay(500). Serial.print('i'.I++) { spi_transfer(buffer[I]).HIGH).BYTE). //get data byte digitalWrite(SLAVESELECT. //release chip.//debug delay(1000). digitalWrite(SLAVESELECT. if (address == 128) address = 0. //pause for readability } code and tutorial by Heather Dewey-Hagborg. //transmit read opcode spi_transfer((char)(EEPROM_address>>8)).print(eeprom_output_data.BYTE). Serial.cc/en/Tutorial/SPIEEPROM) . Serial. //write data byte } digitalWrite(SLAVESELECT.BYTE). Serial.print('\n'.for (int I=0. } void loop() { eeprom_output_data = read_eeprom(address). photos by Thomas Dexter (Printable View of http://www.arduino. address++.BYTE). } byte read_eeprom(int EEPROM_address) { //READ EEPROM int data. Serial.print('h'. spi_transfer(READ). //release chip //wait for eeprom to finish writing delay(3000).I<128.print('\n'.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

SPIDigitalPot History Hide minor edits . 2006. at 03:49 PM by Heather Dewey-Hagborg Changed lines 28-29 from: PICTURE power to: Changed lines 32-33 from: PICTURE datacom to: . tutorial and photos by Heather Dewey-Hagborg Restore September 06. at 04:02 PM by Heather Dewey-Hagborg Changed lines 137-138 from: VIDEO ? LEDs to: LED video Restore September 06. 2006.Show changes to markup September 06. at 03:55 PM by Heather Dewey-Hagborg Changed lines 204-206 from: @] to: @] code. 2006.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.

at 09:22 AM by Heather Dewey-Hagborg Changed lines 7-10 from: PICTURE pins PICTURE pin functions to: . at 03:38 PM by Heather Dewey-Hagborg Added lines 5-11: Materials Needed: AD5206 Digital Potentiometer Arduino Microcontroller Module 6 Light Emitting Diodes (LEDs) Hookup Wire Restore September 06.Changed lines 36-37 from: PICTURE leds to: Restore September 06. at 10:03 AM by Heather Dewey-Hagborg Restore September 06. 2006. 2006. 2006.

.

This makes room to add the resistance value which occupies the least significant eight bits of the data byte. at 03:07 PM by Heather Dewey-Hagborg Restore September 05. 2006. at 03:11 PM by Heather Dewey-Hagborg Added lines 130-131: VIDEO ? LEDs Restore September 05.Restore September 05. 2006. When we sum the two together we get our 11 bit opcode to . at 03:03 PM by Heather Dewey-Hagborg Changed lines 117-118 from: The write_pot function allows us to control the individual potentiometers. First we shift the potentiometer address 8 bits to the left to put it in the most significant bit position of the 11 bit data byte. 2006.

we set the SLAVSELECT line high again to release the chip and signal the end of our data transfer. B1 and W1. Restore September 05. d5d6d700000 //send MSByte address first a0a1a2d0d1d2d3d4 //send LSByte address. Then we transfer the 11 bit opcode in two bytes sending the eight most significant bits first and sending the three least significant bits last. [@ Changed lines 124-125 from: spi_transfer((char)(opcode>>8)). //10111111111 Changed lines 176-177 from: spi_transfer((char)(opcode>>8)). and they can be interfaced with just as you would use a mechanical potentiometer. 101 = 10100000000 opcode = address+value. There are three pins on the chip for each of the six internal variable resistors. to: spi_transfer(address). 101 = 10100000000 opcode = address+value. We set the SLAVESELECT line low to enable the device. This means it has six variable resistors (potentiometers) built in for individual electronic control. The individual variable resistor pins are labeled Ax. d5d6d700000 . //shift pot address 8 left. Deleted lines 173-175: int opcode=0. Bx and Wx. and they can be interfaced with just as you would use a mechanical potentiometer. Deleted lines 121-128: int opcode=0. Bx and Wx. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. It then returns any data that has been shifted in to the data register by the EEPROM: to: In our main loop we iterate through each resistance value (0-255) for each potentiometer address (0-5). spi_transfer(value). Finally. We set the SLAVSELECT line high again to release the chip and signal the end of our data transfer. spi_transfer((char)(opcode)). We pause for 10 //send MSByte address first a0a1a2d0d1d2d3d4 //send LSByte address. A1. to: spi_transfer(address). address<<=8. ie.transmit: to: The write_pot function allows us to control the individual potentiometers. //shift pot address 8 left. SPIF. B1 and W1. 2006. Changed lines 85-86 from: The spi_transfer function loads the output data into the data transmission register. This means it has six variable resistors built in for individual electronic control. A1. ie. ie. There are three pins on the chip for each of the six internal variable resistors. thus starting the SPI transmission. The individual variable resistor pins are labeled Ax. spi_transfer(value). An explanation of bit masks can be found here?. spi_transfer((char)(opcode)). address<<=8. Then we transfer the address byte followed by the resistance value byte. ie. //10111111111 @] We set the SLAVESELECT line low to enable the device. at 02:42 PM by Heather Dewey-Hagborg Changed lines 11-12 from: The AD5206 is a 6 channel digital potentiometer. to: The AD5206 is a 6 channel digital potentiometer.

//shift pot address 8 left.milliseconds each iteration to make the steps visible. This causes the LEDs to sequentially flash on brightly and then fade out slowly: Changed line 88 from: char spi_transfer(volatile char data) to: void loop() Changed lines 90-94 from: SPDR = data. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. to: write_pot(pot. delay(10). It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask.LOW). First we shift the potentiometer address 8 bits to the left to put it in the most significant bit position of the 11 bit data byte. } if (pot==6) { pot=0. ie. //send MSByte address first a0a1a2d0d1d2d3d4 . An explanation of bit masks can be found here. return SPDR. 101 = 10100000000 opcode = address+value. It then returns any data that has been shifted in to the data register by the EEPROM: char spi_transfer(volatile char data) { SPDR = data. When we sum the two together we get our 11 bit opcode to transmit: byte write_pot(int address. digitalWrite(SLAVESELECT. thus starting the SPI transmission. This makes room to add the resistance value which occupies the least significant eight bits of the data byte. while (!(SPSR & (1<<SPIF))) { }. resistance++. } Added lines 102-205: @] The spi_transfer function loads the output data into the data transmission register.resistance). int value) { int opcode=0. //10111111111 We set the SLAVESELECT line low to enable the device. if (resistance==255) { pot++. We set the SLAVSELECT line high again to release the chip and signal the end of our data transfer. //2 byte opcode spi_transfer((char)(opcode>>8)). return SPDR. SPIF. Then we transfer the 11 bit opcode in two bytes sending the eight most significant bits first and sending the three least significant bits last. // return the received byte } // Start the transmission // Wait the end of the transmission // return the received byte The write_pot function allows us to control the individual potentiometers. address<<=8.

HIGH).i++) { write_pot(i. //10111111111 digitalWrite(SLAVESELECT. delay(10). //release } void loop() { write_pot(pot. opcode = address+value. but part of builtin SPI SPICLOCK 13//sck SLAVESELECT 10//ss byte pot=0.master.msb 1st. INPUT).255). int value) { int opcode=0.spi enabled.i<6.system clock/4 (fastest) SPCR = (1<<SPE)|(1<<MSTR). clr=SPSR. 2. //send digitalWrite(SLAVESELECT.resistance). //send spi_transfer((char)(opcode)). pinMode(DATAOUT.OUTPUT). //2 byte opcode spi_transfer((char)(opcode>>8)).OUTPUT). //send LSByte address. OUTPUT). resistance++.HIGH). pinMode(DATAIN. //shift pot address 8 left. byte resistance=0. signal end transfer } For easy copy and pasting the full program text of this tutorial is below: [@ 1. while (!(SPSR & (1<<SPIF))) { }. 4. //release chip. // Start the transmission // Wait the end of the transmission // return the received byte ie. char spi_transfer(volatile char data) { SPDR = data. digitalWrite(SLAVESELECT. pinMode(SLAVESELECT.spi_transfer((char)(opcode)).clk low when idle. //sample on leading edge of clk. return SPDR. address<<=8. for (i=0. clr=SPDR. byte clr. delay(10). } void setup() { byte i. 3. if (resistance==255) { pot++.HIGH).LOW). //disable device // SPCR = 01010000 //interrupt disabled. d5d6d700000 digitalWrite(SLAVESELECT. pinMode(SPICLOCK. signal end transfer .not used. 101 = 10100000000 MSByte address first a0a1a2d0d1d2d3d4 LSByte address. d5d6d700000 chip. } } byte write_pot(int address. define define define define DATAOUT 11//MOSI DATAIN 12//MISO .

255).OUTPUT). pinMode(DATAOUT. In the control register each bit sets a different functionality. at 02:25 PM by Heather Dewey-Hagborg Added lines 53-96: First we set our input and output pin modes and set the SLAVESELECT line high to start. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. // return the received byte } Restore September 05.OUTPUT). pinMode(SLAVESELECT. the sixth bit chooses transmission with the most significant bit going first. INPUT). clr=SPDR. SPIF. } } The spi_transfer function loads the output data into the data transmission register. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. the seventh bit enables the SPI. 2006. pinMode(DATAIN.i++) { write_pot(i. The data clock is idle when low. the fourth bit sets the data clock idle when it is low. the third bit sets the SPI to sample data on the rising edge of the data clock. After setting our control register up we read the SPI status register (SPSR) and data register (SPDR) in to the junk clr variable to clear out any spurious data from past runs: SPCR = (1<<SPE)|(1<<MSTR). The device is enabled by pulling the Chip Select (CS) pin low. return SPDR. The eighth bit disables the SPI interrupt. the fifth bit puts the Arduino in Master mode.HIGH). digitalWrite(SLAVESELECT. 2006.} if (pot==6) { pot=0. and the interface runs much faster than the Arduino. An explanation of bit masks can be found here?.i<6. It then returns any data that has been shifted in to the data register by the EEPROM: char spi_transfer(volatile char data) { SPDR = data. . so we don't need to worry about pre-scaling to slow down the transmission. clr=SPSR. Instructions are sent as 11 bit operational codes (opcodes) and are shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. } } Restore September 05. OUTPUT). and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). delay(10). //disable device Now we set the SPI Control register (SPCR) to the binary value 01010000. pinMode(SPICLOCK. at 02:14 PM by Heather Dewey-Hagborg Changed lines 15-16 from: The AD5206 is digitally controlled using SPI. We conclude the setup function by setting all the potentiometers to full on resistance states thereby turning the LEDs off: for (i=0. thus starting the SPI transmission. This deselects the device and avoids any false transmission messages due to line noise: void setup() { byte clr.

14. Instructions are sent as 11 bit operational codes (opcodes) and are shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. We define the pins we will be using for our SPI connection. Restore September 05. and the interface runs much faster than the Arduino. at 01:59 PM by Heather Dewey-Hagborg Changed lines 11-12 from: The AD5206 is a 6 channel digital potentiometer. ie. 2006. 17. or flat side of the LED connects to ground. The individual variable resistor pins are labeled Ax. Instructions are sent as 11 bit operational codes (opcodes) with the three most significant bits (11-9) defining the address of which potentiometer to adjust and the eight least significant bits (8-1) defining what value to set that potentiometer to from 0-255. to: The AD5206 is digitally controlled using SPI. The device is enabled by pulling the Chip Select (CS) pin low. Bx and Wx. Changed lines 15-25 from: The AD5206 is digitally controlled using standard SPI. The data clock is idle when low. connect an LED between each Wiper pin (AD5206 pins 2. Prepare the Breadboard . byte resistance=0. and the interface runs much faster than the Arduino. DATAOUT. This program will sequentially pulse each LED on and then fade it out gradually. A1. and they can be interfaced with just as you would use a mechanical potentiometer.to: The AD5206 is digitally controlled using SPI. Instructions are sent as 11 bit operational codes (opcodes) and are shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. SPICLOCK and SLAVESELECT. 20 and 23) and ground so that the long pin of the LED connects to the wiper and the short pin. and they can be interfaced with just as you would use a mechanical potentiometer. so we don't need to worry about pre-scaling to slow down the transmission. Data is shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. 11. but part of builtin SPI SPICLOCK 13//sck SLAVESELECT 10//ss Next we allocate variables to store resistance values and address values for the potentiometers: byte pot=0. DATAIN. There are three pins on the chip for each of the six internal variable resistors. and the interface runs much faster than the Arduino. The device is enabled by pulling the Chip Select (CS) pin low. so we don't need to worry about pre-scaling to slow down the transmission. The data clock is idle when low. This is accomplished in the main loop of the program by individually changing the resistance of each potentiometer from full off to full on over its full range of 255 steps. to: The AD5206 is a 6 channel digital potentiometer. Although we are not reading any data back out of the AD5206 in this program. The data clock is idle when low.not used. We will walk through the code in small sections. This means it has six variable resistors built in for individual electronic control. pin 12 is attached to the builtin SPI so it is best not to use it for other programming functions to avoid any possible errors: #define #define #define #define DATAOUT 11//MOSI DATAIN 12//MISO . Added lines 26-52: Finally. so we don't need to worry about pre-scaling to slow down the transmission. There are three pins on the chip for each of the six internal variable resistors. B1 and W1. PICTURE leds Program the Arduino Now we will write the code to enable SPI control of the AD5206. The device is enabled by pulling the Chip Select (CS) pin low. This means it has six variable resistors built in for individual electronic control.

The device is enabled by pulling the Chip Select (CS) pin low. AD5206 pin 7 to Arduino pin 11 (Master Out Slave In .MOSI). to: The AD5206 is digitally controlled using standard SPI. 2006.Insert the AD5206 chip into the breadboard. 10. The device is enabled by pulling the Chip Select (CS) pin low. We are connecting all the A pins to ground and all of the B pins to 5v to create 6 voltage dividers.SS). 18. and the interface runs up to speeds of 100Mhz. and 22 to ground. PICTURE datacom Restore September 05. Instructions are sent as 11 bit operational codes (opcodes) and are shifted in Most Significant Bit (MSB) first on the rising edge of the data clock.SCK). and the interface runs much faster than the Arduino. 9. 2006. Connect AD5206 pins 3. at 01:30 PM by Heather Dewey-Hagborg Changed line 15 from: The AD5206is controlled using standard SPI. The steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. There are three pins on the chip for each of the six internal variable resistors. The data clock is idle when low. The data clock is idle when low. in this tutorial we will be using each variable resistor as a voltage divider by pulling one side pin (pin B) high. to: The AD5206 is digitally controlled using standard SPI. Restore Edit Page | Page History | Printable View | All Recent Site Changes . Restore September 05. 4. Instructions are sent as 8 bit operational codes (opcodes) and are shifted in on the rising edge of the data clock. For example. at 01:34 PM by Heather Dewey-Hagborg Changed line 15 from: The AD5206 is digitally controlled using standard SPI. Instructions are sent as 8 bit operational codes (opcodes) and are shifted in on the rising edge of the data clock. For an explanation of SPI see the SPI EEPROM tutorial. and the interface runs up to speeds of 100Mhz. Introduction to the AD5206 Digital Potentiometer PICTURE pins PICTURE pin functions The AD5206 is a 6 channel digital potentiometer. 13. 15. The device is enabled by pulling the Chip Select (CS) pin low. audio signal conditioning and tone generation. and they can be interfaced with just as you would use a mechanical potentiometer. The AD5206is controlled using standard SPI. 6. 12. Restore September 05. In this example we will use a six channel digital potentiometer to control the brightness of six LEDs. 19. Instructions are sent as 11 bit operational codes (opcodes) and are shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. The data clock is idle when low. 21 and 24 to 5v and pins 1. at 01:23 PM by Heather Dewey-Hagborg Added lines 1-15: Controlling a Digital Potentiometer Using SPI In this tutorial you will learn how to control the AD5206 digital potentiometer using Serial Peripheral Interface (SPI). and AD5206 pin 8 to Arduino pin 13 (Serial Clock . 2006. pulling another side pin (pin A) low and taking the variable voltage output of the center pin (Wiper). Example applications include LED dimming. 16. PICTURE power Connect AD5206 pin 5 to Arduino pin 10 (Slave Select . Digital potentiometers are useful when you need to vary the resistance in a ciruit electronically rather than by hand. Instructions are sent as 11 bit operational codes (opcodes) and are shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. The device is enabled by pulling the Chip Select (CS) pin low. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. This means it has six variable resistors built in for individual electronic control. so we don't need to worry about pre-scaling to slow down the transmission. The device is enabled by pulling the Chip Select (CS) pin low.

.

Materials Needed: AD5206 Digital Potentiometer Arduino Microcontroller Module 6 Light Emitting Diodes (LEDs) Hookup Wire Introduction to the AD5206 Digital Potentiometer . Digital potentiometers are useful when you need to vary the resistance in a ciruit electronically rather than by hand. audio signal conditioning and tone generation. In this example we will use a six channel digital potentiometer to control the brightness of six LEDs. The steps we will cover for implementing SPI communication can be modified for use with most other SPI devices.Arduino : Tutorial / SPI Digital Pot Learning Examples | Foundations | Hacking | Links Controlling a Digital Potentiometer Using SPI In this tutorial you will learn how to control the AD5206 digital potentiometer using Serial Peripheral Interface (SPI). Example applications include LED dimming. For an explanation of SPI see the SPI EEPROM tutorial.

Instructions are sent as 11 bit operational codes (opcodes) with the three most significant bits (11-9) defining the address of which potentiometer to adjust and the eight least significant bits (8-1) defining what value to set that potentiometer to from 0-255. This means it has six variable resistors (potentiometers) built in for individual electronic control.The AD5206 is a 6 channel digital potentiometer. The device is enabled by pulling the Chip Select (CS) pin low. and they can be interfaced with just as you would use a mechanical potentiometer. Data is shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. . There are three pins on the chip for each of the six internal variable resistors. in this tutorial we will be using each variable resistor as a voltage divider by pulling one side pin (pin B) high. pulling another side pin (pin A) low and taking the variable voltage output of the center pin (Wiper). For example. Bx and Wx. A1. ie. The individual variable resistor pins are labeled Ax. The AD5206 is digitally controlled using SPI. B1 and W1.

SS). 4. 18. 6. 21 and 24 to 5v and pins 1. 12.SCK). 13. and AD5206 pin 8 to Arduino pin 13 (Serial Clock . 19. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. connect an LED between each Wiper pin (AD5206 pins 2. and the interface runs much faster than the Arduino. 15. so we don't need to worry about pre-scaling to slow down the transmission. Finally. 20 and 23) and ground so that the long pin of the LED connects to the wiper and the short pin. We are connecting all the A pins to ground and all of the B pins to 5v to create 6 voltage dividers. 16. or flat side of the LED connects to ground. 10. 14.The data clock is idle when low. 17. Connect AD5206 pins 3. 11. Connect AD5206 pin 5 to Arduino pin 10 (Slave Select . AD5206 pin 7 to Arduino pin 11 (Master Out Slave In . 9. and 22 to ground.MOSI). . Prepare the Breadboard Insert the AD5206 chip into the breadboard.

In the control register each bit sets a different functionality. byte resistance=0. digitalWrite(SLAVESELECT. the sixth bit chooses transmission with the most significant bit going first. First we set our input and output pin modes and set the SLAVESELECT line high to start. pin 12 is attached to the builtin SPI so it is best not to use it for other programming functions to avoid any possible errors: #define #define #define #define DATAOUT 11//MOSI DATAIN 12//MISO . the seventh bit enables the SPI. //disable device Now we set the SPI Control register (SPCR) to the binary value 01010000. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). The eighth bit disables the SPI interrupt.OUTPUT). pinMode(DATAIN. DATAIN. Although we are not reading any data back out of the AD5206 in this program.Program the Arduino Now we will write the code to enable SPI control of the AD5206.OUTPUT). the fifth bit puts the Arduino in Master mode. After setting our control register up we read the SPI status register (SPSR) and data register (SPDR) in to the junk clr variable to clear out any spurious data from past runs: . pinMode(SLAVESELECT. DATAOUT. the fourth bit sets the data clock idle when it is low. We will walk through the code in small sections. This deselects the device and avoids any false transmission messages due to line noise: void setup() { byte clr. pinMode(SPICLOCK. This program will sequentially pulse each LED on and then fade it out gradually. INPUT).not used. the third bit sets the SPI to sample data on the rising edge of the data clock. OUTPUT). pinMode(DATAOUT. but part of builtin SPI SPICLOCK 13//sck SLAVESELECT 10//ss Next we allocate variables to store resistance values and address values for the potentiometers: byte pot=0. This is accomplished in the main loop of the program by individually changing the resistance of each potentiometer from full off to full on over its full range of 255 steps. SPICLOCK and SLAVESELECT. We define the pins we will be using for our SPI connection.HIGH).

if (resistance==255) { pot++. //release chip.LOW). } } The spi_transfer function loads the output data into the data transmission register. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask.HIGH). delay(10).255). We pause for 10 milliseconds each iteration to make the steps visible. It then returns any data that has been shifted in to the data register by the EEPROM: char spi_transfer(volatile char data) { SPDR = data. int value) { digitalWrite(SLAVESELECT. An explanation of bit masks can be found here. } if (pot==6) { pot=0. We set the SLAVESELECT line low to enable the device. we set the SLAVSELECT line high again to release the chip and signal the end of our data transfer. We conclude the setup function by setting all the potentiometers to full on resistance states thereby turning the LEDs off: for (i=0. return SPDR. Then we transfer the address byte followed by the resistance value byte. Finally. digitalWrite(SLAVESELECT.i++) { write_pot(i. clr=SPSR. thus starting the SPI transmission. signal end transfer } LED video For easy copy and pasting the full program text of this tutorial is below: #define DATAOUT 11//MOSI .resistance). clr=SPDR. SPIF.i<6. delay(10). resistance++. byte write_pot(int address.SPCR = (1<<SPE)|(1<<MSTR). spi_transfer(value). This causes the LEDs to sequentially flash on brightly and then fade out slowly: void loop() { write_pot(pot. // return the received byte } The write_pot function allows us to control the individual potentiometers. } } In our main loop we iterate through each resistance value (0-255) for each potentiometer address (0-5). // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. //2 byte opcode spi_transfer(address).

} } code.HIGH). clr=SPSR. resistance++. byte clr.LOW). // return the received byte } void setup() { byte i. but part of builtin SPI #define SPICLOCK 13//sck #define SLAVESELECT 10//ss byte pot=0. pinMode(DATAOUT.clk low when idle. clr=SPDR.system clock/4 (fastest) SPCR = (1<<SPE)|(1<<MSTR). pinMode(SLAVESELECT. pinMode(SPICLOCK. tutorial and photos by Heather Dewey-Hagborg (Printable View of http://www. signal end transfer } void loop() { write_pot(pot.#define DATAIN 12//MISO .arduino. delay(10).i<6. INPUT). pinMode(DATAIN.HIGH).OUTPUT). spi_transfer(value). } if (pot==6) { pot=0.cc/en/Tutorial/SPIDigitalPot) . // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }.resistance). //2 byte opcode spi_transfer(address). //sample on leading edge of clk. char spi_transfer(volatile char data) { SPDR = data.not used. } } byte write_pot(int address.spi enabled. //release chip.255). int value) { digitalWrite(SLAVESELECT. //disable device // SPCR = 01010000 //interrupt disabled.msb 1st. if (resistance==255) { pot++. for (i=0. OUTPUT). byte resistance=0.i++) { write_pot(i.OUTPUT). delay(10). digitalWrite(SLAVESELECT. return SPDR.master. digitalWrite(SLAVESELECT.

0). shiftOut(dataPin.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Back to ShiftOut Tutorial //**************************************************************// // Name : shiftOutCode. int myClockPin. j). pinMode(myDataPin. //on the rising edge of the clock. clockPin. //Pin connected to SH_CP of 74HC595 int clockPin = 12. 0). //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. Hello World // Author : Carlyn Maw. int pinState. OUTPUT). // void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin. pinMode(myClockPin.0 // // Notes : Code for using a 74HC595 Shift Register // // : to count from 0 to 255 // //**************************************************************** //Pin connected to ST_CP of 74HC595 int latchPin = 8. 2006 // // Version : 1. j++) { //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin. . } void loop() { //count up routine for (int j = 0. j < 256. 1). ////Pin connected to DS of 74HC595 int dataPin = 11. delay(1000). OUTPUT).Tom Igoe // // Date : 25 Oct. } } void shiftOut(int myDataPin. OUTPUT). //clock idles low //internal function setup int i=0. byte myDataOut) { // This shifts 8 bits out MSB first.

if ( myDataOut & (1<<i) ) { pinState= 1. } else { pinState= 0. //register shifts bits on upstroke of clock pin digitalWrite(myClockPin.digitalWrite(myClockPin. for (i=7. //if the value passed to myDataOut and a bitmask result // true then. i--) { digitalWrite(myClockPin. 1). } //stop shifting digitalWrite(myClockPin. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. i>=0. } Edit Page | Page History | Printable View | All Recent Site Changes .. 0). //for each bit in the byte myDataOut… //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin.. 0). pinState). 0). 0).

////Pin connected to DS of 74HC595 int dataPin = 11.500). j++) { lightShiftPinA(j). //holder for infromation you're going to pass to shifting function byte data = 0.500). j < 8.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Back to ShiftOut Tutorial //**************************************************************// // Name : shiftOutCode. One By One // // Author : Carlyn Maw. delay(1000). //Pin connected to SH_CP of 74HC595 int clockPin = 12. // light each pin one by one using a function A for (int j = 0. void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin. // light each pin one by one using a function A for (int j = 0. OUTPUT). 2006 // // Version : 1. Tom Igoe // // Date : 25 Oct. } blinkAll(2. } } //This function uses bitwise math to move the pins up void lightShiftPinA(int p) { . j++) { lightShiftPinB(j). j < 8. delay(1000). } void loop() { //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll(1.0 // // Notes : Code for using a 74HC595 Shift Register // // : to count from 0 to 255 // //**************************************************************** //Pin connected to ST_CP of 74HC595 int latchPin = 8.

. //for each bit in the byte myDataOut… //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. digitalWrite(myClockPin. //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. } // the heart of the program void shiftOut(int myDataPin. for (int x = 0. int pinState. x < p. OUTPUT). 0). //this is line uses a bitwise operator //shifting a bit left using << is the same //as multiplying the decimal number by two. pinMode(myDataPin. clockPin. 1). pin = 1. //start with the pin = 1 so that if 0 is passed to this //function pin 0 will light. int myClockPin. OUTPUT). 0). pinMode(myClockPin. pin). 1).//defines a local variable int pin. pin). clockPin. //move 'em out shiftOut(dataPin. x++) { pin = pin * 2. pin = 1<< p. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. } //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. //clock idles low //internal function setup int i=0. //on the rising edge of the clock. //move 'em out shiftOut(dataPin. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. 0). //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin. byte myDataOut) { // This shifts 8 bits out MSB first. } //This function uses that fact that each bit in a byte //is 2 times greater than the one before it to //shift the bits higher void lightShiftPinB(int p) { //defines a local variable int pin. 0).

x < n. } else { pinState= 0. 1). 0). 0). //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin. 0). //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. delay(200). 0).. //if the value passed to myDataOut and a bitmask result // true then. delay(d). 255). void blinkAll(int n. 0). clockPin. shiftOut(dataPin. so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. } //blinks the whole register based on the number of times you want to //blink "n" and the pause between them "d" //starts with a moment of darkness to make sure the first blink //has its full visual effect. } } Edit Page | Page History | Printable View | All Recent Site Changes . i>=0. 0). 1). for (int x = 0. if ( myDataOut & (1<<i) ) { pinState= 1..for (i=7. 0). pinState). clockPin. digitalWrite(latchPin. digitalWrite(latchPin. int d) { digitalWrite(latchPin. clockPin. digitalWrite(latchPin. delay(d). 1). 0). shiftOut(dataPin. x++) { digitalWrite(latchPin. i--) { digitalWrite(myClockPin. } //stop shifting digitalWrite(myClockPin. shiftOut(dataPin. digitalWrite(latchPin. 1). } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin.

Decimal would have been fine. //Pin connected to SH_CP of 74HC595 int clockPin = 12. Tom Igoe // // Date : 25 Oct. //holders for infromation you're going to pass to shifting function byte data. //Arduino doesn't seem to have a way to write binary straight into the code //so these values are in HEX. OUTPUT).0 // // Notes : Code for using a 74HC595 Shift Register // // : to count from 0 to 255 // //**************************************************************** //Pin connected to ST_CP of 74HC595 int latchPin = 8. //11111111 dataArray[6] = 0x7E. j++) { //load the light sequence you want from array data = dataArray[j]. Predefined Array Style // // Author : Carlyn Maw. //01111110 dataArray[7] = 0x3C. //00000000 //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll(2. //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. byte dataArray[10]. //11100111 dataArray[5] = 0xFF. } void loop() { for (int j = 0. j < 10.begin(9600). //01010101 dataArray[2] = 0x81. Serial. dataArray[0] = 0xAA. ////Pin connected to DS of 74HC595 int dataPin = 11. too. 0). //11000011 dataArray[4] = 0xE7.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Back to ShiftOut Tutorial //**************************************************************// // Name : shiftOutCode. //00111100 dataArray[8] = 0x18.500). 2006 // // Version : 1. void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin. //00011000 dataArray[9] = 0x00. //10101010 dataArray[1] = 0x55. . //10000001 dataArray[3] = 0xC3.

} //stop shifting digitalWrite(myClockPin. if ( myDataOut & (1<<i) ) { pinState= 1. i--) { digitalWrite(myClockPin. digitalWrite(myClockPin. data). for (i=7. pinMode(myClockPin.. 0). 1). OUTPUT).//move 'em out shiftOut(dataPin. clockPin. . } //blinks the whole register based on the number of times you want to //blink "n" and the pause between them "d" //starts with a moment of darkness to make sure the first blink //has its full visual effect. int pinState. 0). 0). 0). //if the value passed to myDataOut and a bitmask result // true then. //for each bit in the byte myDataOut… //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. delay(1000). void blinkAll(int n. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. 0). int myClockPin. //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin. i>=0. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. 1). //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. 0). pinState). } else { pinState= 0. //clock idles low //internal function setup int i=0. //on the rising edge of the clock. pinMode(myDataPin. } } // the heart of the program void shiftOut(int myDataPin. byte myDataOut) { // This shifts 8 bits out MSB first.. int d) { digitalWrite(latchPin. so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. OUTPUT). //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin.

digitalWrite(latchPin. 0). for (int x = 0. 1). digitalWrite(latchPin. clockPin. delay(d). } } Edit Page | Page History | Printable View | All Recent Site Changes . clockPin. clockPin. 0).shiftOut(dataPin. x < n. shiftOut(dataPin. 0). shiftOut(dataPin. 255). digitalWrite(latchPin. delay(d). 1). 1). x++) { digitalWrite(latchPin. digitalWrite(latchPin. delay(200). 0).

OUTPUT). OUTPUT). j++) { //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. int pinState. //on the rising edge of the clock. //count up on GREEN LEDs shiftOut(dataPin. pinMode(myClockPin.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Back to ShiftOut Tutorial //**************************************************************// // Name : shiftOutCode. //count down on RED LEDs shiftOut(dataPin. } } void shiftOut(int myDataPin. int myClockPin. //clock idles low . Tom Igoe // // Date : 25 Oct. j < 256. clockPin. //Pin connected to SH_CP of 74HC595 int clockPin = 12. 255-j). } void loop() { //count up routine for (int j = 0.//internal function setup int i=0. clockPin. j). ////Pin connected to DS of 74HC595 int dataPin = 11. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. //set pins to output because they are addressed in the main loop pinMode(latchPin. byte myDataOut) { // This shifts 8 bits out MSB first. 2006 // // Version : 1. . void setup() { //Start Serial for debuging purposes Serial. 1). delay(1000). Dual Binary Counters // // Author : Carlyn Maw..0 // // Notes : Code for using a 74HC595 Shift Register // // : to count from 0 to 255 // //**************************************************************// //Pin connected to ST_CP of 74HC595 int latchPin = 8. 0).begin(9600).

//prepare shift register for bit shifting digitalWrite(myDataPin. for (i=7. 0). i--) { digitalWrite(myClockPin. //for each bit in the byte myDataOut… //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. i>=0. } //stop shifting digitalWrite(myClockPin. . } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. } else { pinState= 0. 0). //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. pinState). if ( myDataOut & (1<<i) ) { pinState= 1. 0). OUTPUT). //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin.pinMode(myDataPin. } Edit Page | Page History | Printable View | All Recent Site Changes . digitalWrite(myClockPin.. 0).. //if the value passed to myDataOut and a bitmask result // true then. //clear everything out just in case to . so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. 1). 0).

Dual One By One // Author : Carlyn Maw. ////Pin connected to DS of 74HC595 int dataPin = 11. j < 8. 0). //Pin connected to SH_CP of 74HC595 int clockPin = 12.0 // // Notes : Code for using a 74HC595 Shift Register // // : to count from 0 to 255 // //**************************************************************// //Pin connected to ST_CP of 74HC595 int latchPin = 8. j++) { //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. } // light each pin one by one using a function A for (int j = 0. OUTPUT). j++) { //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. //green LEDs lightShiftPinA(j). // void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin. // light each pin one by one using a function A for (int j = 0. 2006 // // Version : 1. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. j < 8. //red LEDs lightShiftPinA(7-j). Tom Igoe // // Date : 25 Oct. //holder for infromation you're going to pass to shifting function byte data = 0.500). } void loop() { //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll_2Bytes(1. .Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Back to ShiftOut Tutorial //**************************************************************// // Name : shiftOutCode. delay(1000). 0). 1).

//start with the pin = 1 so that if 0 is passed to this //function pin 0 will light. delay(1000). } //This function uses that fact that each bit in a byte //is 2 times greater than the one before it to //shift the bits higher void lightShiftPinB(int p) { //defines a local variable int pin. pin). int pinState. //move 'em out shiftOut(dataPin. pin = 1. } } //This function uses bitwise math to move the pins up void lightShiftPinA(int p) { //defines a local variable int pin. byte myDataOut) { // This shifts 8 bits out MSB first. //green LEDs lightShiftPinB(7-j). OUTPUT). 0).//red LEDs lightShiftPinB(j). //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. pin = 1<< p. int myClockPin. //for each bit in the byte myDataOut… //NOTICE THAT WE ARE COUNTING DOWN in our for loop . //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin. for (int x = 0. 1). digitalWrite(myClockPin. //this is line uses a bitwise operator //shifting a bit left using << is the same //as multiplying the decimal number by two. x++) { pin = pin * 2. clockPin. OUTPUT). pinMode(myDataPin. clockPin. 0). pin). } // the heart of the program void shiftOut(int myDataPin. x < p. } //move 'em out shiftOut(dataPin. //on the rising edge of the clock. pinMode(myClockPin. //clock idles low //internal function setup int i=0.

1). x++) { digitalWrite(latchPin. 0). x < n. shiftOut(dataPin. } //blinks both registers based on the number of times you want to //blink "n" and the pause between them "d" //starts with a moment of darkness to make sure the first blink //has its full visual effect. for (i=7. shiftOut(dataPin. digitalWrite(latchPin. 1). 255). delay(200). void blinkAll_2Bytes(int n. 0). 0). clockPin. clockPin. clockPin. 1). for (int x = 0. i>=0. pinState).. 0). 0). } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. int d) { digitalWrite(latchPin. } else { pinState= 0. i--) { digitalWrite(myClockPin.//This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. 0). clockPin. shiftOut(dataPin. shiftOut(dataPin. digitalWrite(latchPin. 0). digitalWrite(latchPin. 1).. 255). digitalWrite(latchPin. delay(d). } } Edit Page | Page History | Printable View | All Recent Site Changes . shiftOut(dataPin. clockPin. //if the value passed to myDataOut and a bitmask result // true then. shiftOut(dataPin. if ( myDataOut & (1<<i) ) { pinState= 1. 0). 0). 0). //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. } //stop shifting digitalWrite(myClockPin. clockPin. so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. delay(d). //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin.

//11111000 0xF0. void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin. //11111110 0xFC. byte dataArrayRED[10]. //11000000 0x80. ////Pin connected to DS of 74HC595 int dataPin = 11. //11100000 seem to have a way to write binary straight into the code are in HEX. //00000001 = 0x00. //00000111 = 0x03. //10000000 0x00. //11111100 0xF8. Predefined Dual Array Style // // Author : Carlyn Maw. //11111111 0xFE. too. //00000011 = 0x01. Decimal would have been fine. //11111111 = 0x7F. //11100000 0xC0. 0xFF. Decimal would have been fine. //00000000 . //00111111 = 0x1F. //Pin connected to SH_CP of 74HC595 int clockPin = 12. byte dataArrayGREEN[10]. too.begin(9600). Tom Igoe // // Date : 25 Oct. //01111111 = 0x3F. byte dataGREEN. Serial. //holders for infromation you're going to pass to shifting function byte dataRED. //00011111 = 0x0F. 2006 // // Version : 1. = 0xFF.0 // // Notes : Code for using a 74HC595 Shift Register // // : to count from 0 to 255 // //**************************************************************** //Pin connected to ST_CP of 74HC595 int latchPin = 8.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Back to ShiftOut Tutorial //**************************************************************// // Name : shiftOutCode. //00000000 0xE0. //11110000 0xE0. //Arduino doesn't //so these values dataArrayRED[0] = dataArrayRED[1] = dataArrayRED[2] = dataArrayRED[3] = dataArrayRED[4] = dataArrayRED[5] = dataArrayRED[6] = dataArrayRED[7] = dataArrayRED[8] = dataArrayRED[9] = //Arduino doesn't //so these values dataArrayGREEN[0] dataArrayGREEN[1] dataArrayGREEN[2] dataArrayGREEN[3] dataArrayGREEN[4] dataArrayGREEN[5] dataArrayGREEN[6] dataArrayGREEN[7] dataArrayGREEN[8] seem to have a way to write binary straight into the code are in HEX. //00001111 = 0x07. OUTPUT).

//00000111 //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll_2Bytes(2. i--) { digitalWrite(myClockPin. digitalWrite(myClockPin. //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. 0). 0). } else { pinState= 0. j < 10.dataArrayGREEN[9] = 0x07. int pinState. //on the rising edge of the clock. //clock idles low //internal function setup int i=0. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. . dataGREEN = dataArrayGREEN[j]. shiftOut(dataPin. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. //move 'em out shiftOut(dataPin. //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin. clockPin. if ( myDataOut & (1<<i) ) { pinState= 1.500).. pinMode(myDataPin. byte myDataOut) { // This shifts 8 bits out MSB first. dataGREEN). } } // the heart of the program void shiftOut(int myDataPin. } void loop() { for (int j = 0. j++) { //load the light sequence you want from array dataRED = dataArrayRED[j]. pinMode(myClockPin. delay(300). pinState). 0). dataRED). clockPin. for (i=7. OUTPUT). i>=0. OUTPUT).. //for each bit in the byte myDataOut… //NOTICE THAT WE ARE COUNTING DOWN in our for loop //This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. so if we are at i=6 and our value is // %11010100 it would the code compares it to %01000000 // and proceeds to set pinState to 1. //if the value passed to myDataOut and a bitmask result // true then. 0). 1). int myClockPin.

clockPin. } //stop shifting digitalWrite(myClockPin. digitalWrite(latchPin. delay(d). 0). x < n. 1). 0). clockPin. shiftOut(dataPin. 0). digitalWrite(latchPin. 0). digitalWrite(latchPin. void blinkAll_2Bytes(int n. shiftOut(dataPin. } } Edit Page | Page History | Printable View | All Recent Site Changes . clockPin. 1). 0). //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin. for (int x = 0. 1). } //blinks the whole register based on the number of times you want to //blink "n" and the pause between them "d" //starts with a moment of darkness to make sure the first blink //has its full visual effect. delay(200). shiftOut(dataPin. clockPin.//register shifts bits on upstroke of clock pin digitalWrite(myClockPin. clockPin. 0). delay(d). 255). 255). 0). shiftOut(dataPin. 1). x++) { digitalWrite(latchPin. digitalWrite(latchPin. 0). clockPin. int d) { digitalWrite(latchPin. shiftOut(dataPin. shiftOut(dataPin. 0).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Users may also wish to search for other driver chips with "595" or "596" in their part numbers. You can link multiple registers together to extend your output even more. The STP16C596 for example will drive 16 LED's and eliminates the series resistors with built-in constant current sources. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. 2006. serial or parallel-out shift register with output latches. serial or parallel-out shift register with output latches. 3-state. to: At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. This example is based on the 74HC595. Vss to: (:cell:) Output Pins Restore November 13. The STP16C596 for example will drive 16 LED's and eliminates the series resistors with built-in constant current sources. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. The datasheet refers to the 74HC595 as an “8-bit serial-in.ShiftOut History Hide minor edits . 2006. serial or parallel-out shift register with output latches.” In other words. The datasheet refers to the 74HC595 as an “8-bit serial-in. 3-state. there are many. The STP16C596 for example will drive 16 LED's and eliminates the series resistors with built-in constant current sources.” In other words. 3-state. there are many. at 05:20 PM by Carlyn Maw Changed line 21 from: (:cell:) Ground.” In other words. 2007. at 11:23 AM by Paul Badger Changed lines 7-8 from: At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. serial or parallel-out shift register with output latches. there are many.” In other words. 3-state. You can link multiple registers together to extend your output even more. The datasheet refers to the 74HC595 as an “8-bit serial-in.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. You can link multiple registers together to extend your output even more. The datasheet refers to the 74HC595 as an “8-bit serial-in. at 11:26 AM by Paul Badger Changed lines 7-10 from: At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers.Show changes to markup May 23. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. Users may also wish to search for other driver chips with "595" or "596" in their part numbers. at 05:18 PM by Carlyn Maw Changed lines 83-84 from: to: .) Restore May 23. 2007. Restore December 07. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. This example is based on the 74HC595. This example is based on the 74HC595. You can link multiple registers together to extend your output even more. This example is based on the 74HC595. to: At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. (Users may also wish to search for other driver chips with "595" or "596" in their part numbers.

Added lines 124-127: Circuit Diagram .

Restore November 09. 2006. at 04:25 PM by Carlyn Maw Changed lines 89-91 from: 595 Logic Table .

When the latchPin goes from low to high the sent data gets moved from the shift registers aforementioned memory register into the output pins. . to: In this case you should connect the cathode (short pin) of each LED to a common ground. lighting the LEDs. As the data gets shifted in it is saved in an internal memory register. and the anode (long pin) of each LED to its respective shift register output pin. You should check the your specific datasheet if you aren’t using a 595 series chip. lighting the LEDs. Some shift registers won't supply power. When the clockPin goes from low to high. to: 595 Logic Table 595 Timing Diagram The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. The logic table is what tells you that basically everything important happens on an up beat. 2006. If you have one of those it means you will have to flip the direction of the LEDs. When the clockPin goes from low to high. When the latchPin goes from low to high the sent data gets moved from the shift registers aforementioned memory register into the output pins. Using the shift register to supply power like this is called sourcing current. Some shift registers can't source current. they can only do what is called sinking current. doubling the number of output pins you have while still using the same number of pins from the Arduino. The logic table is what tells you that basically everything important happens on an up beat. at 04:22 PM by Carlyn Maw Changed lines 77-78 from: In this case you should connect the cathode (short pin) of each LED to a common ground. they will only ground.595 Timing Diagram The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. As the data gets shifted in it is saved in an internal memory register. Restore November 09. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded. You should check the your specific datasheet if you aren’t using a 595 series chip. the shift register reads the state of the data pin. Added lines 100-101: In this example you’ll add a second shift register. and the anode (long pin) of each LED to its respective shift register output pin. putting the anodes directly to power and the cathodes (ground pins) to the shift register outputs. the shift register reads the state of the data pin. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded.

you can’t set pins to their high impedance state individually. When the latchPin goes from low to high the sent data gets moved from the shift registers aforementioned memory register into the output pins. at 03:07 PM by Carlyn Maw Added lines 87-88: Here are three code examples. the shift register reads the state of the data pin. at 04:10 PM by Carlyn Maw Changed lines 13-14 from: “3 states” refers to the fact that you can set the output pins as either high. low or “high impedance. As the data gets shifted in it is saved in an internal memory register. 2006. The third cycles through an array. The logic table is what tells you that basically everything important happens on an up beat.” Unlike the HIGH and LOW states. lighting the LEDs. You can only set the whole chip together. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. This is a pretty specialized thing to do -. The second program lights one LED at a time. The third cycles through an array. you can’t set pins to their high impedance state individually. 2006. lighting the LEDs. The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. You can only set the whole chip together.” Unlike the HIGH and LOW states. Niether example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. When the clockPin goes from low to high. Changed lines 90-97 from: 595 Timing Diagram Here are three code examples. the shift register reads the state of the data pin. 2006. The logic table is what tells you that basically everything important happens on an up beat. This is a pretty specialized thing to do -. low or “high impedance. When the clockPin goes from low to high.Restore November 09. When the latchPin goes from low to high the sent data gets moved from the shift registers aforementioned memory register into the output pins. The second program lights one LED at a time. The first is just some “hello world” code that simply outputs a byte value from 0 to 255.Think of an LED array that might need to be controlled by completely different microcontrollers depending on a specific mode setting built into your project. to: 595 Timing Diagram The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. Added lines 96-97: . at 03:07 PM by Carlyn Maw Restore November 09. to: “3 states” refers to the fact that you can set the output pins as either high. Restore November 09.Think of an LED array that might need to be controlled by completely different microcontrollers depending on a specific mode setting built into your project. As the data gets shifted in it is saved in an internal memory register. Neither example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it.

The second program lights one LED at a time.png Here are three code examples. The third cycles through an array.cc/en/uploads/Tutorial/595_logic_table. The third cycles through an array. Changed lines 91-97 from: . to: Here are three code examples. 2006. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. 2006. The second program lights one LED at a time.arduino.Restore November 09. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. at 03:02 PM by Carlyn Maw Changed lines 87-88 from: http://www. at 03:04 PM by Carlyn Maw Added lines 87-89: 595 Logic Table 595 Timing Diagram Deleted lines 93-95: 595 Logic Table 595 Timing Diagram Restore November 09.

595 Logic Table 595 Logic Table .

The first is just some “hello world” code that simply outputs a byte value from 0 to 255. The third cycles through an array. The second program lights one LED at a time. at 03:00 PM by Carlyn Maw Changed lines 87-88 from: Here are three code examples. to: http://www.cc/en/uploads/Tutorial/595_logic_table. The third cycles through an array.png Here are three code examples. The first is just some “hello world” code that simply outputs a byte value from 0 to 255.arduino.to: 595 Logic Table 595 Timing Diagram Restore November 09. The second program lights one LED at a time. 2006. Added lines 91-94: .

at 02:46 PM by Carlyn Maw Deleted lines 54-55: Added lines 63-64: .595 Logic Table 595 Logic Table Restore November 09. 2006.

Deleted lines 66-67: Added lines 73-74: .

you should put a second shift register on the board. Deleted lines 108-109: Added lines 112-113: . Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded. It should have the same leads to power and ground. Deleted lines 80-81: In this case you should connect the cathode (short pin) of each LED to a common ground. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded. and the anode (long pin) of each LED to its respective shift register output pin. It should have the same leads to power and ground. you should put a second shift register on the board. they will only ground.Added lines 77-78: In this case you should connect the cathode (short pin) of each LED to a common ground. Deleted lines 107-108: Starting from the previous example. You should check the your specific datasheet if you aren’t using a 595 series chip. they will only ground. Some shift registers won't supply power. Some shift registers won't supply power. Added lines 104-105: Starting from the previous example. You should check the your specific datasheet if you aren’t using a 595 series chip. and the anode (long pin) of each LED to its respective shift register output pin.

at 02:41 PM by Carlyn Maw Restore November 09. 2006. at 02:41 PM by Carlyn Maw Changed line 18 from: (:cell rowspan=9 :) to: .Added lines 116-117: In this case I added green ones so when reading the code it is clear which byte is going to which set of LEDs Deleted lines 119-120: In this case I added green ones so when reading the code it is clear which byte is going to which set of LEDs Restore November 09. 2006.

(:cell rowspan=9 :) Changed lines 55-56 from: to: .

Changed lines 67-68 from: to: .

Changed lines 77-78 from: to: .

Changed lines 104-105 from: to: .

Changed line 110 from: to: .

gif Δ to: .Changed lines 116-117 from: Attach:Exmp2_3.

Restore November 09. 2006. at 02:19 PM by Carlyn Maw Added lines 55-56: . at 02:22 PM by Carlyn Maw Changed lines 77-78 from: Attach:Exmp1_.gif Δ to: Restore November 09. 2006.

gif Δ Added lines 83-84: Added lines 91-93: .Added lines 67-68: Changed lines 75-76 from: Add 8 LEDs. Add 8 LEDs. to: 3. Attach:Exmp1_.

Added lines 104-105: .

Added lines 109-110: Added lines 115-117: Attach:Exmp2_3. at 02:08 PM by Carlyn Maw Changed lines 15-17 from: Here is a table explaining the pin-outs adapted from the datasheet. (:table border=1 cellpadding=5 cellspacing=0:) to: Here is a table explaining the pin-outs adapted from the Phillip's datasheet. at 02:01 PM by Carlyn Maw Changed lines 18-48 from: (:cell rowspan=9 :) a1 (:cell:) b1 (:cell:) c1 (:cell:) d1 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 . 2006. (:table border=1 bordercolor=#CCCCCC cellpadding=5 cellspacing=0:) Restore November 09. 2006.gif Δ Restore November 09.

active low (:cellnr:) PIN 14 (:cell:) DS (:cell:) Serial data input (:cellnr:) PIN 16 (:cell:) Vcc (:cell:) Positive supply voltage Deleted lines 47-48: Restore November 09. 2006. at 01:49 PM by Carlyn Maw Changed lines 13-14 from: “3 states” refers to the fact that you can set the output pins as either high. active low (:cellnr:) PIN 11 (:cell:) SH_CP (:cell:) Shift register clock pin (:cellnr:) PIN 12 (:cell:) ST_CP (:cell:) Storage register clock pin (latch pin) (:cellnr:) PIN 13 (:cell:) OE (:cell:) Output enable. (:cell rowspan=9 :) Vss (:cellnr:) PIN 8 (:cell:) GND (:cell:) Ground. 2006.Think of an LED array that might need to be controlled by completely different microcontrollers depending on a specific mode setting built into your project. Niether example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it.(:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 to: (:cell:) PINS 1-7. you can’t set pins to their high impedance state individually. This is a . low or “high impedance.” Unlike the HIGH and LOW states. to: “3 states” refers to the fact that you can set the output pins as either high. Vss (:cellnr:) PIN 9 (:cell:) Q7’ (:cell:) Serial Out (:cellnr:) PIN 10 (:cell:) MR (:cell:) Master Reclear. 15 (:cell:) Q0 – Q7 (:cell:) Ground. You can only set the whole chip together. at 01:53 PM by Carlyn Maw Added lines 17-50: (:table border=1 cellpadding=5 cellspacing=0:) (:cell rowspan=9 :) a1 (:cell:) b1 (:cell:) c1 (:cell:) d1 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:cellnr:) b2 (:cell:) c2 (:cell:) d2 (:tableend:) Restore November 09.” Unlike the HIGH and LOW states. You can only set the whole chip together. you can’t set pins to their high impedance state individually. low or “high impedance. This is a pretty specialized thing to do -.

to: How this all works is through something called “synchronous serial communication. Niether example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. the shift register isn’t actively set to either a high or low voltage.pretty specialized thing to do -. It's by pulsing second pin. Once the whole byte is transmitted to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. Restore November 09. it will output whatever voltage you have connected to the Vcc pin. for example.” i. This is in contrast to using the “asynchronous serial communication” of the Serial.begin() function which relies on the sender and the receiver to be set independently to an agreed upon specified data rate. This is a pretty specialized thing to do -.Think of an LED array that might need to be controlled by completely different microcontrollers depending on a specific mode setting built into your project. This is in contrast using the “asynchronous serial communication” of the Serial.” Unlike the HIGH and LOW states. it will output whatever voltage you have connected to the Vcc pin. Here is a table explaining the pin-outs adapted from the datasheet. When you set low it will output zero volts (Vss). low or “high impedance. low or “high impedance.Think of an LED array that might need to be controlled by completely different microcontrollers depending on a specific mode setting built into your project. that you delineate between bits. Unlike the HIGH and LOW states. When you set low it will output zero volts (Vss). you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. the shift register isn’t actively set to either a high or . High impedance is meant to be a type of blank state so if you wanted to have the outputs attached to one register controlled by. you can’t set pins to their high impedance state individually. When a pin is in a high impedance state. the clock pin. at 07:38 PM by Carlyn Maw Changed lines 9-10 from: How this all works is through something called “synchronous serial communication. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. low or “high impedance.” When you set a pin set high by sending a 1 bit to that address.e.e. so you don’t need to spend a lot of time on it now. you can’t set pins to their high impedance state individually.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate. When a pin is in a high impedance state. Changed lines 13-14 from: "3 states" refers to the fact that you can set the output pins as either high. the clock pin. 2006. you can only set the whole chip together. to: “3 states” refers to the fact that you can set the output pins as either high. Restore November 01. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. This is the “parallel output” part.” When you set a pin set high by sending a 1 bit to that address. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project. having all the pins do what you want them to do all at once. 2006. Neither example takes advantage of this feature as it is a pretty specialized thing to do. Niether example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. You can only set the whole chip together.” i. having all the pins do what you want them to do all at once. Once the whole byte gets to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. at 01:45 PM by Carlyn Maw Changed lines 13-14 from: "3 states" refers to the fact that you can set the output pins as either high. It's by pulsing second pin. that you delineate between bits. This is the “parallel output” part. a second register attached in parallel to the original circuit you could do so without competition.

it will output whatever voltage you have connected to the Vcc pin. you can only set the whole chip together. low or “high impedance. you can only set the whole chip together. You should check the your specific datasheet if you aren’t using a 595 series chip. a second register attached in parallel to the original circuit you could do so without competition. When the latchPin goes from low to high the sent data gets moved from the shift registers aforementioned memory register into the output pins. the clockPin and the latchPin respectively. The logic table is what tells you that basically everything important happens on an up beat When the clockPin goes from low to high. if you have some flicker when the latch pin pulses you can use a capacitor to even it out. for example. lighting the LEDs. High impedance is meant to be a type of blank state so if you wanted to have the outputs attached to one register controlled by. they will only ground. Changed lines 36-37 from: From now on those will be refered to as the dataPin. Neither example takes advantage of this feature. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. Unlike the HIGH and LOW states. When you set low it will output zero volts (Vss). lighting the LEDs. and it is a pretty specialized thing to do. You can get around this by controlling the MR and OE pins from your Arduino board too. if you notice some flicker every time the latch pin pulses you can use a capacitor to even it out. the shift register reads the state of the data pin. and the anode (long pin) of each to its respective shift register output pin. the shift register isn’t actively set to either a high or low voltage. When the clockPin goes from low to high. You should check the your specific datasheet if you aren’t using a 595 series chip. Neither example takes advantage of this feature as it is a pretty specialized thing to do. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project. but this will work and leave you with more open pins.1µf capacitor on the latchPin.low voltage. Changed lines 28-29 from: This set up makes all of the output pins active and addressable all the time.” When you set a pin set high by sending a 1 bit to that address. to: From now on those will be refered to as the dataPin. so you don’t need to spend a lot of time on it now. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded. When the latchPin goes from low to high the sent data gets moved from the aforementioned memory register into the output pins. High impedance is meant to be a type of blank state so if you wanted to have the outputs attached to one register controlled by. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project. Changed lines 48-49 from: The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. Unlike the HIGH and LOW states. Some shift registers won't supply power. As the data gets shifted in it is saved in an internal memory register. to: This set up makes all of the output pins active and addressable all the time. The one flaw of this set up is that you end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. but this way will work and leave you with more open pins. When a pin is in a high impedance state. The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. the shift register reads the state of the data pin. The logic table is what tells you that basically everything important happens on an up beat. to: "3 states" refers to the fact that you can set the output pins as either high. the clockPin and the latchPin respectively. they will only ground. Some shift registers won't supply power. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded. Notice the 0. As the data gets shifted in it is saved in an internal memory register on the shift register. you can’t set pins to their high impedance state individually. you can’t set pins to their high impedance state individually. so you don’t need to spend a lot of time on it now. and the anode (long pin) of each LED to its respective shift register output pin. for example. Notice the 0. to: The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. . Changed lines 40-41 from: In this case you should connect the cathode (short pin) of each LED to a common ground.1µf capacitor on the latchPin. a second register attached in parallel to the original circuit you could do so without competition. You can get around this by also controlling the MR and OE pins from your Arduino board. to: In this case you should connect the cathode (short pin) of each LED to a common ground.

at 06:51 PM by Carlyn Maw Restore November 01. to: "3 states" refers to the fact that you can set the output pins as either high. that you delineate between bits.3 also takes advantage of the new blinkAll_2bytes() function.3 is only that instead of just a single variable called “data” and a single array called “dataArray” you have to have a dataRED. dataArrayRED. When you set low it will output zero volts (Vss). to: How this all works is through something called “synchronous serial communication. Once the whole byte gets to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. This is in contrast using the “asynchronous serial communication” of the Serial. for example. a dataGREEN. and it is a pretty specialized thing to do.Restore November 01. When a pin is in a high impedance state. it will output whatever voltage you have connected to the Vcc pin. at 06:46 PM by Carlyn Maw Changed line 79 from: Code Sample 2. Neither example takes advantage of this feature.Dual Defined Arrays\\ Restore . When you set low it will output zero volts (Vss).3 . This is the “parallel output” part. dataArrayGREEN defined up front. a dataGREEN. the shift register isn’t actively set to either a high or low voltage.” i. having all the pins do what you want them to do all at once. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project.3 also takes advantage of the new blinkAll_2bytes() function. This is in contrast using the “asynchronous serial communication” of the Serial.e. low or “high impedance. dataArrayRED. High impedance is meant to be a type of blank state so if you wanted to have the outputs attached to one register controlled by. so you don’t need to spend a lot of time on it now. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW.e. This means that line Restore November 01. Restore November 01. It's by pulsing second pin.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate. 2006. low or “high impedance.” When you set a pin set high by sending a 1 bit to that address. the clock pin. Once the whole byte gets to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. you can only set the whole chip together. Unlike the HIGH and LOW states. you can’t set pins to their high impedance state individually. 2. for example. you can’t set pins to their high impedance state individually. Its big difference from 1.3's big difference from sample 1. This means that later on line to: Like sample 2. 2006. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. Changed lines 13-14 from: The 3 states refers to the fact that you can set the output pins as either high. you can only set the whole chip together.2. and it is a pretty specialized thing to do.Dual Defined Arrays to: Code Sample 2. a second register attached in parallel to the original circuit you could do so without competition. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project.” When you set a pin set high by sending a 1 bit to that address. so you don’t need to spend a lot of time on it now.3 .” i. 2006. Unlike the HIGH and LOW states. sample 2.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate. at 06:51 PM by Carlyn Maw Changed lines 80-81 from: 2. it will output whatever voltage you have connected to the Vcc pin. having all the pins do what you want them to do all at once. dataArrayGREEN defined up front. High impedance is meant to be a type of blank state so if you wanted to have the outputs attached to one register controlled by. 2006. When a pin is in a high impedance state. at 07:28 PM by Carlyn Maw Changed lines 9-10 from: How this all works is through something called “synchronous serial communication. Neither example takes advantage of this feature. that you delineate between bits. a second register attached in parallel to the original circuit you could do so without competition. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. This is the “parallel output” part.3 is only that instead of just a single variable called “data” and a single array called “dataArray” you have to have a dataRED. the shift register isn’t actively set to either a high or low voltage. Its by pulsing second pin. the clock pin.

Also. Starting from the previous example. It should have the same leads to power and ground.2 – 2 Byte One By One Comparing this code to the similar code from Example 1 you see that a little bit more has had to change. Add a second shift register. 06 Changed line 73 from: Code Sample 2. a dataGREEN. Here they need to be moved back into the main loop to accommodate needing to run each subfunction twice in a row. In this case I added green ones so when reading the code it is clear which byte is going to which set of LEDs The Code Here again are three code samples. clockPin. 2006. shiftOut(dataPin. 2. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires). Its big difference from 1. This forces the first shift register. at 06:41 PM by Carlyn Maw Added lines 53-74: Example 2 The Circuit 1. to pass . Code Sample 2. Restore November 01. dataGREEN).November 01.3 . The blinkAll() function has been changed to the blinkAll_2Bytes() function to reflect the fact that now there are 16 LEDs to control. you might want to try the samples from the first example with this circuit set up just to see what happens.3 also takes advantage of the new blinkAll_2bytes() function. If you are curious.Dual Defined Arrays 2. the one directly attached to the Arduino. clockPin. The blue wire is going from the serial out pin (pin 9) of the first shift register to the serial data input (pin 14) of the second register. and shiftOut(dataPin. clockPin.3 is only that instead of just a single variable called “data” and a single array called “dataArray” you have to have a dataRED. becomes shiftOut(dataPin. Code Sample 2. you should put a second shift register on the board. dataArrayRED. This means that later on line data = dataArray[j]. 2006.1 – Dual Binary Counters\\ Added lines 75-97: Code Sample 2. at 06:45 PM by Carlyn Maw Changed lines 3-4 from: Carlyn Maw. dataArrayGREEN defined up front. becomes dataRED = dataArrayRED[j]. data). Add a second set of LEDs. 3. dataRED). Connect the 2 registers. Tom Igoe to: Started by Carlyn Maw and Tom Igoe Nov.1 – Dual Binary Counters to: Code Sample 2. in version 1 the pulsings of the latchPin were situated inside the subfunctions lightShiftPinA and lightShiftPinB(). once for the green LEDs and once for the red ones. It sends out a second byte.1 – Dual Binary Counters There is only one extra line of code compared to the first code sample from Example 1. dataGREEN = dataArrayGREEN[j].

1µf capacitor on the latchPin. they will only ground.2 – One by One Restore November 01. the clockPin and the latchPin respectively. if you notice some flicker every time the latch pin pulses you can use a capacitor to even it out. lighting the green LEDs. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded. In this case you should connect the cathode (short pin) of each LED to a common ground. 2006. Notice the 0.2 – One by One Code Sample 1. As the data gets shifted in it is saved in an internal memory register on the shift register. Code Sample 1.2 – One by One to: Code Sample 1. 2006. Tom Igoe Changed line 36 from: I’m going to refer to them from now on as the dataPin.the first byte sent through to the second register. Notice the 0.1 – Hello World Code Sample 1. the clockPin and the latchPin respectively.1 – Hello World Code Sample 1. Notice the 0. the clockPin and the latchPin respectively. You should check the your specific datasheet if you aren’t using a 595 series chip. the shift register reads the state of the data pin. Restore November 01. The third cycles through an array. to: From now on those will be refered to as the dataPin. at 06:19 PM by Carlyn Maw Changed lines 3-4 from: by Carlyn Maw to: Carlyn Maw. at 06:25 PM by Carlyn Maw Changed lines 36-42 from: From now on those will be refered to as the dataPin. The logic table is what tells you that basically everything important happens on an up beat When the clockPin goes from low to high. The code is based on two pieces of information in the datasheet: the timing diagram and the logic table.3 – from Defined Array\\ Restore November 01. The second byte will then show up on the red LEDs. The second program lights one LED at a time. lighting the LEDs. Circuit Diagram Restore November 01. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. at 06:34 PM by Carlyn Maw Changed lines 50-51 from: Code Sample 1. and the anode (long pin) of each to its respective shift register output pin. 2006. Add 8 LEDs. When the latchPin goes from low to high the sent data gets moved from the aforementioned memory register into the output pins.1 – Hello World Restore November 01. Some shift registers won't supply power.1µf capacitor on the latchPin. at 06:32 PM by Carlyn Maw Added line 51: Code Sample 1. 2006. to: . The first is just some “hello world” code that simply outputs a byte value from 0 to 255. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out.1µf capacitor on the latchPin. 2006. at 06:27 PM by Carlyn Maw Added lines 43-50: The Code Here are three code examples.

The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before . you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. Unlike the HIGH and LOW states.1µf capacitor on the latchPin. serial or parallel-out shift register with output latches. at 06:17 PM by Carlyn Maw Changed lines 51-52 from: This set up makes all of the output pins active and addressable all the time. Notice the 0. The Circuit 1. Restore November 01.e. You can learn to do that from the second example. The 3 states refers to the fact that you can set the output pins as either high. the clockPin and the latchPin respectively. the shift register isn’t actively set to either a high or low voltage. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. the clockPin and the latchPin respectively.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate. and it is a pretty specialized thing to do. having all the pins do what you want them to do all at once.” i. The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. at 06:18 PM by Carlyn Maw Deleted lines 27-49: This set up makes all of the output pins active and addressable all the time. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. This is the “parallel output” part. Restore November 01.” When you set a pin set high by sending a 1 bit to that address. low or “high impedance. How this all works is through something called “synchronous serial communication. You can link multiple registers together to extend your output even more. The “serial output” part of this component comes from its extra pin which can pass the serial information received from the microcontroller out again unchanged.1µf capacitor on the latchPin. a second register attached in parallel to the original circuit you could do so without competition. Example 1: One Shift Register The first step is to extend your Arduino with one shift register. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project. ======= At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. it will output whatever voltage you have connected to the Vcc pin.1µf capacitor on the latchPin. The datasheet refers to the 74HC595 as an “8-bit serial-in. 2006. so you don’t need to spend a lot of time on it now. This is in contrast using the “asynchronous serial communication” of the Serial. Notice the 0. When a pin is in a high impedance state. Notice the 0. you can only set the whole chip together.From now on those will be refered to as the dataPin. Its by pulsing second pin. High impedance is meant to be a type of blank state so if you wanted to have the outputs attached to one register controlled by. Once the whole byte gets to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. When you set low it will output zero volts (Vss). you can’t set pins to their high impedance state individually. This means you can transmit 16 bits in a row (2 bytes) and the first 8 will flow through the first register into the second register and be expressed there. Vcc (pin 16) to 5V OE (pin 13) to ground MR (pin 10) to 5V Changed line 36 from: I’m going to refer to them from now on as the dataPin. to: I’m going to refer to them from now on as the dataPin. Neither example takes advantage of this feature. >>>>>>> to: This set up makes all of the output pins active and addressable all the time. The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. This example is based on the 74HC595. Turning it on Make the following connections: GND (pin 8) to ground. 2006.” In other words. 3-state. that you delineate between bits. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. the clockPin and the latchPin respectively. for example. the clock pin.

The Circuit 1. having all the pins do what you want them to do all at once. This means you can transmit 16 bits in a row (2 bytes) and the first 8 will flow through the first register into the second register and be expressed there. Neither example takes advantage of this feature. The 3 states refers to the fact that you can set the output pins as either high. Its by pulsing second pin. at 06:13 PM by Carlyn Maw Added line 4: <<<<<<< Changed lines 26-50 from: This set up makes all of the output pins active and addressable all the time. it will output whatever voltage you have connected to the Vcc pin. ======= At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. Once the whole byte gets to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. a second register attached in parallel to the original circuit you could do so without competition. You can learn to do that from the second example. the shift register isn’t actively set to either a high or low voltage. This is in contrast using the “asynchronous serial communication” of the Serial. that you delineate between bits.e. to: This set up makes all of the output pins active and addressable all the time. 2006. low or “high impedance. at 06:13 PM by Carlyn Maw Added lines 2-4: by Carlyn Maw Deleted line 6: <<<<<<< Restore November 01. you can’t set pins to their high impedance state individually.” When you set a pin set high by sending a 1 bit to that address. High impedance is meant to be a type of blank state so if you wanted to have the outputs attached to one register controlled by. 2. and it is a pretty specialized thing to do. the clock pin. The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. Unlike the HIGH and LOW states. the clockPin and the latchPin respectively. You can link multiple registers together to extend your output even more. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project.” i. for example. This is the “parallel output” part. How this all works is through something called “synchronous serial communication. The datasheet refers to the 74HC595 as an “8-bit serial-in. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. Notice the 0. you can only set the whole chip together. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. When you set low it will output zero volts (Vss). The “serial output” part of this component comes from its extra pin which can pass the serial information received from the microcontroller out again unchanged. so you don’t need to spend a lot of time on it now. Example 1: One Shift Register The first step is to extend your Arduino with one shift register. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. This example is based on the 74HC595. When a pin is in a high impedance state. Turning it on . but this will work and leave you with more open pins. Restore November 01. serial or parallel-out shift register with output latches.the program starts to run.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate. 2006. Connect to Arduino DS (pin 14) to Ardunio DigitalPin 11 (blue wire) SH_CP (pin 11) to to Ardunio DigitalPin 12 (yellow wire) ST_CP (pin 12) to Ardunio DigitalPin 8 (green wire) I’m going to refer to them from now on as the dataPin. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. You can get around this by also controlling the MR and OE pins from your Arduino board.” In other words.1µf capacitor on the latchPin. 3-state.

Vcc (pin 16) to 5V OE (pin 13) to ground MR (pin 10) to 5V This set up makes all of the output pins active and addressable all the time. a second register attached in parallel to the original circuit you could do so without competition. Unlike the HIGH and LOW states. The 3 states refers to the fact that you can set the output pins as either high. Once the whole byte gets to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. Its by pulsing second pin.” i. How this all works is through something called “synchronous serial communication. Restore Edit Page | Page History | Printable View | All Recent Site Changes . The datasheet refers to the 74HC595 as an “8-bit serial-in. High impedance is meant to be a type of blank state so if you wanted to have the outputs attached to one register controlled by. 3-state. The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. the clock pin. at 06:13 PM by Carlyn Maw Added lines 11-25: Example 1: One Shift Register The first step is to extend your Arduino with one shift register.Make the following connections: GND (pin 8) to ground.” In other words. The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. This example is based on the 74HC595. you can only set the whole chip together. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project. Neither example takes advantage of this feature. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. When you set low it will output zero volts (Vss). so you don’t need to spend a lot of time on it now. and it is a pretty specialized thing to do. that you delineate between bits. The “serial output” part of this component comes from its extra pin which can pass the serial information received from the microcontroller out again unchanged.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate. it will output whatever voltage you have connected to the Vcc pin. This is the “parallel output” part. You can link multiple registers together to extend your output even more. This means you can transmit 16 bits in a row (2 bytes) and the first 8 will flow through the first register into the second register and be expressed there. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. 2006. for example. >>>>>>> Restore November 01. Restore November 01. Turning it on Make the following connections: GND (pin 8) to ground. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. low or “high impedance. having all the pins do what you want them to do all at once. at 06:09 PM by Carlyn Maw Added lines 1-10: Serial to Parallel Shifting-Out with a 74HC595 Shifting Out & the 595 chip At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. the shift register isn’t actively set to either a high or low voltage. serial or parallel-out shift register with output latches.” When you set a pin set high by sending a 1 bit to that address. 2006. This is in contrast using the “asynchronous serial communication” of the Serial. you can’t set pins to their high impedance state individually.e. The Circuit 1. Vcc (pin 16) to 5V OE (pin 13) to ground MR (pin 10) to 5V This set up makes all of the output pins active and addressable all the time. You can learn to do that from the second example. When a pin is in a high impedance state.

.

” In other words. Once the whole byte is transmitted to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. Neither example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. 15 Q0 – Q7 Output Pins PIN 8 PIN 9 PIN 10 PIN 11 PIN 12 PIN 13 PIN 14 PIN 16 GND Q7’ MR SH_CP ST_CP OE DS Vcc Ground. “3 states” refers to the fact that you can set the output pins as either high. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit.) How this all works is through something called “synchronous serial communication.” i. active low Serial data input Positive supply voltage . having all the pins do what you want them to do all at once. You can link multiple registers together to extend your output even more.Think of an LED array that might need to be controlled by completely different microcontrollers depending on a specific mode setting built into your project.e. The datasheet refers to the 74HC595 as an “8-bit serial-in. Vss Serial Out Master Reclear. PINS 1-7. serial or parallel-out shift register with output latches. This is a pretty specialized thing to do -. low or “high impedance. This is the “parallel output” part. You can only set the whole chip together. It's by pulsing second pin. This means you can transmit 16 bits in a row (2 bytes) and the first 8 will flow through the first register into the second register and be expressed there. This is in contrast to using the “asynchronous serial communication” of the Serial. 3-state. You can learn to do that from the second example. that you delineate between bits. active low Shift register clock pin Storage register clock pin (latch pin) Output enable. The STP16C596 for example will drive 16 LED's and eliminates the series resistors with built-in constant current sources. The “serial output” part of this component comes from its extra pin which can pass the serial information received from the microcontroller out again unchanged.begin() function which relies on the sender and the receiver to be set independently to an agreed upon specified data rate. the clock pin.Arduino : Tutorial / Shift Out Learning Examples | Foundations | Hacking | Links Serial to Parallel Shifting-Out with a 74HC595 Started by Carlyn Maw and Tom Igoe Nov. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. 06 Shifting Out & the 595 chip At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. (Users may also wish to search for other driver chips with "595" or "596" in their part numbers.” Unlike the HIGH and LOW states. there are many. you can’t set pins to their high impedance state individually. This example is based on the 74HC595. Here is a table explaining the pin-outs adapted from the Phillip's datasheet .

Vcc (pin 16) to 5V OE (pin 13) to ground MR (pin 10) to 5V This set up makes all of the output pins active and addressable all the time.1µf capacitor on the latchPin. The one flaw of this set up is that you end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. The Circuit 1. Notice the 0. You can get around this by controlling the MR and OE pins from your Arduino board too. . Connect to Arduino DS (pin 14) to Ardunio DigitalPin 11 (blue wire) SH_CP (pin 11) to to Ardunio DigitalPin 12 (yellow wire) ST_CP (pin 12) to Ardunio DigitalPin 8 (green wire) From now on those will be refered to as the dataPin. the clockPin and the latchPin respectively.Example 1: One Shift Register The first step is to extend your Arduino with one shift register. but this way will work and leave you with more open pins. 2. if you have some flicker when the latch pin pulses you can use a capacitor to even it out. Turning it on Make the following connections: GND (pin 8) to ground.

Add 8 LEDs. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded. putting the anodes directly to power and the cathodes (ground pins) to the shift register outputs. In this case you should connect the cathode (short pin) of each LED to a common ground. Circuit Diagram .3. and the anode (long pin) of each LED to its respective shift register output pin. Using the shift register to supply power like this is called sourcing current. You should check the your specific datasheet if you aren’t using a 595 series chip. Some shift registers can't source current. If you have one of those it means you will have to flip the direction of the LEDs. they can only do what is called sinking current.

the shift register reads the state of the data pin. The second program lights one LED at a time.2 – One by One Code Sample 1. The third cycles through an array. doubling the number of output pins you have while still using the same number of pins from the Arduino. The logic table is what tells you that basically everything important happens on an up beat. When the clockPin goes from low to high.The Code Here are three code examples. When the latchPin goes from low to high the sent data gets moved from the shift registers aforementioned memory register into the output pins. . As the data gets shifted in it is saved in an internal memory register. The Circuit 1.1 – Hello World Code Sample 1.3 – from Defined Array 595 Logic Table 595 Timing Diagram Example 2 In this example you’ll add a second shift register. Code Sample 1. lighting the LEDs. The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. Add a second shift register.

Add a second set of LEDs. 2. The blue wire is going from the serial out pin (pin 9) of the first shift register to the serial data input (pin 14) of the second register. Connect the 2 registers. 3. It should have the same leads to power and ground. In this case I added green ones so when reading the code it is clear which byte is going to which set of LEDs .Starting from the previous example. you should put a second shift register on the board. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires).

Circuit Diagram .

in version 1 the pulsings of the latchPin were situated inside the subfunctions lightShiftPinA and lightShiftPinB(). Code Sample 2. Here they need to be moved back into the main loop to accommodate needing to run each . to pass the first byte sent through to the second register. Code Sample 2. The second byte will then show up on the red LEDs. you might want to try the samples from the first example with this circuit set up just to see what happens. This forces the first shift register. lighting the green LEDs.1 – Dual Binary Counters There is only one extra line of code compared to the first code sample from Example 1. The blinkAll() function has been changed to the blinkAll_2Bytes() function to reflect the fact that now there are 16 LEDs to control. Also. It sends out a second byte. If you are curious. the one directly attached to the Arduino.The Code Here again are three code samples.2 – 2 Byte One By One Comparing this code to the similar code from Example 1 you see that a little bit more has had to change.

subfunction twice in a row. sample 2. dataGREEN = dataArrayGREEN[j]. becomes dataRED = dataArrayRED[j].cc/en/Tutorial/ShiftOut) . (Printable View of http://www.3 is only that instead of just a single variable called “data” and a single array called “dataArray” you have to have a dataRED. clockPin. shiftOut(dataPin. once for the green LEDs and once for the red ones. dataGREEN).arduino. dataRED).3's big difference from sample 1.3 also takes advantage of the new blinkAll_2bytes() function.3 . data). Code Sample 2. clockPin. 2. This means that line data = dataArray[j]. clockPin. a dataGREEN. dataArrayRED. becomes shiftOut(dataPin.2.Dual Defined Arrays Like sample 2. dataArrayGREEN defined up front. and shiftOut(dataPin.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

e.version()). at 10:22 AM by Tom Igoe Added lines 29-34: version(void) . 2007.initialize an instance of the X10 library on two digital pins.g. // initializes X10 on pins 9 (zero crossing pin) and 10 (data pin) to: x10(int strLength) .jpg to: Restore . 2007. Serial. X10 myHouse = X10(9. Since there will be more functions added.version()). printing the version is a useful debugging tool when you get an error from a given function. Serial. // prints the version of the library Restore June 20.g. // prints the version of the library Deleted lines 56-61: version(void) . at 10:23 AM by Tom Igoe Changed lines 19-22 from: X10(int strLength) . 10).Show changes to markup June 20. e. Perhaps you're using an earlier version that doesn't feature the version you need! e.println(myHouse.get the library version.g. Since there will be more functions added. x10 myHouse = x10(9. 2007.g.println(myHouse. printing the version is a useful debugging tool when you get an error from a given function.initialize an instance of the X10 library on two digital pins. at 10:21 AM by Tom Igoe Changed lines 9-10 from: Attach: X10-schematic. 10).X10 History Hide minor edits . Perhaps you're using an earlier version that doesn't feature the version you need! e.get the library version.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. // initializes X10 on pins 9 (zero crossing pin) and 10 (data pin) Restore June 20.

2007.smarthome.2. e. Download: X10. at 10:18 AM by Tom Igoe Changed lines 3-4 from: This library enables you to send and receive X10 commands from an Arduino module. and the TW523 two-way X10 controller. called TextString. at 10:19 AM by Tom Igoe Changed lines 49-50 from: For a full explanation of X10 and these codes.jpg Restore June 20. As of version 0. When you restart. 2007. get a phone cable with an RJ-11 connector.initialize an instance of the X10 library on two digital pins. see this technote Restore June 20. to: This library enables you to send and receive X10 commands from an Arduino module.png to: Attach: X10-schematic. This library has been tested using the PL513 one-way X10 controller. It's used in home automation.zip To use. see to: For a full explanation of X10 and these codes. at 10:21 AM by Tom Igoe Changed lines 49-50 from: For a full explanation of X10 and these codes. sending a bit every time the AC power crosses zero volts. here's what you can do: X10(int strLength) . you'll see a few warning messages in the debugger pane at the bottom of the program. You can find X10 controllers and devices at http://www. see this technote Restore June 20.png Changed lines 49-50 from: to: For a full explanation of X10 and these codes. 2007. see this technote to: For a full explanation of X10 and these codes.com.x10. You can ignore them. and cut one end off. 2007. . at 09:59 AM by Tom Igoe Added lines 1-52: X10 Library This library enables you to send and receive X10 commands from an Arduino module. 2007.June 20. at 10:20 AM by Tom Igoe Changed lines 9-10 from: Attach: X10. Then re-start the Arduino application. and more. To connect an Arduino to one of these modules. Then wire the pins as follows: Attach: X10. Both of these are essentially X10 modems.g. converting the 5V output of the Arduino into AC signals on the zero crossing. into the lib/targets/libraries directory of your arduino application folder. http://www.com. X10 is a synchronous serial protocol that travels over AC power lines. unzip it and copy the resulting folder. see Restore June 20.

version()). 1). byte numberCode. int numRepeats) . printing the version is a useful debugging tool when you get an error from a given function.println(myHouse. e. // Turns on all lights in house code A There are a number of constants added to make X10 easier. They are as follows: A through F: house code values.igoe at gmail.X10 myHouse = X10(9.write(A.com Restore Edit Page | Page History | Printable View | All Recent Site Changes . 10). // initializes X10 on pins 9 (zero crossing pin) and 10 (data pin) void write(byte houseCode.get the library version.g. myHouse. Since there will be more functions added. ALL_LIGHTS_ON. UNIT_1 through UNIT_16: unit code values ALL_UNITS_OFF ALL_LIGHTS_ON ON OFF DIM BRIGHT ALL_LIGHTS_OFF EXTENDED_CODE HAIL_REQUEST HAIL_ACKNOWLEDGE PRE_SET_DIM EXTENDED_DATA STATUS_ON STATUS_OFF STATUS_REQUEST version(void) .Send an X10 message. Serial. please contact me at tom. // prints the version of the library If anyone's interested in helping to develop this library further. Perhaps you're using an earlier version that doesn't feature the version you need! e.g.

converting the 5V output of the Arduino into AC signals on the zero crossing.zip To use. This library has been tested using the PL513 one-way X10 controller. You can find X10 controllers and devices at http://www.x10.Send an X10 message. Then re-start the Arduino application.g. They are as follows: . ALL_LIGHTS_ON. printing the version is a useful debugging tool when you get an error from a given function. sending a bit every time the AC power crosses zero volts.get the library version. into the lib/targets/libraries directory of your arduino application folder.println(myHouse. As of version 0. e. 1). and more.version()).Arduino : Tutorial / X 10 Learning Examples | Foundations | Hacking | Links X10 Library This library enables you to send and receive X10 commands from an Arduino module. x10 myHouse = x10(9. called TextString. Serial.g.com. int numRepeats) .smarthome. get a phone cable with an RJ-11 connector. // prints the version of the library There are a number of constants added to make X10 easier. To connect an Arduino to one of these modules. e. Both of these are essentially X10 modems. unzip it and copy the resulting folder. // Turns on all lights in house code A version(void) .write(A. myHouse.com. you'll see a few warning messages in the debugger pane at the bottom of the program. and cut one end off. 10). Perhaps you're using an earlier version that doesn't feature the version you need! e.initialize an instance of the X10 library on two digital pins. You can ignore them. Then wire the pins as follows: Download: X10. http://www. When you restart. It's used in home automation. // initializes X10 on pins 9 (zero crossing pin) and 10 (data pin) void write(byte houseCode.2. byte numberCode. and the TW523 two-way X10 controller. X10 is a synchronous serial protocol that travels over AC power lines. Since there will be more functions added. here's what you can do: x10(int strLength) .g.

igoe at gmail. UNIT_1 through UNIT_16: unit code values ALL_UNITS_OFF ALL_LIGHTS_ON ON OFF DIM BRIGHT ALL_LIGHTS_OFF EXTENDED_CODE HAIL_REQUEST HAIL_ACKNOWLEDGE PRE_SET_DIM EXTENDED_DATA STATUS_ON STATUS_OFF STATUS_REQUEST For a full explanation of X10 and these codes. please contact me at tom. see this technote If anyone's interested in helping to develop this library further.arduino.com (Printable View of http://www.cc/en/Tutorial/X10) .A through F: house code values.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Code #include <EEPROM. Mellis Changed lines 29-31 from: Example: EEPROM Read Example: EEPROM Write Reference: EEPROM library to: EEPROM Read example EEPROM Write example EEPROM library reference Restore May 21.EEPROMClear History Hide minor edits . Mellis Added lines 1-25: Examples > EEPROM Library EEPROM Clear Sets all of the bytes of the EEPROM to 0. } void loop() { .Show changes to markup May 21.h> void setup() { // write a 0 to all 512 bytes of the EEPROM for (int i = 0.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 0). i++) EEPROM. // turn the LED on when we're done digitalWrite(13. Mellis Changed lines 25-31 from: @] to: @] See also Example: EEPROM Read Example: EEPROM Write Reference: EEPROM library Restore May 21. 2008. at 09:32 PM by David A. 2008. HIGH). at 09:32 PM by David A. 2008. i < 512. at 09:27 PM by David A.write(i.

} Restore Edit Page | Page History | Printable View | All Recent Site Changes .

0). // turn the LED on when we're done digitalWrite(13.cc/en/Tutorial/EEPROMClear) .write(i. i++) EEPROM. Code #include <EEPROM. } void loop() { } See also EEPROM Read example EEPROM Write example EEPROM library reference (Printable View of http://www.Arduino : Tutorial / EEPROM Clear Learning Examples | Foundations | Hacking | Links Examples > EEPROM Library EEPROM Clear Sets all of the bytes of the EEPROM to 0.h> void setup() { // write a 0 to all 512 bytes of the EEPROM for (int i = 0. HIGH).arduino. i < 512.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

so if we're // on address 512. Mellis Added lines 1-41: Examples > EEPROM Library EEPROM Read Reads the value of each byte of the EEPROM and prints it to the computer. Code #include <EEPROM. } void loop() { // read a byte from the current address of the EEPROM value = EEPROM.read(address). void setup() { Serial.print("\t").EEPROMRead History Hide minor edits .h> // start reading from the first byte (address 0) of the EEPROM int address = 0. wrap around to address 0 if (address == 512) .print(value. Serial. byte value. 2008. 2008. at 09:28 PM by David A. DEC).print(address). at 09:33 PM by David A.begin(9600).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. Serial.Show changes to markup May 21. from 0 to 511. Serial.println(). // advance to the next address of the EEPROM address = address + 1. Serial. Mellis Changed lines 41-47 from: @] to: @] See also EEPROM Clear example EEPROM Write example EEPROM library reference Restore May 21. // there are only 512 bytes of EEPROM.

} Restore Edit Page | Page History | Printable View | All Recent Site Changes . delay(500).address = 0.

void setup() { Serial. Serial. Serial. } void loop() { // read a byte from the current address of the EEPROM value = EEPROM.read(address). delay(500). Serial. Code #include <EEPROM. // there are only 512 bytes of EEPROM. from 0 to 511.arduino.print(address).Arduino : Tutorial / EEPROM Read Learning Examples | Foundations | Hacking | Links Examples > EEPROM Library EEPROM Read Reads the value of each byte of the EEPROM and prints it to the computer.cc/en/Tutorial/EEPROMRead) . // advance to the next address of the EEPROM address = address + 1.println(). wrap around to address 0 if (address == 512) address = 0. DEC).h> // start reading from the first byte (address 0) of the EEPROM int address = 0. byte value. } See also EEPROM Clear example EEPROM Write example EEPROM library reference (Printable View of http://www. Serial.print(value.print("\t"). so if we're // on address 512.begin(9600).

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

EEPROMWrite History Hide minor edits . EEPROM. 2008. addr = addr + 1.write(addr. void setup() { } void loop() { // need to divide by 4 because analog inputs range from // 0 to 1023 and each byte of the EEPROM can only hold a // value from 0 to 255. Mellis Changed lines 40-46 from: @] to: @] See also EEPROM Clear example EEPROM Read example EEPROM library reference Restore May 21. 2008. at 09:30 PM by David A. val).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.e. Code #include <EEPROM.h> // the current address in the EEPROM (i. there are 512 bytes in // the EEPROM.Show changes to markup May 21. // these values will remain there when the board is // turned off. at 09:33 PM by David A. if (addr == 512) . // write the value to the appropriate byte of the EEPROM. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch. int val = analogRead(0) / 4. so go back to 0 when we hit 512. Mellis Added lines 1-40: Examples > EEPROM Library EEPROM Write Stores values read from analog input 0 into the EEPROM. // advance to the next address. which byte // we're going to write to next) int addr = 0.

delay(100).addr = 0. } Restore Edit Page | Page History | Printable View | All Recent Site Changes .

there are 512 bytes in // the EEPROM. // advance to the next address. // these values will remain there when the board is // turned off. if (addr == 512) addr = 0. so go back to 0 when we hit 512. int val = analogRead(0) / 4.h> // the current address in the EEPROM (i.e. val). // write the value to the appropriate byte of the EEPROM. void setup() { } void loop() { // need to divide by 4 because analog inputs range from // 0 to 1023 and each byte of the EEPROM can only hold a // value from 0 to 255. Code #include <EEPROM.arduino. delay(100). These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch. EEPROM.write(addr. addr = addr + 1.cc/en/Tutorial/EEPROMWrite) .Arduino : Tutorial / EEPROM Write Learning Examples | Foundations | Hacking | Links Examples > EEPROM Library EEPROM Write Stores values read from analog input 0 into the EEPROM. which byte // we're going to write to next) int addr = 0. } See also EEPROM Clear example EEPROM Read example EEPROM library reference (Printable View of http://www.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

2008. The unipolar? or bipolar? stepper is controlled with pins 8. Restore May 21. The unipolar? or bipolar? stepper is controlled with pins 8.MotorKnob History Hide minor edits . Mellis Added lines 1-43: Examples > Stepper Library Motor Knob Description A stepper motor follows the turns of a potentiometer (or other sensor) on analog input 0. 2008. 2008. The unipolar or bipolar stepper is controlled with pins 8. at 09:40 PM by David A. using one of the circuits on the linked pages. Mellis Changed lines 7-8 from: A stepper motor follows the turns of a potentiometer (or other sensor) on analog input 0. and 11.Show changes to markup May 21. to: A stepper motor follows the turns of a potentiometer (or other sensor) on analog input 0. at 09:37 PM by David A. 9. at 09:36 PM by David A. and 11. 10. and 11. at 09:40 PM by David A. 9. using one of the circuits on the linked pages.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 9. 10. Mellis Changed lines 43-47 from: @] to: @] See Also Stepper library reference Restore May 21.h> // change this to the number of steps on your motor #define STEPS 100 . Code #include <Stepper. 2008. Mellis Changed lines 45-46 from: See Also to: See also Restore May 21. 10. using one of the circuits on the linked pages.

// remember the previous value of the sensor previous = val. 10. 9. } Restore Edit Page | Page History | Printable View | All Recent Site Changes .previous). specifying // the number of steps of the motor and the pins it's // attached to Stepper stepper(STEPS. } void loop() { // get the sensor value int val = analogRead(0).setSpeed(30).// create an instance of the stepper class.step(val . // the previous reading from the analog input int previous = 0. void setup() { // set the speed of the motor to 30 RPMs stepper. 8. 11). // move a number of steps equal to the change in the // sensor reading stepper.

9. Code #include <Stepper. 9. // the previous reading from the analog input int previous = 0. // move a number of steps equal to the change in the // sensor reading stepper. 10.arduino. The unipolar or bipolar stepper is controlled with pins 8. void setup() { // set the speed of the motor to 30 RPMs stepper.setSpeed(30).step(val . } See also Stepper library reference (Printable View of http://www.Arduino : Tutorial / Motor Knob Learning Examples | Foundations | Hacking | Links Examples > Stepper Library Motor Knob Description A stepper motor follows the turns of a potentiometer (or other sensor) on analog input 0. 8. using one of the circuits on the linked pages. and 11.h> // change this to the number of steps on your motor #define STEPS 100 // create an instance of the stepper class. 10.previous). } void loop() { // get the sensor value int val = analogRead(0). specifying // the number of steps of the motor and the pins it's // attached to Stepper stepper(STEPS. // remember the previous value of the sensor previous = val.cc/en/Tutorial/MotorKnob) . 11).

Mellis Changed lines 2-3 from: Arduino Examples to: Examples Restore July 02. and the links page for other documentation. Mellis Added lines 43-46: Matrix Library Hello Matrix?: blinks a smiley face on the LED matrix. Mellis Added line 63: Read an ADXL3xx accelerometer Restore May 21. Mellis Deleted lines 42-45: Matrix Library Hello Matrix?: blinks a smiley face on the LED matrix. to: See the foundations page for in-depth description of core concepts of the Arduino hardware and software.Show changes to markup July 02. Restore May 21. at 09:36 PM by David A. at 09:44 PM by David A.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 2008. 2008. Added lines 37-42: . Restore May 21. Mellis Changed lines 4-5 from: See the foundations page for in-depth description of core concepts of the Arduino hardware and software. Restore May 21. 2008.HomePage History Show minor edits . at 09:25 PM by David A. at 09:43 PM by David A. at 03:11 PM by David A. 2008. at 02:07 PM by David A. and the links page for other documentation. at 03:11 PM by David A.adding EEPROM examples. Restore July 02. Mellis . 2008. the hacking page for information on extending and modifying the Arduino hardware and software. Mellis Added lines 43-46: Stepper Library Motor Knob: control a stepper motor with a potentiometer. 2008. 2008.

2008. to: Blink Without Delay: blinking an LED without using the delay() function. at 06:55 PM by David A.EEPROM Library EEPROM Clear: clear the bytes in the EEPROM. Changed lines 2-5 from: Arduino Tutorials Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. Added line 15: BlinkWithoutDelay: blinking an LED without using the delay() function. at 09:22 PM by David A. The code is included in the tutorial. Restore April 29. Changed lines 37-42 from: Timing & Millis Blinking an LED without using the delay() function Stopwatch (:if false:) TimeSinceStart: (:ifend:) to: (:cell width=50%:) Changed lines 41-42 from: These are more complex examples for using particular electronic components or accomplishing specific tasks. The code is included on the page. and the links page for other documentation. see the Arduino Getting Started. For instructions on getting the board and environment up and running. 2008. Deleted lines 43-44: Added lines 49-51: Timing & Millis Stopwatch Deleted lines 75-125: . to: These are more complex examples for using particular electronic components or accomplishing specific tasks.moving the resources to the links page. EEPROM Read: read the EEPROM and send its values to the computer. Mellis Changed line 15 from: BlinkWithoutDelay: blinking an LED without using the delay() function. Mellis . Restore May 21. EEPROM Write: stores values from an analog input to the EEPROM. to: Arduino Examples See the foundations page for in-depth description of core concepts of the Arduino hardware and software.

Flash. at 05:59 PM by Paul Badger Changed line 39 from: to: . communication. 2008. Code Library and Tutorials: Arduino functions for performing specific tasks and other programming tutorials. and Other Resources Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino.(:cell width=50%:) Foundations See the foundations page for explanations of the concepts involved in the Arduino hardware and software. Board Setup and Configuration: Information about the components and usage of Arduino hardware. arduino+processing. procedures and hacking code Lesson 3: Breadboards.. and instructions for using various electronic components with an Arduino board.. Output Input Interaction Storage Communication Interfacing with Software: how to get an Arduino board talking to software running on the computer (e. servos. Lesson 0: Pre-flight check. Processing. and pwm) (piezo sound & sensors. Examples from Tom Igoe Examples from Jeff Gray Restore April 23. By ladyada.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. Example labs from ITP Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class class class class 1 2 3 4 (getting started) (input and sensors) (communication. 2008. this one focusing on physical sensing and making motion. Curricula.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. Interfacing With Hardware: Code. a simple blinking light Lesson 2: Sketches. debouncing and your first contract product design. digital inputs. stand-alone operation) Bionic Arduino: another Arduino class from TodBot. at 10:29 PM by David A. resistors and LEDs. variables. Tutorials Tutorials created by the Arduino community. Electronics Techniques: tutorials on soldering and other electronics resources. and basic RGB color-mixing Lesson 4: The serial library and binary data . PD. pull-up and pull-down resistors. Manuals. using Arduino. Learn electronics using Arduino: an introduction to programming. Mellis Changed line 6 from: (:table width=90% border=0 cellpadding=5 cellspacing=0:) to: (:table width=100% border=0 cellpadding=5 cellspacing=0:) Restore April 22. etc. schematics. circuits.g. Hosted on the publicly-editable playground wiki. input / output. Max/MSP). if/if-else statements.

at 07:20 PM by David A. at 09:24 PM by Paul Badger Changed lines 74-107 from: Memory: The various types of memory available on the Arduino board. 2008. 2008. Mellis . 2008.moving TwoSwitchesOnePin to "other examples" since it's not (yet) in the distribution. 2008. at 09:26 PM by Paul Badger Changed lines 73-75 from: to: Foundations has moved here Restore March 07. at 05:56 PM by Paul Badger Added lines 40-41: TimeSinceStart: Restore April 18. Restore March 07. 2008. Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs. Changed lines 18-19 from: TwoSwitchesOnePin: Read two switches with one I/O pin to: Added line 43: * TwoSwitchesOnePin: Read two switches with one I/O pin Restore April 08. 2008. at 07:41 PM by Paul Badger Changed lines 18-19 from: to: TwoSwitchesOnePin: Read two switches with one I/O pin Restore March 09. . Mellis Changed lines 73-78 from: Foundations has moved here Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. at 08:22 PM by David A. 2008. to: See the foundations page for explanations of the concepts involved in the Arduino hardware and software. at 07:22 AM by Paul Badger Added lines 36-39: Timing & Millis Blinking an LED without using the delay() function Stopwatch Changed line 46 from: Blinking an LED without using the delay() function to: Restore April 08.(:if false:) Changed line 41 from: to: (:ifend:) Restore April 22.

) Serial Communication?: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). Communication?: An overview of the various ways in which an Arduino board can communicate with other devices (serial. see the Arduino guide. see the Arduino Getting Started. Variables: How to define and use variables. For instructions on getting the board and environment up and running. Mellis Changed lines 72-73 from: Tutorials to: Foundations Changed lines 108-109 from: More Tutorials to: Tutorials Restore February 13. SPI. Debugging?: Figuring out what's wrong with your hardware or software and how to fix it.Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. Restore February 13. 2008. Foundations (:if false:) PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. 2008. For instructions on getting the board and environment up and running. Optimization?: What to do when your program runs too slowly. etc. I2C. at 10:06 PM by David A. 2008. Midi. Arrays?: How to store multiple values of the same type. at 09:09 PM by Paul Badger Added lines 80-81: Foundations Restore February 15. Pointers?: Functions?: How to write and call functions. 2008. Interrupts?: Code that interrupts other code under certain conditions. (:ifend:) to: Restore March 07. Mellis - . Numbers?: The various types of numbers available and how to use them. to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. at 10:42 PM by Paul Badger Changed lines 4-5 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. at 06:00 PM by David A.

Variables: How to define and use variables. Restore February 13. at 09:12 PM by David A. Mellis - . at 09:22 PM by David A. SPI. Restore February 13. 2008. (:ifend:) Restore February 13. Mellis Changed lines 86-87 from: Serial Communication?: How to send serial data from an Arduino board to a computer or other device. etc. Restore February 13. Interrupts?: Code that interrupts other code under certain conditions. I2C. 2008. 2008. Pointers?: Functions?: How to write and call functions. at 09:36 PM by David A. at 09:58 PM by David A. 2008. Restore February 13. Mellis Added lines 100-103: Optimization?: What to do when your program runs too slowly. Mellis Added lines 80-81: Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. at 09:41 PM by David A. Mellis Changed lines 80-81 from: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. at 09:38 PM by David A. 2008. at 09:31 PM by David A.Restore February 13. Mellis Added lines 80-81: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. 2008. to: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. 2008. Restore February 13. Arrays?: How to store multiple values of the same type.) Serial Communication?: How to send serial data from an Arduino board to a computer or other device. 2008. Mellis Added lines 80-81: (:if false:) Added lines 84-89: Communication?: An overview of the various ways in which an Arduino board can communicate with other devices (serial. Midi. to: Serial Communication?: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). Debugging?: Figuring out what's wrong with your hardware or software and how to fix it. Restore February 13. Mellis Added lines 90-99: Numbers?: The various types of numbers available and how to use them. at 09:30 PM by David A.

2008. to: Other Examples These are more complex examples for using particular electronic components or accomplishing specific tasks. The code is included in the tutorial. 2007. PD. Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs. The code is included in the tutorial. etc. todbot. Processing.linking to board setup and configuration on the playground. Output Input Interaction Storage Communication Interfacing with Software: how to get an Arduino board talking to software running on the computer (e. Restore December 19. Learn electronics using Arduino: an introduction to programming. Electronics Techniques: tutorials on soldering and other electronics resources.g. Mellis . By . Added lines 76-77: Board Setup and Configuration: Information about the components and usage of Arduino hardware. and Other Resources Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino. communication. Hosted on the publicly-editable playground wiki. Interfacing With Hardware: Code.Added lines 74-81: Memory: The various types of memory available on the Arduino board. ladyada's tutorials. Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. input / output. circuits. Mellis . Code Library and Tutorials: Arduino functions for performing specific tasks and other programming tutorials. Manuals. at 11:31 AM by David A. Max/MSP). etc. More Tutorials Restore January 11. Curricula. at 11:54 PM by David A.adding links to other pages: the tutorial parts of the playground. and instructions for using various electronic components with an Arduino board. Changed lines 36-42 from: (:cell width=50%:) Tutorials These are more complex tutorials for using particular electronic components or accomplishing specific tasks. Flash. Changed lines 71-78 from: Other Arduino Tutorials Tutorials from the Arduino playground Example labs from ITP Spooky Arduino and more from Todbot Examples from Tom Igoe Examples from Jeff Gray to: (:cell width=50%:) Tutorials Tutorials created by the Arduino community. using Arduino.

2007. this one focusing on physical sensing and making motion. Mellis Changed lines 10-11 from: Simple programs that demonstrate the use of the Arduino board. at 11:15 PM by Tom Igoe Changed lines 71-72 from: to: X10 output control devices over AC powerlines using X10 Restore June 15. to open them. arduino+processing. if/if-else statements. click the Open button on the toolbar and look in the examples folder. and basic RGB color-mixing Lesson 4: The serial library and binary data . Lesson 0: Pre-flight check. Examples from Tom Igoe Examples from Jeff Gray Restore December 13. 2007. schematics. filtering noise.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches.. a simple blinking light Lesson 2: Sketches. Restore August 28. Mellis . These are included with the Arduino environment. and pwm) (piezo sound & sensors. (If you're looking for an older example. see processing. click the Open button on the toolbar and look in the examples folder. to open them. 2007. Deleted line 43: Interfacing a Joystick Restore June 11.. debouncing and your first contract product design. (If you're looking for an older example. Mellis .adding link to Processing (for the communication examples) Added lines 27-28: These examples include code that allows the Arduino to talk to Processing sketches running on the computer. digital inputs. .Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics. resistors and LEDs. Restore June 12. to: Simple programs that demonstrate the use of the Arduino board.removing link to obsolete joystick example. These are included with the Arduino environment. These are included with the Arduino environment. procedures and hacking code Lesson 3: Breadboards. click the Open button on the toolbar and look in the examples folder. servos. check the Arduino 0007 tutorials page. at 05:04 PM by David A. Added line 16: Debounce: read a pushbutton. check the Arduino 0007 tutorials page. variables.adding debounce example. Mellis Changed lines 10-11 from: Simple programs that demonstrate the use of the Arduino board.org. Example labs from ITP Spooky Arduino: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: class class class class 1 2 3 4 (getting started) (input and sensors) (communication. at 11:08 PM by David A. 2007. 2007. at 08:57 AM by David A. at 11:14 PM by David A. pull-up and pull-down resistors.) Restore June 11. 2007. For more information or to download Processing. at 11:13 PM by David A. to open them. stand-alone operation) Bionic Arduino: another Arduino class from TodBot. Mellis .ladyada.

These are included with the Arduino environment. Dimmer: move the mouse to change the brightness of an LED. check the Arduino 0007 tutorials page. Restore June 11. to open them. to open them. Virtual Color Mixer: sending multiple variables from Arduino to the computer and reading them in Processing. click the Open button on the toolbar and look in the examples folder. Physical Pixel: turning on and off an LED by sending data from Processing. at 11:10 PM by David A. Loop: controlling multiple LEDs with a loop and an array. Miscellaneous Deleted lines 42-51: Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) More complex dimming/color crossfader Knight Rider example Shooting star PWM all of the digital pins in a sinewave pattern Digital Input Digital Input and Output (from ITP physcomp labs) Read a Pushbutton Using a pushbutton as a switch Deleted lines 43-45: Analog Input Read a Potentiometer . 2007. Communication ASCII Table: demonstrates Arduino's advanced serial output functions. These are included with the Arduino environment. The code is included in the tutorial. Smoothing: smooth multiple readings of an analog input. Graph: sending data to the computer and graphing it in Processing. click the Open button on the toolbar and look in the examples folder.updating to 0008 examples Changed lines 10-11 from: Digital Output Blinking LED to: Simple programs that demonstrate the use of the Arduino board. Fading: uses an analog output (PWM pin) to fade an LED. Digital I/O Blink: turn an LED on and off. Mellis . (If you're looking for an older example. (:cell width=50%:) Tutorials These are more complex tutorials for using particular electronic components or accomplishing specific tasks. Analog I/O Analog Input: use a potentiometer to control the blinking of an LED. Button: use a pushbutton to control an LED. Knock: detect knocks with a piezo element.to: Simple programs that demonstrate the use of the Arduino board.

2007. at 06:06 AM by Paul Badger Changed lines 17-18 from: to: .Deleted lines 45-46: Read a Piezo Sensor 3 LED cross-fades with a potentiometer Changed lines 52-53 from: Use two Arduino pins as a capacitive sensor to: Deleted line 54: More sound ideas Added line 64: Build your own DMX Master device Changed lines 70-72 from: Multiple digital inputs with a CD4021 Shift Register Other Arduino Examples to: Other Arduino Tutorials Tutorials from the Arduino playground Added line 75: Spooky Arduino and more from Todbot Deleted lines 78-105: (:cell width=50%:) Interfacing with Other Software Introduction to Serial Communication (from ITP physcomp labs) Arduino + Flash Arduino + Processing Arduino + PD Arduino + MaxMSP Arduino + VVVV Arduino + Director Arduino + Ruby Arduino + C Tech Notes (from the forums or playground) Software serial (serial on pins besides 0 and 1) L297 motor driver Hex inverter Analog multiplexer Power supplies The components on the Arduino board Arduino build process AVRISP mkII on the Mac Non-volatile memory (EEPROM) Bluetooth Zigbee LED as light sensor (en Francais) Arduino and the Asuro robot Using Arduino from the command line Restore May 11.

2007. at 02:51 PM by Carlyn Maw Changed lines 52-53 from: to: Multiple digital ins with a CD4021 Shift Register Restore January 30. 2007.pl?num=1171076259 |Use a couple of Arduino pins as a capacitive sensor]] to: Use two Arduino pins as a capacitive sensor Restore May 10.cc/cgi-bin/yabb2/YaBB. Mellis Deleted line 46: . at 03:40 PM by Clay Shirky Changed lines 13-14 from: Dimming 3 LEDs with Pulse-Width Modulation (PWM) to: Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) More complex dimming/color crossfader Restore February 08. at 07:04 PM by Paul Badger Changed lines 36-37 from: to: http://www. 2007.arduino. at 07:05 PM by Paul Badger Changed lines 36-37 from: http://www.cc/cgi-bin/yabb2/YaBB.pl?num=1171076259 |Use a couple of Arduino pins as a capacitive sensor]] Restore May 10.cc/cgi-bin/yabb2/YaBB. at 02:52 PM by Carlyn Maw Changed lines 52-54 from: Multiple digital ins with a CD4021 Shift Register to: Restore February 06. at 03:37 PM by David A. 2007. at 12:02 PM by Carlyn Maw Changed lines 52-53 from: to: Multiple digital inputs with a CD4021 Shift Register Restore February 06. 2007. 2007.arduino.PWM all of the digital pins in a sinewave pattern Restore May 10.cc/cgi-bin/yabb2/YaBB. at 07:07 PM by Paul Badger Changed lines 36-37 from: http://www.pl?num=1171076259 Use a couple of Arduino pins as a capacitive sensor to: http://www. at 06:59 PM by Paul Badger Added line 39: More sound ideas Restore April 24.pl?num=1171076259 Use a couple of Arduino pins as a capacitive sensor Restore May 10. 2007. 2007.arduino.arduino. 2007.

Build your own DMX Master device Restore December 25.adding link to todbot's C serial port code. at 03:10 PM by Carlyn Maw Changed lines 50-51 from: to: Multiple digital outs with a 595 Shift Register Restore November 06. 2006. Mellis Added line 64: Arduino + MaxMSP Changed lines 67-68 from: to: Arduino + Ruby Restore November 18. 2006. at 12:24 PM by David A. Changed lines 69-70 from: to: Arduino + C Restore December 02. at 11:57 PM by David A. at 06:04 AM by David A. Mellis Deleted line 53: Deleted line 54: Restore November 04. at 02:42 AM by David A. at 10:43 AM by David A. at 10:13 AM by David A. 2006. 2006. Mellis Added lines 51-58: Other Arduino Examples Example labs from ITP . 2006. at 10:49 AM by David A. Mellis Changed lines 20-21 from: Controlling an LED circle with a joystick to: Added line 24: Controlling an LED circle with a joystick Restore November 09. Mellis Added line 20: Using a pushbutton as a switch Restore December 07. Mellis Added line 1: (:title Tutorials:) Restore November 21. 2006. 2006. Mellis Changed lines 37-38 from: MIDI Output (from ITP physcomp labs) to: MIDI Output (from ITP physcomp labs) and from Spooky Arduino Restore November 04. 2006. 2006. Mellis . at 12:25 PM by David A.

Restore November 04. Deleted lines 52-67: The Arduino board This guide to the Arduino board explains the functions of the various parts of the board. at 12:24 PM by David A. The Arduino environment . For instructions on getting the board and environment up and running. Restore November 04. at 12:23 PM by David A. at 10:38 AM by David A. Mellis . Mellis Changed line 77 from: Other Arduino Sites to: Other Arduino Examples Deleted lines 79-81: Do you need extra help? Is there a sensor you would like to see characterized for Arduino. Examples from Jeff Gray. Mellis Changed lines 3-4 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. 2006. or is there something you would like to see published in this site? Refer to the forum for further help. see the Arduino guide. Restore November 04. 2006. to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. to: Example labs from ITP Examples from Tom Igoe. 2006. Restore November 04.lots of content moved to the new guide. see the examples from Tom Igoe and those from Jeff Gray. see the Arduino guide?. For instructions on getting the board and environment up and running. Mellis Changed lines 50-51 from: Example labs from ITP to: Changed lines 77-78 from: Also. at 10:37 AM by David A. Examples from Jeff Gray.Examples from Tom Igoe Examples from Jeff Gray Deleted lines 83-89: Other Arduino Examples Example labs from ITP Examples from Tom Igoe. 2006.

class 3 (communication. Restore November 01. Thanks to Pollie Barden for the great videos. Video Lectures by Tom Igoe Watch Tom introduce Arduino. 2006. Make magazine has some great links in its electronics archive. and pwm). to: todbot has some very detailed. class 4 (piezo sound & sensors. servos. stand-alone operation) Restore October 22. illustrated tutorials from his Spooky Projects course: class 1 (getting started). arduino+processing. see the Howto. see the Howto. at 12:52 PM by David A. illustrated tutorials from his Spooky Projects course: class 1 (getting started). class 3 (communication. For instructions on getting the board and environment up and running. hack a day has links to interesting hacks and how-to articles on various topics. Kurt Changed lines 67-68 from: todbot has some very detailed. stand-alone operation) Deleted lines 82-87: External Resources Instant Soup is an introduction to electronics through a series of beautifully-documented fun projects. Course Guides todbot has some very detailed. at 06:06 PM by Carlyn Maw Added line 50: Extend your digital outs with 74HC595 shift registers Restore October 31. 2006.This guide to the Arduino IDE (integrated development environment) explains the functions of the various buttons and menus. class 2 (input and sensors). For instructions on getting the board and environment up and running. . For instructions on getting the board and IDE up and running. 2006. class 3 (communication. servos. at 10:17 AM by David A. Mellis Changed lines 3-4 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. class 2 (input and sensors). Restore November 04. servos. arduino+processing. to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. 2006. class 2 (input and sensors). The libraries page explains how to use libraries in your sketches and how to make your own. illustrated tutorials from his Spooky Projects course: class 1 (getting started). at 06:54 PM by Carlyn Maw Deleted line 49: Extend your digital outs with 74HC595 shift registers Restore November 01. and pwm). Mellis Changed lines 1-4 from: Learning to use Arduino Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. 2006. see the Arduino guide?. at 10:47 AM by Tod E. and pwm). class 4 (piezo sound & sensors.

illustrated tutorials from his Spooky Projects course: class 1 (getting started). Mellis Changed lines 59-62 from: This guide to the Arduino IDE? (integrated development environment) explains the functions of the various buttons and menus. Mellis Changed lines 3-4 from: Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. Mellis . see the Howto. Restore October 08. Restore October 22. Restore October 21. Mellis Added lines 1-102: Learning to use Arduino Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. servos. (:table width=90% border=0 cellpadding=5 cellspacing=0:) (:cell width=50%:) Examples Digital Output Blinking LED . see the Howto. at 05:38 PM by David A. The libraries? page explains how to use libraries in your sketches and how to make your own. at 04:25 PM by David A. at 05:46 PM by David A. For instructions on getting the board and IDE up and running. at 12:51 PM by David A. see the Howto?. to: Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. 2006.adding links to todbot's class notes. Restore October 08. class 2 (input and sensors). class 3 (communication. and pwm). Mellis Changed lines 67-68 from: todbot has some very detailed. at 05:45 PM by David A. For instructions on getting the board and environment up and running. to: todbot has some very detailed. 2006. For instructions on getting the board and IDE up and running. to: This guide to the Arduino IDE (integrated development environment) explains the functions of the various buttons and menus. class 2 (input and sensors). Added lines 66-68: Course Guides todbot has some very detailed. For instructions on getting the board and IDE up and running. illustrated tutorials from his Spooky Projects course: class 1 (getting started). The libraries page explains how to use libraries in your sketches and how to make your own. see the Howto?.to: Arduino Tutorials Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. illustrated tutorials from his Spooky Projects course: class 1 (getting started). class 2 (input and sensors). 2006. 2006. Restore October 08. 2006.

Blinking an LED without using the delay() function Dimming 3 LEDs with Pulse-Width Modulation (PWM) Knight Rider example Shooting star Digital Input Digital Input and Output (from ITP physcomp labs) Read a Pushbutton Read a Tilt Sensor Controlling an LED circle with a joystick Analog Input Read a Potentiometer Interfacing a Joystick Read a Piezo Sensor 3 LED cross-fades with a potentiometer 3 LED color mixer with 3 potentiometers Complex Sensors Read an Accelerometer Read an Ultrasonic Range Finder (ultrasound sensor) Reading the qprox qt401 linear touch sensor Sound Play Melodies with a Piezo Speaker Play Tones from the Serial Connection MIDI Output (from ITP physcomp labs) Interfacing w/ Hardware Multiply the Amount of Outputs with an LED Driver Interfacing an LCD display with 8 bits LCD interface library Driving a DC Motor with an L293 (from ITP physcomp labs). Interfacing with Other Software Introduction to Serial Communication (from ITP physcomp labs) Arduino + Flash Arduino + Processing . The Arduino environment This guide to the Arduino IDE? (integrated development environment) explains the functions of the various buttons and menus. The libraries? page explains how to use libraries in your sketches and how to make your own. Driving a Unipolar Stepper Motor Build your own DMX Master device Implement a software serial connection RS-232 computer interface Interface with a serial EEPROM using SPI Control a digital potentiometer using SPI Example labs from ITP (:cell width=50%:) The Arduino board This guide to the Arduino board explains the functions of the various parts of the board. Thanks to Pollie Barden for the great videos. Video Lectures by Tom Igoe Watch Tom introduce Arduino.

or is there something you would like to see published in this site? Refer to the forum for further help. External Resources Instant Soup is an introduction to electronics through a series of beautifully-documented fun projects.Arduino + PD Arduino + VVVV Arduino + Director Tech Notes (from the forums or playground) Software serial (serial on pins besides 0 and 1) L297 motor driver Hex inverter Analog multiplexer Power supplies The components on the Arduino board Arduino build process AVRISP mkII on the Mac Non-volatile memory (EEPROM) Bluetooth Zigbee LED as light sensor (en Francais) Arduino and the Asuro robot Using Arduino from the command line Other Arduino Sites Also. see the examples from Tom Igoe and those from Jeff Gray. (:tableend:) Restore Edit Page | Page History | Printable View | All Recent Site Changes . Make magazine has some great links in its electronics archive. hack a day has links to interesting hacks and how-to articles on various topics. Do you need extra help? Is there a sensor you would like to see characterized for Arduino.

2008. Restore May 21. and the '''[[Tutorial/Links | links page]]''' for other documentation. at 09:22 PM by David A. Restore May 21. Added lines 37-42: !!!! EEPROM Library * [[EEPROMClear | EEPROM Clear]]: clear the bytes in the EEPROM.'' to: ''See the '''[[Tutorial/Foundations | foundations page]]''' for in-depth description of core concepts of the Arduino hardware and software.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. at 09:44 PM by David A. 2008. 2008. Mellis Added lines 43-46: !!!! Matrix Library * [[HelloMatrix | Hello Matrix]]: blinks a smiley face on the LED matrix.Show changes to output July 02. * [[EEPROMWrite | EEPROM Write]]: stores values from an analog input to the EEPROM. 2008. Mellis Changed line 15 from: * [[BlinkWithoutDelay | BlinkWithoutDelay]]: blinking an LED without using the delay() function. and the '''[[Tutorial/Links | links page]]''' for other documentation. Restore May 21. at 09:25 PM by David A. at 03:11 PM by David A. at 09:36 PM by David A. 2008. Mellis Added lines 43-46: !!!! Stepper Library * [[MotorKnob | Motor Knob]]: control a stepper motor with a potentiometer. . * [[EEPROMRead | EEPROM Read]]: read the EEPROM and send its values to the computer. at 03:11 PM by David A. Mellis Changed lines 4-5 from: ''See the '''[[Tutorial/Foundations | foundations page]]''' for in-depth description of core concepts of the Arduino hardware and software. Mellis Changed lines 2-3 from: !!Arduino Examples to: !!Examples Restore July 02. 2008. the '''[[Hacking/HomePage | hacking page]]''' for information on extending and modifying the Arduino hardware and software. at 02:07 PM by David A. Mellis Deleted lines 42-45: !!!! Matrix Library * [[HelloMatrix | Hello Matrix]]: blinks a smiley face on the LED matrix. to: * [[BlinkWithoutDelay | Blink Without Delay]]: blinking an LED without using the delay() function. 2008. at 09:43 PM by David A. Mellis .adding EEPROM examples. 2008. Restore May 21. Mellis Added line 63: * [[ Tutorial/ADXL3xx | Read an ADXL3xx accelerometer]] Restore May 21.HomePage History Hide minor edits .'' Restore July 02.

2008.arduino. The code is included in the tutorial. !!!Tutorials Tutorials created by the Arduino community. Deleted lines 43-44: Added lines 49-51: !!!Timing & Millis * [[ Tutorial/stopwatch | Stopwatch ]] Deleted lines 75-125: (:cell width=50%:) !!!Foundations See the [[Foundations| foundations page]] for explanations of the concepts involved in the Arduino hardware and software. Hosted on the publicly-editable [[http://www.cc/playground/Main/InterfacingWithHardware | Interfacing With Hardware]]: Code. and the '''[[Tutorial/Links | links page]]''' for other documentation. For instructions on getting the board and environment up and running.arduino.cc/playground/Main/InterfacingWithHardware#Output | Output]] * [[http://www. to: These are more complex examples for using particular electronic components or accomplishing specific tasks. .cc/playground/Main/GeneralCodeLibrary | Code Library and Tutorials]]: Arduino functions for performing specific tasks and other programming tutorials.moving the resources to the links page.cc/playground/Main/ArduinoCoreHardware | Board Setup and Configuration]]: Information about the components and usage of Arduino hardware.cc/playground/ | playground wiki]].cc/playground/Main/InterfacingWithHardware#Communication | Communication]] [[http://www. see the Arduino [[Guide/HomePage | Getting Started]]. [[http://www.arduino.arduino.arduino. Changed lines 37-42 from: !!!Timing & Millis * [[ Tutorial/BlinkWithoutDelay | Blinking an LED without using the delay() function]] * [[ Tutorial/stopwatch | Stopwatch ]] (:if false:) * [[TimeSinceStart]]: (:ifend:) to: (:cell width=50%:) Changed lines 41-42 from: These are more complex examples for using particular electronic components or accomplishing specific tasks.cc/playground/Main/InterfacingWithSoftware | Interfacing with Software]]: how to get an Arduino board talking to software running on the computer (e.arduino.g.cc/playground/Main/InterfacingWithHardware#Input | Input]] * [[http://www.arduino. [[http://www. The code is included on the page. Flash. [[http://www.Restore April 29. Processing.arduino. at 06:55 PM by David A. PD.arduino. [[http://www. * [[http://www. Mellis . to: !!Arduino Examples ''See the '''[[Tutorial/Foundations | foundations page]]''' for in-depth description of core concepts of the Arduino hardware and software.cc/playground/Main/InterfacingWithHardware#Interaction | Interaction]] * [[http://www. circuits. Changed lines 2-5 from: !!Arduino Tutorials Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino.arduino.cc/playground/Main/InterfacingWithHardware#Storage | Storage]] * [[http://www.cc/playground/Main/ElectroInfoResources | Electronics Techniques]]: tutorials on soldering and other electronics resources.'' Added line 15: * [[BlinkWithoutDelay | BlinkWithoutDelay]]: blinking an LED without using the delay() function. and instructions for using various electronic components with an Arduino board. Max/MSP).arduino.

schematics. stand-alone operation)]] [[http://todbot. * [[http://www.tigoe.shtml | Examples from Tom Igoe]] [[http://www.net/ | ladyada]]. using Arduino.pdf | class 3 (communication.net/pcomp/code/archives/avr/arduino/index.it/en/uploads/v3_arduino_small.net/learn/arduino/lesson0.html | Lesson 1]]: The &quot.net/learn/arduino/lesson4. and Other Resources [[http://www.pdf | class 1 (getting started)]] * [[http://todbot. [[http://www.html | Learn electronics using Arduino]]: an introduction to programming.Is your Arduino and computer ready? * [[http://www. By [[http://www. at 07:22 AM by Paul Badger Added lines 36-39: !!!Timing & Millis * [[ Tutorial/BlinkWithoutDelay | Blinking an LED without using the delay() function]] * [[ Tutorial/stopwatch | Stopwatch ]] Changed line 46 from: * [[ Tutorial/BlinkWithoutDelay | Blinking an LED without using the delay() function]] to: . servos.com/blog/?p=15 | Examples from Jeff Gray]] Restore April 23.net/learn/arduino/index. a simple blinking light * [[http://www. at 05:56 PM by Paul Badger Added lines 40-41: * [[TimeSinceStart]]: Restore April 18. etc.tinker.ladyada. switches.html | Lesson 0]]: Pre-flight check.net/learn/arduino/lesson5.pdf | class 2 (input and sensors)]] * [[http://todbot. this one focusing on physical sensing and making motion. and pwm)]] * [[http://todbot..html | Lesson 5]]: Buttons &amp. and basic RGB color-mixing * [[http://www.html | Lesson 3]]: Breadboards.pdf | Arduino Booklet (pdf)]]: an illustrated guide to the philosophy and practice of Arduino.html | Lesson 4]]: The serial library and binary data .com/blog/bionicarduino/ | Bionic Arduino]]: another Arduino class from TodBot.edu/physcomp/Labs/Labs | Example labs from ITP]] [[http://todbot.ladyada. [[ http://itp. pull-up and pulldown resistors.ladyada.nyu. [[http://www.ladyada. at 05:59 PM by Paul Badger Changed line 39 from: to: (:if false:) Changed line 41 from: to: (:ifend:) Restore April 22.net/learn/arduino/lesson2.net/learn/arduino/lesson1.net/learn/arduino/lesson3. input / output. 2008. debouncing and your first contract product design.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class3. 2008.ladyada.html | Lesson 2]]: Sketches.ladyada. of electronics. 2008.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class2..com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class1.ladyada. arduino+processing. if/if-else statements. communication. at 10:29 PM by David A. procedures and hacking code * [[http://www.Hello World!&quot.getting chatty with Arduino and crunching numbers * [[http://www.ladyada.com/blog/spookyarduino/ | Spooky Arduino]]: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: * [[http://todbot.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class4. resistors and LEDs. 2008.!!!Manuals.grayfuse.pdf | class 4 (piezo sound & sensors. Curricula. Mellis Changed line 6 from: (:table width=90% border=0 cellpadding=5 cellspacing=0:) to: (:table width=100% border=0 cellpadding=5 cellspacing=0:) Restore April 22. digital inputs. variables.

Restore March 07. etc. at 08:22 PM by David A.Restore April 08. 2008. to: See the [[Foundations| foundations page]] for explanations of the concepts involved in the Arduino hardware and software. . 2008. * [[Communication]]: An overview of the various ways in which an Arduino board can communicate with other devices (serial. * [[Digital Pins]]: How the pins work and what it means for them to be configured as inputs or outputs. at 09:26 PM by Paul Badger Changed lines 73-75 from: to: * [[Foundations| Foundations has moved here]] Restore March 07.) * [[Serial | Serial Communication]]: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). Midi. 2008.moving TwoSwitchesOnePin to "other examples" since it's not (yet) in the distribution. * [[Interrupts]]: Code that interrupts other code under certain conditions. Changed lines 18-19 from: * [[TwoSwitchesOnePin]]: Read two switches with one I/O pin to: Added line 43: * * [[TwoSwitchesOnePin]]: Read two switches with one I/O pin Restore April 08. * [[Analog Input Pins]]: Details about the analog-to-digital conversion and other uses of the pins. Mellis . 2008. at 09:24 PM by Paul Badger Changed lines 74-107 from: * [[Memory]]: The various types of memory available on the Arduino board. 2008. * [[Numbers]]: The various types of numbers available and how to use them. at 08:23 PM by David A. at 07:41 PM by Paul Badger Changed lines 18-19 from: to: * [[TwoSwitchesOnePin]]: Read two switches with one I/O pin Restore March 09. * [[Foundations]] (:if false:) * [[PWM | PWM (Pulse-Width Modulation)]]: The method used by analogWrite() to simulate an analog output with digital pins. at 07:20 PM by David A. I2C. Mellis Changed lines 73-78 from: * [[Foundations| Foundations has moved here]] * [[Bootloader]]: A small program pre-loaded on the Arduino board to allow uploading sketches. 2008. SPI. Mellis Changed line 43 from: * * [[TwoSwitchesOnePin]]: Read two switches with one I/O pin to: * [[TwoSwitchesOnePin]]: Read two switches with one I/O pin Restore April 08.

Mellis Added lines 90-99: * [[Numbers]]: The various types of numbers available and how to use them. * [[Arrays]]: How to store multiple values of the same type. * [[Arrays]]: How to store multiple values of the same type. Mellis Added lines 100-103: * [[Optimization]]: What to do when your program runs too slowly. see the Arduino [[Guide/HomePage | guide]]. * [[Pointers]]: * [[Functions]]: How to write and call functions. 2008. * [[Optimization]]: What to do when your program runs too slowly. 2008. at 09:41 PM by David A. to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. * [[Debugging]]: Figuring out what's wrong with your hardware or software and how to fix it. at 10:06 PM by David A.* [[Variables]]: How to define and use variables. Restore February 13. * [[Debugging]]: Figuring out what's wrong with your hardware or software and how to fix it. at 09:58 PM by David A. Mellis Restore February 13. Restore February 13. to: . * [[Pointers]]: * [[Functions]]: How to write and call functions. at 09:09 PM by Paul Badger Added lines 80-81: * [[Foundations]] Restore February 15. Restore February 13. at 09:38 PM by David A. 2008. see the Arduino [[Guide/HomePage | Getting Started]]. (:ifend:) to: Restore March 07. For instructions on getting the board and environment up and running. 2008. at 06:00 PM by David A. 2008. * [[Variables]]: How to define and use variables. Mellis Changed lines 72-73 from: !!!Tutorials to: !!!Foundations Changed lines 108-109 from: !!!More Tutorials to: !!!Tutorials Restore February 13. For instructions on getting the board and environment up and running. at 10:42 PM by Paul Badger Changed lines 4-5 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. Mellis Changed lines 86-87 from: * [[Serial | Serial Communication]]: How to send serial data from an Arduino board to a computer or other device. 2008. 2008.

cc/playground/Learning/Tutorials | Tutorials from the Arduino playground]] . 2008. at 11:54 PM by David A. 2008. Restore December 19. Restore February 13. !!!More Tutorials Restore January 11.cc/playground/Main/ArduinoCoreHardware | Board Setup and Configuration]]: Information about the components and usage of Arduino hardware. Restore February 13. The code is included in the tutorial. I2C. at 09:31 PM by David A. at 09:22 PM by David A.arduino.* [[Serial | Serial Communication]]: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). ladyada's tutorials. Mellis Added lines 80-81: * [[Bootloader]]: A small program pre-loaded on the Arduino board to allow uploading sketches. Changed lines 71-78 from: !!!!Other Arduino Tutorials * [[http://www. etc.arduino. * [[Interrupts]]: Code that interrupts other code under certain conditions.linking to board setup and configuration on the playground. 2008. Mellis Added lines 74-81: * [[Memory]]: The various types of memory available on the Arduino board. SPI.) * [[Serial | Serial Communication]]: How to send serial data from an Arduino board to a computer or other device. Mellis Changed lines 80-81 from: * [[PWM]] (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. * [[Analog Input Pins]]: Details about the analog-to-digital conversion and other uses of the pins. 2008. Restore February 13. 2007. 2008. etc. Midi. at 09:36 PM by David A. * [[Digital Pins]]: How the pins work and what it means for them to be configured as inputs or outputs. Mellis . The code is included in the tutorial. (:ifend:) Restore February 13. todbot. at 09:30 PM by David A. Restore February 13. at 09:12 PM by David A. at 11:31 AM by David A. to: * [[PWM | PWM (Pulse-Width Modulation)]]: The method used by analogWrite() to simulate an analog output with digital pins. Mellis Added lines 80-81: * [[PWM]] (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. Mellis Added lines 80-81: (:if false:) Added lines 84-89: * [[Communication]]: An overview of the various ways in which an Arduino board can communicate with other devices (serial. Mellis . Changed lines 36-42 from: (:cell width=50%:) !!!Tutorials These are more complex tutorials for using particular electronic components or accomplishing specific tasks. 2008.adding links to other pages: the tutorial parts of the playground. to: !!!Other Examples These are more complex examples for using particular electronic components or accomplishing specific tasks. Added lines 76-77: [[http://www.

arduino.com/blog/?p=15 | Examples from Jeff Gray]] to: (:cell width=50%:) !!!Tutorials Tutorials created by the Arduino community.arduino. PD. and Other Resources [[http://www. circuits.arduino. !!!Manuals.arduino. etc.ladyada. [[ http://itp. switches. communication.shtml | Examples from Tom Igoe]] * [[http://www. arduino+processing. schematics.html | Lesson 3]]: Breadboards.* [[ http://itp.html | Lesson 2]]: Sketches. [[http://www.ladyada.tigoe. and pwm)]] * [[http://todbot. By [[http://www.it/en/uploads/v3_arduino_small.pdf | class 1 (getting started)]] * [[http://todbot.arduino.net/learn/arduino/lesson2.cc/playground/Main/InterfacingWithHardware#Input | Input]] * [[http://www. [[http://www. a simple blinking light * [[http://www. stand-alone operation)]] [[http://todbot.html | Learn electronics using Arduino]]: an introduction to programming.net/learn/arduino/index.cc/playground/Main/ElectroInfoResources | Electronics Techniques]]: tutorials on soldering and other electronics resources.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class1.pdf | class 4 (piezo sound & sensors. * [[http://www. this one focusing on physical sensing and making motion. pull-up and pulldown resistors.com/blog/spookyarduino/ | Spooky Arduino]]: Longer presentation-format documents introducing Arduino from a Halloween hacking class taught by TodBot: * [[http://todbot. servos..net/learn/arduino/lesson5.arduino. input / output.cc/playground/Main/InterfacingWithHardware | Interfacing With Hardware]]: Code.html | Lesson 4]]: The serial library and binary data .edu/physcomp/Labs/Labs | Example labs from ITP]] * [[http://todbot.Hello World!&quot.ladyada.arduino.html | Lesson 5]]: Buttons &amp.ladyada.grayfuse.net/learn/arduino/lesson1. Processing. and instructions for using various electronic components with an Arduino board. Curricula.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class2.ladyada.com/blog/bionicarduino/ | Bionic Arduino]]: another Arduino class from TodBot. [[http://www. of electronics. debouncing and your first contract product design.ladyada.cc/playground/Main/InterfacingWithSoftware | Interfacing with Software]]: how to get an Arduino board talking to software running on the computer (e.com/blog/?p=15 | Examples from Jeff Gray]] . * [[http://www. [[http://www.net/learn/arduino/lesson4. using Arduino.net/pcomp/code/archives/avr/arduino/index.ladyada.cc/playground/Main/InterfacingWithHardware#Output | Output]] * [[http://www.html | Lesson 0]]: Pre-flight check. procedures and hacking code * [[http://www.pdf | class 2 (input and sensors)]] * [[http://todbot.com/blog/category/arduino/ | Spooky Arduino and more from Todbot]] * [[http://www. if/if-else statements.getting chatty with Arduino and crunching numbers * [[http://www.cc/playground/ | playground wiki]].edu/physcomp/Labs/Labs | Example labs from ITP]] [[http://todbot.g. variables. Hosted on the publicly-editable [[http://www.tinker. Flash. and basic RGB color-mixing * [[http://www.nyu.cc/playground/Main/InterfacingWithHardware#Communication | Communication]] [[http://www.arduino.arduino. Max/MSP).pdf | class 3 (communication.arduino.net/pcomp/code/archives/avr/arduino/index.grayfuse.net/learn/arduino/lesson0.nyu.Is your Arduino and computer ready? * [[http://www.tigoe.shtml | Examples from Tom Igoe]] [[http://www.net/learn/arduino/lesson3. resistors and LEDs.cc/playground/Main/InterfacingWithHardware#Interaction | Interaction]] * [[http://www.ladyada.cc/playground/Main/InterfacingWithHardware#Storage | Storage]] * [[http://www.net/ | ladyada]].com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class3.pdf | Arduino Booklet (pdf)]]: an illustrated guide to the philosophy and practice of Arduino. [[http://www. digital inputs.html | Lesson 1]]: The &quot.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class4..cc/playground/Main/GeneralCodeLibrary | Code Library and Tutorials]]: Arduino functions for performing specific tasks and other programming tutorials.

at 11:15 PM by Tom Igoe Changed lines 71-72 from: to: * [[Tutorial/X10 | X10 output]] control devices over AC powerlines using X10 Restore June 15. [[Fading]]: uses an analog output (PWM pin) to fade an LED. 2007. !!!! Digital I/O * [[Blink]]: turn an LED on and off.Restore December 13. Mellis . (If you're looking for an older example. to open them. Restore August 28. [[Smoothing]]: smooth multiple readings of an analog input. These are included with the Arduino environment. * [[Button]]: use a pushbutton to control an LED.org/ | processing. For more information or to download Processing. click the Open button on the toolbar and look in the '''examples''' folder. to: Simple programs that demonstrate the use of the Arduino board. check the [[HomePage-0007 | Arduino 0007 tutorials page]].adding link to Processing (for the communication examples) Added lines 27-28: ''These examples include code that allows the Arduino to talk to Processing sketches running on the computer. These are included with the Arduino environment. at 11:13 PM by David A. Mellis . click the Open button on the toolbar and look in the '''examples''' folder. to open them. 2007. see [[http://processing. 2007. at 05:04 PM by David A.'' Restore June 12. * [[Dimmer]]: move the mouse to change the brightness of an LED. Deleted line 43: * [[ Tutorial/JoyStick | Interfacing a Joystick]] Restore June 11. to open them. Mellis . . (If you're looking for an older example. These are included with the Arduino environment. !!!! Analog I/O * * * * [[Analog Input]]: use a potentiometer to control the blinking of an LED. at 11:10 PM by David A. !!!! Communication * [[ASCII Table]]: demonstrates Arduino's advanced serial output functions. These are included with the Arduino environment. to open them. to open them. Restore June 11. 2007.org]]. 2007. [[Knock]]: detect knocks with a piezo element. click the Open button on the toolbar and look in the '''examples''' folder. These are included with the Arduino environment. 2007. * [[Loop]]: controlling multiple LEDs with a loop and an array. at 11:08 PM by David A.removing link to obsolete joystick example. check the [[HomePage-0007 | Arduino 0007 tutorials page]]. at 11:14 PM by David A. Mellis . (If you're looking for an older example. click the Open button on the toolbar and look in the '''examples''' folder. Added line 16: * [[Debounce]]: read a pushbutton.updating to 0008 examples Changed lines 10-11 from: !!!! Digital Output * [[ Tutorial/Blinking LED | Blinking LED]] to: Simple programs that demonstrate the use of the Arduino board.adding debounce example. click the Open button on the toolbar and look in the '''examples''' folder. to: Simple programs that demonstrate the use of the Arduino board.) Restore June 11. 2007. filtering noise. Mellis Changed lines 10-11 from: Simple programs that demonstrate the use of the Arduino board. check the [[HomePage-0007 | Arduino 0007 tutorials page]]. at 08:57 AM by David A. Mellis Changed lines 10-11 from: Simple programs that demonstrate the use of the Arduino board.

cc/playground/Interfacing/Director | Arduino + Director]] * [[http://www.nyu.arduino.cc/playground/Learning/Tutorials | Tutorials from the Arduino playground]] Added line 75: * [[http://todbot. * [[Physical Pixel]]: turning on and off an LED by sending data from Processing.edu/physcomp/Labs/DigitalInOut | Digital Input and Output]] (from [[http://itp.nyu.com/blog/category/arduino/ | Spooky Arduino and more from Todbot]] Deleted lines 78-105: (:cell width=50%:) !!!Interfacing with Other Software * [[http://itp.arduino.cc/playground/Interfacing/MaxMSP | Arduino + MaxMSP]] * [[http://www.arduino.nyu.arduino. * [[Virtual Color Mixer]]: sending multiple variables from Arduino to the computer and reading them in Processing.arduino.pl?num=1171076259 | Use two Arduino pins as a capacitive sensor]] to: Deleted line 54: * [[http://www.cc/playground/Interfacing/Processing | Arduino + Processing]] * [[http://www.cc/playground/Main/PWMallPins | PWM all of the digital pins in a sinewave pattern]] !!!! Digital Input * [[http://itp. (:cell width=50%:) !!!Tutorials These are more complex tutorials for using particular electronic components or accomplishing specific tasks.edu/physcomp/Labs/Labs | ITP physcomp labs]]) * [[http://www. The code is included in the tutorial.edu/physcomp/Labs/Serial | Introduction to Serial Communication]] (from [[http://itp.arduino.cc/cgi-bin/yabb2/YaBB.arduino.cc/playground/Interfacing/PD | Arduino + PD]] * [[http://www.cc/playground/Interfacing/Flash | Arduino + Flash]] * [[http://www. !!!!Miscellaneous Deleted lines 42-51: * [[ Tutorial/Dimming LEDs | Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) ]] * [[ Tutorial/Color Crossfader | More complex dimming/color crossfader ]] * [[ Tutorial/Knight Rider|Knight Rider example]] * [[ Tutorial/ShootingStar | Shooting star]] * [[ http://www.cc/playground/Main/Freqout|More sound ideas]] Added line 64: * [[ Tutorial/DMX Master | Build your own DMX Master device]] Changed lines 70-72 from: *[[Tutorial/ShiftIn | Multiple digital inputs with a CD4021 Shift Register]] !!!Other Arduino Examples to: !!!!Other Arduino Tutorials * [[http://www.edu/physcomp/Labs/Labs | ITP physcomp labs]]) * [[ Tutorial/Pushbutton | Read a Pushbutton]] * [[ Tutorial/Switch | Using a pushbutton as a switch]] Deleted lines 43-45: !!!! Analog Input * [[ Tutorial/Potentiometer | Read a Potentiometer]] Deleted lines 45-46: * [[ Tutorial/Knock Sensor | Read a Piezo Sensor]] * [[ Tutorial/LED cross-fades with potentiometer | 3 LED cross-fades with a potentiometer ]] Changed lines 52-53 from: *[[http://www.cc/playground/Interfacing/Ruby | Arduino + Ruby]] * [[http://todbot.* [[Graph]]: sending data to the computer and graphing it in Processing.arduino.nyu.arduino.arduino.arduino.cc/playground/Interfacing/VVVV | Arduino + VVVV]] * [[http://www.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/ | Arduino + C]] .

at 06:59 PM by Paul Badger Added line 39: * [[http://www. 2007.arduino.arduino.pl?num=1138892708 | Power supplies]] * [[http://www. 2007.cc/playground/Main/PWMallPins | PWM all of the digital pins in a sinewave pattern]] Restore May 10.arduino.cc/playground/Main/Freqout|More sound ideas]] Restore April 24.arduino.cc/cgi-bin/yabb2/YaBB.arduino.arduino. 2007.arduino.pl?num=1147888882 | Software serial]] (serial on pins besides 0 and 1) * [[http://www.pl?num=1139161553 | The components on the Arduino board]] * [[http://www.arduino.!!!Tech Notes (from the [[http://www.danslchamp.arduino. at 02:52 PM by Carlyn Maw Changed lines 52-54 from: *[[Tutorial/ShiftIn | Multiple digital ins with a CD4021 Shift Register]] to: Restore February 06.cc/playground/Code/EEPROM-Flash | Non-volatile memory (EEPROM)]] * [[http://www.cc/playground/Learning/Asuro | Arduino and the Asuro robot]] * [[http://www.pl?num=1171076259]] |Use a couple of Arduino pins as a capacitive sensor]] Restore May 10.arduino.pl?num=1171076259]] |Use a couple of Arduino pins as a capacitive sensor]] to: *[[http://www.cc/playground/Learning/CommandLine | Using Arduino from the command line]] Restore May 11. at 02:51 PM by Carlyn Maw Changed lines 52-53 from: . at 07:05 PM by Paul Badger Changed lines 36-37 from: * [[http://www. at 07:04 PM by Paul Badger Changed lines 36-37 from: to: * [[http://www.cc/cgi-bin/yabb2/YaBB.cc/cgi-bin/yabb2/YaBB.cc/cgi-bin/yabb2/YaBB. at 07:07 PM by Paul Badger Changed lines 36-37 from: * [[http://www.cc/cgi-bin/yabb2/YaBB.pl?num=1135701338 | Hex inverter]] * [[http://www.pl?num=1138666403 | Analog multiplexer]] * [[http://www.arduino. 2007.pl?num=1171076259 | Use two Arduino pins as a capacitive sensor]] Restore May 10.pl?num=1146679536 | LED as light sensor]] (en Francais) * [[http://www.arduino.cc/playground/Learning/Tutorial01 | Bluetooth]] * [[http://mrtof.cc/cgi-bin/yabb2/YaBB. 2007.cc/cgi-bin/yabb2/YaBB.cc/cgi-bin/yabb2/YaBB. 2007.cc/cgi-bin/yabb2/YaBB.arduino.arduino. 2007. 2007.cc/cgi-bin/yabb2/YaBB. at 12:02 PM by Carlyn Maw Changed lines 52-53 from: to: *[[Tutorial/ShiftIn | Multiple digital inputs with a CD4021 Shift Register]] Restore February 06.arduino.pl?num=1171076259]] Use a couple of Arduino pins as a capacitive sensor to: * [[http://www.pl?num=1171076259]] Use a couple of Arduino pins as a capacitive sensor Restore May 10.cc/playground/Learning/BuildProcess | Arduino build process]] * [[http://www.pl | forums]] or [[http://www.cc/cgi-bin/yabb2/YaBB.arduino.arduino. 2007.cc/playground/ | playground]]) * [[http://www.cc/playground/Code/OSXISPMKII | AVRISP mkII on the Mac]] * [[http://www.arduino. at 06:06 AM by Paul Badger Changed lines 17-18 from: to: * [[ http://www.arduino.arduino.cc/cgi-bin/yabb2/YaBB. at 03:40 PM by Clay Shirky Changed lines 13-14 from: * [[ Tutorial/Dimming LEDs | Dimming 3 LEDs with Pulse-Width Modulation (PWM) ]] to: * [[ Tutorial/Dimming LEDs | Simple Dimming 3 LEDs with Pulse-Width Modulation (PWM) ]] * [[ Tutorial/Color Crossfader | More complex dimming/color crossfader ]] Restore February 08.cc/cgi-bin/yabb2/YaBB.arduino.pl?num=1138310274 | L297 motor driver]] * [[http://www.arduino.org/AXIC | Zigbee]] * [[http://www.

edu/physcomp/Labs/Labs | Example labs from ITP]] * [[http://www.edu/physcomp/Labs/MIDIOutput | MIDI Output]] (from [[http://itp. Mellis Added lines 51-58: !!!Other Arduino Examples * [[ http://itp. 2006. 2006. Mellis Changed lines 20-21 from: * [[ Tutorial/ControleLEDcircleWithJoystick | Controlling an LED circle with a joystick]] to: Added line 24: * [[ Tutorial/ControleLEDcircleWithJoystick | Controlling an LED circle with a joystick]] Restore November 09. 2006. at 10:13 AM by David A.edu/physcomp/Labs/Labs | ITP physcomp labs]]) and [[http://todbot.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/ | Arduino + C]] Restore December 02. at 11:57 PM by David A.arduino.arduino.cc/playground/Interfacing/Ruby | Arduino + Ruby]] Restore November 18.cc/playground/Interfacing/MaxMSP | Arduino + MaxMSP]] Changed lines 67-68 from: to: * [[http://www. 2006. 2006. 2006. at 02:42 AM by David A. at 03:37 PM by David A. at 12:25 PM by David A.shtml | Examples from Tom Igoe]] . 2006. 2006.nyu.to: *[[Tutorial/ShiftIn | Multiple digital ins with a CD4021 Shift Register]] Restore January 30. Mellis Deleted line 46: * [[ Tutorial/DMX Master | Build your own DMX Master device]] Restore December 25.adding link to todbot's C serial port code.edu/physcomp/Labs/Labs | ITP physcomp labs]]) to: * [[http://itp. at 10:43 AM by David A.nyu. at 10:49 AM by David A.nyu.nyu.nyu.tigoe. at 12:24 PM by David A. 2006. at 03:10 PM by Carlyn Maw Changed lines 50-51 from: to: *[[Tutorial/ShiftOut | Multiple digital outs with a 595 Shift Register]] Restore November 06. Changed lines 69-70 from: to: * [[http://todbot. Mellis Added line 20: * [[ Tutorial/Switch | Using a pushbutton as a switch]] Restore December 07.edu/physcomp/Labs/MIDIOutput | MIDI Output]] (from [[http://itp. 2007. at 06:04 AM by David A. Mellis Changed lines 37-38 from: * [[http://itp. Mellis . Mellis Added line 1: (:title Tutorials:) Restore November 21. Mellis Added line 64: * [[http://www.com/blog/2006/10/29/spooky-arduino-projects-4-and-musical-arduino/ | from Spooky Arduino]] Restore November 04.net/pcomp/code/archives/avr/arduino/index. Mellis Deleted line 53: Deleted line 54: Restore November 04.

shtml | Examples from Tom Igoe]].tigoe. at 10:38 AM by David A. Restore November 04. !!!The Arduino environment This [[Main/Environment | guide to the Arduino IDE]] (integrated development environment) explains the functions of the various buttons and menus. .shtml | Examples from Tom Igoe]].* [[http://www.net/pcomp/code/archives/avr/arduino/index.edu/physcomp/Labs/Labs | Example labs from ITP]] * [[http://www.pl | forum]] for further help.sbk. Deleted lines 52-67: !!!The Arduino board This [[ Tutorial/ArduinoBoard | guide to the Arduino board]] explains the functions of the various parts of the board.com/blog/spookyarduino/ | Spooky Projects]] course: [[http://todbot. The [[Main/libraries]] page explains how to use libraries in your sketches and how to make your own.com/blog | todbot]] has some very detailed. For instructions on getting the board and environment up and running.net/pcomp/code/archives/avr/arduino/index. Mellis Changed lines 3-4 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino.edu/physcomp/Labs/Labs | Example labs from ITP]] * [[http://www.nyu.com/blog/?p=15 | Examples from Jeff Gray]].com/blog/?p=15 | Examples from Jeff Gray]] Deleted lines 83-89: !!!Other Arduino Examples * [[ http://itp. Mellis Changed line 77 from: !!!Other Arduino Sites to: !!!Other Arduino Examples Deleted lines 79-81: !!!Do you need extra help? Is there a sensor you would like to see characterized for Arduino. Restore November 04. For instructions on getting the board and environment up and running.grayfuse. [[http://todbot. !!!Video Lectures by Tom Igoe [[http://www.pdf | class 2 (input and sensors)]]. [[http://todbot.edu/physcomp/Labs/Labs | Example labs from ITP]] to: Changed lines 77-78 from: Also. illustrated tutorials from his [[http://todbot. or is there something you would like to see published in this site? Refer to the [[ http://www.lots of content moved to the new guide.grayfuse. see the Arduino [[Guide/HomePage | guide]].com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class1. Thanks to Pollie Barden for the great videos. and pwm)]]. servos. 2006. * [[http://www. Mellis Changed lines 50-51 from: !!!! [[ http://itp. 2006. * [[http://www.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class2.grayfuse.shtml | examples from Tom Igoe]] and [[http://www. !!!Course Guides [[http://todbot. at 12:24 PM by David A.net/pcomp/code/archives/avr/arduino/index. 2006.arduino. Restore November 04.org/arduino/index. Mellis . see the [[http://www.nyu.tigoe.nyu.html | Watch Tom]] introduce Arduino. see the Arduino [[Guide/Homepage | guide]]. at 10:37 AM by David A.cc/cgi-bin/yabb2/YaBB. at 12:23 PM by David A.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class3. Restore November 04.tigoe.com/blog/?p=15 | Examples from Jeff Gray]].pdf | class 1 (getting started)]]. to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino.pdf | class 3 (communication.flr4. 2006.com/blog/?p=15 | those from Jeff Gray]]. to: * [[ http://itp.grayfuse.

pdf | class 2 (input and sensors)]].makezine. [[http://todbot. illustrated tutorials from his [[http://todbot.pdf | class 2 (input and sensors)]]. stand-alone operation)]] Deleted lines 82-87: !!!External Resources [[http://www.pdf | class 3 (communication. [[http://todbot. For instructions on getting the board and environment up and running. see the [[Main/Howto]]. servos. 2006. to: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino.makezine.com/blog/spookyarduino/ | Spooky Projects]] course: [[http://todbot.com/blog | todbot]] has some very detailed.org/ | Instant Soup]] is an introduction to electronics through a series of beautifully-documented fun projects. at 06:06 PM by Carlyn Maw Added line 50: *[[Tutorial/ShiftOut | Extend your digital outs with 74HC595 shift registers]] Restore October 31. to: [[http://todbot.instantsoup. arduino+processing. 2006. 2006. and pwm)]]. [[http://todbot. 2006. to: !!Arduino Tutorials Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino. Mellis Changed lines 1-4 from: !!Learning to use Arduino Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class4.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class3.pdf | class 1 (getting started)]].pdf | class 4 (piezo sound & sensors. at 12:51 PM by David A.pdf | class 3 (communication. illustrated tutorials from his [[http://todbot. at 12:52 PM by David A. For instructions on getting the board and environment up and running. Mellis Changed lines 67-68 from: [[http://todbot.pdf | class 1 (getting started)]]. arduino+processing. at 10:47 AM by Tod E. at 06:54 PM by Carlyn Maw Deleted line 49: *[[Tutorial/ShiftOut | Extend your digital outs with 74HC595 shift registers]] Restore November 01. and pwm)]].pdf | class 4 (piezo sound & sensors. see the [[Main/Howto]].com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class1.com/blog | todbot]] has some very detailed. Restore November 04. servos.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class2. stand-alone operation)]] Restore October 22.com/blog/archive/electronics/ | electronics archive]].com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class1.com/blog/wp-content/uploads/2006/10/arduino_spooky_projects_class4. [[http://todbot. [[http://todbot. 2006. [[http://todbot. Restore October 22.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class2. [[http://www. illustrated tutorials from his [[http://todbot. [[http://www.com/blog | todbot]] has some very detailed.com/ | Make magazine]] has some great links in its [[http://www. see the Arduino [[Guide/Homepage | guide]]. Kurt Changed lines 67-68 from: [[http://todbot.com/ | hack a day]] has links to interesting hacks and how-to articles on various topics. Restore November 01.com/blog/spookyarduino/ | Spooky Projects]] course: [[http://todbot.hackaday. Mellis Changed lines 3-4 from: Here you will find a growing number of examples and tutorials for accomplishing specific tasks or interfacing to other hardware and software with Arduino.[[http://todbot. 2006.com/blog/wp- . For instructions on getting the board and environment up and running.com/blog/spookyarduino/ | Spooky Projects]] course: [[http://todbot.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class1.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class3. at 10:17 AM by David A.pdf | class 1 (getting started)]]. For instructions on getting the board and IDE up and running. see the [[Main/Howto]].

For instructions on getting the board and IDE up and running. to: This [[Main/Environment | guide to the Arduino IDE]] (integrated development environment) explains the functions of the various buttons and menus. at 05:45 PM by David A. 2006.pdf | class 1 (getting started)]].com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class1.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class2. Restore October 21. For instructions on getting the board and IDE up and running. 2006. servos. illustrated tutorials from his [[http://todbot.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class3.pdf | class 2 (input and sensors)]].nyu. at 04:25 PM by David A. The [[Main/libraries]] page explains how to use libraries in your sketches and how to make your own. Restore October 08. Added lines 66-68: !!!Course Guides [[http://todbot.com/blog/spookyarduino/ | Spooky Projects]] course: [[http://todbot. at 05:46 PM by David A.pdf | class 1 (getting started)]]. and pwm)]]. Restore October 08. at 05:38 PM by David A.nyu. [[http://todbot. Restore October 08.edu/physcomp/Labs/DigitalInOut | Digital Input and Output]] (from [[http://itp. [[http://todbot. Mellis Changed lines 59-62 from: This [[Environment | guide to the Arduino IDE]] (integrated development environment) explains the functions of the various buttons and menus.edu/physcomp/Labs/Labs | ITP physcomp labs]]) * [[ Tutorial/Pushbutton | Read a Pushbutton]] * [[ Tutorial/Tilt Sensor | Read a Tilt Sensor]] * [[ Tutorial/ControleLEDcircleWithJoystick | Controlling an LED circle with a joystick]] !!!! Analog Input * [[ Tutorial/Potentiometer | Read a Potentiometer]] * [[ Tutorial/JoyStick | Interfacing a Joystick]] * [[ Tutorial/Knock Sensor | Read a Piezo Sensor]] .content/uploads/2006/10/arduino_spooky_projects_class2. Mellis . Mellis Changed lines 3-4 from: Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. The [[libraries]] page explains how to use libraries in your sketches and how to make your own.com/blog/spookyarduino/ | Spooky Projects]] course: [[http://todbot. (:table width=90% border=0 cellpadding=5 cellspacing=0:) (:cell width=50%:) !!!Examples !!!! Digital Output * [[ Tutorial/Blinking LED | Blinking LED]] * [[ Tutorial/BlinkWithoutDelay | Blinking an LED without using the delay() function]] * [[ Tutorial/Dimming LEDs | Dimming 3 LEDs with Pulse-Width Modulation (PWM) ]] * [[ Tutorial/Knight Rider|Knight Rider example]] * [[ Tutorial/ShootingStar | Shooting star]] !!!! Digital Input * [[http://itp. to: Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it. see the [[Howto]]. Mellis Added lines 1-102: !!Learning to use Arduino Here you will find a growing number of step by step guides on how to learn the basics of arduino and the things you can do with it.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class1.com/blog | todbot]] has some very detailed. [[http://todbot. 2006. For instructions on getting the board and IDE up and running.adding links to todbot's class notes.pdf | class 2 (input and sensors)]].com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class2. to: [[http://todbot.com/blog | todbot]] has some very detailed.pdf | class 2 (input and sensors)]]. illustrated tutorials from his [[http://todbot.pdf | class 3 (communication. 2006. see the [[Howto]]. see the [[Main/Howto]].

pl?num=1135701338 | Hex inverter]] * [[http://www.cc/cgi-bin/yabb2/YaBB.nyu. * [[ Tutorial/Stepper Unipolar | Driving a Unipolar Stepper Motor]] * [[ Tutorial/DMX Master | Build your own DMX Master device]] * [[ Tutorial/Software Serial | Implement a software serial connection]] ** [[ http://www.cc/playground/Interfacing/Processing | Arduino + Processing]] * [[http://www.arduino.pl?num=1147888882 | Software serial]] (serial on pins besides 0 and 1) * [[http://www.flr4.arduino.arduino.* [[ Tutorial/LED cross-fades with potentiometer | 3 LED cross-fades with a potentiometer ]] * [[ Tutorial/LED color mixer with 3 potentiometers | 3 LED color mixer with 3 potentiometers]] !!!! Complex Sensors * [[ Tutorial/Accelerometer Memsic 2125 | Read an Accelerometer]] * [[ Tutorial/Ultrasound Sensor | Read an Ultrasonic Range Finder (ultrasound sensor)]] * [[ Tutorial/qt401 | Reading the qprox qt401 linear touch sensor]] !!!! Sound * [[Tutorial/Play Melody | Play Melodies with a Piezo Speaker]] * [[Tutotial/Keyboard Serial | Play Tones from the Serial Connection]] * [[http://itp. !!!Interfacing with Other Software * [[http://itp.arduino.cc/playground/Interfacing/Director | Arduino + Director]] !!!Tech Notes (from the [[http://www.cc/cgi-bin/yabb2/YaBB.nyu.nyu.cc/playground/ | playground]]) * [[http://www.arduino.pl | forums]] or [[http://www.pl?num=1138892708 | Power supplies]] * [[http://www.edu/physcomp/Labs/MIDIOutput | MIDI Output]] (from [[http://itp.cc/cgi-bin/yabb2/YaBB.cc/playground/Code/OSXISPMKII | AVRISP mkII on the Mac]] * [[http://www.cc/playground/Code/EEPROM-Flash | Non-volatile memory (EEPROM)]] * [[http://www.nyu.arduino.arduino.edu/physcomp/Labs/Labs | ITP physcomp labs]]) * [[http://www. Thanks to Pollie Barden for the great videos.arduino.arduino.arduino.edu/physcomp/Labs/Labs | ITP physcomp labs]]).arduino.arduino.nyu.pl?num=1138310274 | L297 motor driver]] * [[http://www.cc/playground/Learning/Tutorial01 | Bluetooth]] .arduino.arduino.arduino.org/arduino/index.cc/cgi-bin/yabb2/YaBB.edu/physcomp/Labs/Serial | Introduction to Serial Communication]] (from [[http://itp.arduino.edu/physcomp/Labs/DCMotorControl | Driving a DC Motor with an L293]] (from [[http://itp.sbk. !!!The Arduino environment This [[Environment | guide to the Arduino IDE]] (integrated development environment) explains the functions of the various buttons and menus. The [[libraries]] page explains how to use libraries in your sketches and how to make your own.cc/cgi-bin/yabb2/YaBB.cc/playground/Learning/BuildProcess | Arduino build process]] * [[http://www.cc/playground/Interfacing/Flash | Arduino + Flash]] * [[http://www.nyu.arduino.cc/en/Tutorial/ArduinoSoftwareRS232 | RS-232 computer interface]] *[[Tutorial/SPI_EEPROM | Interface with a serial EEPROM using SPI]] *[[Tutorial/SPI_Digital_Pot | Control a digital potentiometer using SPI]] !!!! [[ http://itp.cc/playground/Interfacing/PD | Arduino + PD]] * [[http://www.edu/physcomp/Labs/Labs | ITP physcomp labs]]) !!!! Interfacing w/ Hardware * [[ Tutorial/LED Driver | Multiply the Amount of Outputs with an LED Driver ]] * [[ Tutorial/LCD 8 bits | Interfacing an LCD display with 8 bits]] **[[Tutorial/LCD library | LCD interface library]] * [[http://itp.html | Watch Tom]] introduce Arduino.pl?num=1139161553 | The components on the Arduino board]] * [[http://www.cc/cgi-bin/yabb2/YaBB.nyu. !!!Video Lectures by Tom Igoe [[http://www.cc/cgi-bin/yabb2/YaBB.arduino.edu/physcomp/Labs/Labs | Example labs from ITP]] (:cell width=50%:) !!!The Arduino board This [[ Tutorial/ArduinoBoard | guide to the Arduino board]] explains the functions of the various parts of the board.cc/playground/Interfacing/VVVV | Arduino + VVVV]] * [[http://www.pl?num=1138666403 | Analog multiplexer]] * [[http://www.

arduino.arduino.tigoe.cc/playground/Learning/Asuro | Arduino and the Asuro robot]] [[http://www.cc/playground/Learning/CommandLine | Using Arduino from the command line]] !!!Other Arduino Sites Also. [[http://www.com/ | Make magazine]] has some great links in its [[http://www. !!!Do you need extra help? Is there a sensor you would like to see characterized for Arduino.com/ | hack a day]] has links to interesting hacks and how-to articles on various topics. see the [[http://www.net/pcomp/code/archives/avr/arduino/index.arduino.com/blog/?p=15 | those from Jeff Gray]]. !!!External Resources [[http://www.danslchamp.makezine.hackaday. or is there something you would like to see published in this site? Refer to the [[ http://www.com/blog/archive/electronics/ | electronics archive]].grayfuse.pl?num=1146679536 | LED as light sensor]] (en Francais) [[http://www.* * * * [[http://mrtof. [[http://www.instantsoup.org/ | Instant Soup]] is an introduction to electronics through a series of beautifully-documented fun projects.shtml | examples from Tom Igoe]] and [[http://www.arduino.pl | forum]] for further help.makezine.org/AXIC | Zigbee]] [[http://www.cc/cgi-bin/yabb2/YaBB. (:tableend:) Restore Edit Page | Page History | Printable View | All Recent Site Changes .cc/cgi-bin/yabb2/YaBB.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links

search

Blog » | Forum » | Playground »

Time Since Start
A sketch to illustrate keeping track of real world time since the board was started or reset. The sketch is based on the millis() function, which returns the number of milliseconds since the Freeduino was reset. One problem with millis() is that the unsigned long variable it returns will overflow every 9.3 hours. If this overflow is not managed, math in a sketch will break. Re: Millis Rollover Workaround Reply #1 - 06.09.2007 at 01:06:47 Quote You can access it by putting: extern unsigned long timer0_overflow_count; at the top of your sketch. However, there's probably a better way to deal with the overflow. For example, if you just need to be able to get the duration between multiple calls to millis(), you should be able to do a millis() - previous_millis (which should work past the rollover). Or, you could do something like: current_millis_value = millis(); m += current_millis_value - previous_millis_value; // should work even when millis rolls over seconds += m / 1000; m = m % 1000; minutes += seconds / 60; seconds = seconds % 60; hours += minutes / 60; minutes = minutes % 60; previous_millis_value = current_millis_value;

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino
Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ

search

Blog » | Forum » | Playground »

Login to Arduino
Username: Password: Keep me logged in:
Login

Edit Page | Page History | Printable View | All Recent Site Changes

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

ArduinoBoard) Guide Contents | Introduction | How To: Windows.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ (redirected from Tutorial. Serial. Xbee shield | Troubleshooting | Environment (:redirect Reference/Board:) search Blog » | Forum » | Playground » Introduction to the Arduino Board Looking at the board from the top down.S1 (dark blue) In-circuit Serial Programmer (blue-green) Analog In Pins 0-5 (light blue) Power and Ground Pins (power: orange. can be used to power the board) (yellow) Digital Pins In addition to the specific functions listed below. Arduino Mini.SV1 (purple) USB (used for uploading sketches to the board and for serial communication between the board and the computer. Arduino Nano.begin ) .These pins cannot be used for digital i/o ( digitalRead and digitalWrite ) if you are also using serial communication (e. Each pin has an internal pull-up resistor which can be turned on and off using digitalWrite() (w/ a value of HIGH or LOW.TX/RX (dark green) . LilyPad Arduino. Reset Button .g. the digital pins on an Arduino board can be used for general purpose input and output via the pinMode(). digitalRead(). Arduino BT. . The maximum current per pin is 40 mA. and digitalWrite() commands. Linux. Mac OS X.X1 (pink) Toggles External Power and USB Power (place jumper on two pins closest to desired supply) . this is an outline of what you will see (parts of the board you might interact with in the course of normal use are highlighted): Starting clockwise from the top center: Analog Reference pin (orange) Digital Ground (light green) Digital Pins 2-13 (green) Digital Pins 0-1/Serial In/Out . respectively) when the pin is configured as an input. grounds: light orange) External Power Supply In (9-12VDC) .

Reset. On the Arduino Mini and LilyPad Arduino. External Interrupts: 2 and 3. a rising or falling edge. The text of the Arduino getting started guide is licensed under a Creative Commons Attribution-ShareAlike 3. The input voltage to the Arduino board when it's using an external power source (as opposed to 5 volts from the USB connection or other regulated power source). 10. 12 (MISO). they are intended for use with an external TTL serial module (e. GND. You can supply voltage through this pin. Used to receive (RX) and transmit (TX) TTL serial data. I 2 C: 4 (SDA) and 5 (SCL). These pins can be configured to trigger an interrupt on a low value. 10. when the pin is LOW. When the pin is HIGH value. 5. Most of the analog inputs can also be used as digital pins: analog input 0 as digital pin 14 through analog input 5 as digital pin 19. although provided by the underlying hardware. PWM output is available only on pins 9. On the Arduino BT. please see the documentation for your board. which. Support I 2 C (TWI) communication using the Wire library (documentation on the Wiring website).g. these pins are connected to the corresponding pins of the FTDI USB-to-TTL Serial chip. 3V3. and 11. the LED is on. they are connected to the corresponding pins of the WT11 Bluetooth module. The regulated power supply used to power the microcontroller and other components on the board. Reference voltage for the analog inputs. These pins support SPI communication. Other Pins AREF. Note that different boards accept different input voltages ranges. is not currently included in the Arduino language. On the Arduino Diecimila. or. This can come either from VIN via an on-board regulator. PWM: 3. access it through this pin. and 11. Analog inputs 6 and 7 (present on the Mini and BT) cannot be used as digital pins. On the Diecimila and LilyPad.0 License.3 volt supply generated by the on-board FTDI chip. BT Reset: 7. Code samples in the guide are released into the public domain. if supplying voltage via the power jack. 13 (SCK). or a change in value. 11 (MOSI). the analog input pins support 10-bit analog-to-digital conversion (ADC) using the analogRead() function. Provide 8-bit PWM output with the analogWrite() function. See the attachInterrupt() function for details. 6.Serial: 0 (RX) and 1 (TX). it's off. (Arduino BT-only) Connected to the reset line of the bluetooth module. (Diecimila-only) A 3. Also note that the LilyPad has no VIN pin and accepts only a regulated input. SPI: 10 (SS). Analog Pins In addition to the specific functions listed below. the Mini-USB Adapter). On boards with an ATmega8. Edit Page | Page History | Printable View | All Recent Site Changes . or be supplied by USB or another regulated 5V supply. Ground pins. (Diecimila-only) Bring this line LOW to reset the microcontroller. there is a built-in LED connected to digital pin 13. 9. Power Pins VIN (sometimes labelled "9V"). Typically used to add a reset button to shields which block the one on the board. 5V. Not currently supported by the Arduino software. LED: 13.

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Login to Arduino Username: Password: Keep me logged in: Login Edit Page | Page History | Printable View | All Recent Site Changes .

Master your semester with Scribd & The New York Times

Special offer for students: Only $4.99/month.

Master your semester with Scribd & The New York Times

Cancel anytime.