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

Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O board. but in fewer lines. the length of the array) void setup() { int i. one by one using only digitalWrite(pinNum.HIGH/LOW) and delay(time).1 .e. 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. 6. for (i = 0. Circuit Code int timer = 100. // The higher the number. the slower the timing.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. The first code example will make the LEDs blink in a sequence.7 on the board using 220 Ohm resistors. 4. This example makes use of 6 LEDs connected to the pins 2 . int pins[] = { 2. 5. i++) // the array elements are numbered from 0 to num pins .) construction to perform the very same thing. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. i < num pins. it would be interesting to use the Knight Rider as a metaphor. The second example shows how to use a for(. 7 }. // an array of pin numbers int num_pins = 6.

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

that value controls the rate at which an LED blinks. 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. there are 0 volts going to the pin. which we can read into the Arduino board as an analog value. */ int potPin = 2. Circuit Code /* * AnalogInput * by DojoDave <http://www. there are 5 volts going to the pin and we read 1023.org> * * Turns on and off a light emitting diode(LED) connected to digital * pin 13. In between. int ledPin = 13. we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. When the shaft is turned all the way in the other direction. In the easiest case we connect * a potentiometer to analog pin 2.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.0j0. The second goes from 5 volts to the other outer pin of the potentiometer. // select the input pin for the potentiometer // select the pin for the LED . In this example. and we read 0. We connect three wires to the Arduino board. 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. The third goes from analog input 2 to the middle pin of the potentiometer. By turning the shaft of the potentiometer. giving us a different analog input. This changes the relative "closeness" of that pin to 5 volts and ground.

delay(val). delay(val). digitalWrite(ledPin. digitalWrite(ledPin. // 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 .int val = 0. OUTPUT). LOW). HIGH). } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin).

value). void setup() { // nothing for setup } void loop() { for(value = 0 . Code int value = 0.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. int ledpin = 9. value <= 255. } } // variable to keep the actual value // light connected to digital pin 9 Edit Page | Page History | Printable View | All Recent Site Changes . value+=5) // fade in (from min to max) { analogWrite(ledpin. value >=0. Circuit An LED connected to digital pin 9. // sets the value (range from 0 to 255) delay(30). // waits for 30 milli seconds to see the dimming effect } for(value = 255. delay(30). value). value-=5) // fade out (from max to min) { analogWrite(ledpin.

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

delay(10). followed by newline short delay to avoid overloading the serial port Edit Page | Page History | Printable View | All Recent Site Changes .println("Knock!"). // // // // // 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. to toggle the light threshold value to decide when the detected sound is a knock or not void setup() { pinMode(ledPin. // declare the ledPin as as OUTPUT Serial. statePin). Serial. } } // 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. int THRESHOLD = 100.* We have to basically listen to an analog pin and detect * if the signal goes over a certain threshold. int statePin = LOW.arduino. digitalWrite(ledPin. int knockSensor = 0. * and toggles the LED on pin 13. // use the serial port } void loop() { val = analogRead(knockSensor). byte val = 0.cc/en/Tutorial/Knock */ int ledPin = 13. if (val >= THRESHOLD) { statePin = !statePin.begin(9600). OUTPUT). * * http://www.

index = (index + 1). average = 0.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 . for (int i = 0. if (index >= NUMREADINGS) index = 0. but the slower the output will // respond to the input. // the more the readings will be smoothed. Circuit Potentiometer on analog input pin 0.begin(9600)..println(average). total += readings[index]..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. index = 0. Code // Define the number of samples to keep track of. #define NUMREADINGS 10 int int int int readings[NUMREADINGS]. readings[index] = analogRead(inputPin). Serial. total = 0. // . Using a #define rather than a normal variable lets // use this value to determine the size of the readings array. The higher the number. void setup() { Serial. calculating a running average and printing it to the computer.. i < NUMREADINGS. i++) readings[i] = 0. Demonstrates the use of arrays. } // 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. average = total / NUMREADINGS. // // // // the the the the readings from the analog input index of the current reading running total average int inputPin = 0.. } void loop() { total -= readings[index].

HEX).print(number. Serial. octal. 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 . oct: "). Serial.print(". bin: "). hexadecimal.print(number. } int number = 33. // Serial. Serial. dec: ").println("ASCII Table ~ Character Map").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. // first visible character '!' is #33 void loop() { Serial.print(". BIN).print(". OCT). DEC).print(".print(number). Serial..zambetti. BYTE).begin(9600). hex: "). and binary. // wait for the long string to be sent delay(100).. if(number == 126) { // loop forever while(true) { continue. Serial. Code // ASCII Table // by Nicholas Zambetti <http://www.print(number. Serial. Circuit None. but the Arduino has to be connected to the computer. Serial. // prints value unaltered.println(number.com> void setup() { Serial. } } . // prints title with ending line break Serial. Serial.print(number.

&. ". '. // to the next character delay(100). .number++. %. oct: 47. dec: 40. ~ Character Map hex: 21. oct: 41. dec: 38. oct: 42. oct: 50.. dec: 33. dec: 37. hex: 26. dec: 34. #. oct: 43. oct: 46. hex: 28. oct: 44. hex: 27. 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 . hex: 22. hex: 24. // allow some time for the Serial data to be sent } Output ASCII Table !.. $. oct: 45. dec: 36. dec: 39. hex: 23. (. dec: 35. hex: 25.

150). in this case to control the brightness of an LED.sends bytes over a serial port // by David A. Serial port. Code int ledPin = 9. void setup() { size(256.list()). Circuit An LED connected to pin 9 (with appropriate resistor). Arduino reads these bytes and uses them to set the brightness of the LED. } void loop() { byte val.serial. } } Processing Code // Dimmer . Mellis import processing.available()) { // read the most recent byte (which will be from 0 to 255) val = Serial. OUTPUT). pinMode(ledPin. The data is sent in individual bytes. val). // check if data has been sent from the computer if (Serial. println(Serial. // set the brightness of the LED analogWrite(ledPin.read(). // Uses the first port in this list (number 0). each of which ranges from 0 to 255. void setup() { // begin the serial communication Serial. println("Available serial ports:").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.*.begin(9600). Change this to .

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

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

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

available()) { val = Serial. } if (val == 'L') { digitalWrite(outputPin. PD. the Arduino boards turns on an LED when it receives the character 'H'. and turns off the LED when it receives the character 'L'. void setup() { Serial. or Max/MSP.begin(9600). Flash (via a serial-net proxy). if (val == 'H') { digitalWrite(outputPin. or another program like Processing (see code below). OUTPUT). // created 13 May 2004 import processing. Code int outputPin = 13. } void loop() { if (Serial. int val.interaction-ivrea. In this case.it/h.barragan> // Demonstrates how to send data to the Arduino I/O board. } } } Processing Code // mouseover serial // by BARRAGAN <http://people. LOW).read(). void setup() . The data can be sent from the Arduino serial monitor.*. Serial port. pinMode(outputPin. HIGH). Circuit An LED on pin 13. in order to // turn ON a light if the mouse is over a rectangle and turn it off // if the mouse is not.serial.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.

{ size(200. port. 100. Serial. println(Serial. noStroke(). } // function to test if mouse is over square boolean mouseOverRect() { return ((mouseX >= 50)&&(mouseX <= 150)&&(mouseY >= 50)&(mouseY <= 150)).write('L').list()). port. } else { fill(#666660). frameRate(10). 50. if(mouseOverRect()) { fill(#BBBBB0). // List all the available serial ports in the output pane.list()[0]. } // 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 . // You will need to choose the port that the Arduino board is // connected to from this list. 200). // 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. } void draw() { background(#222222). The first port in the list is // port #0 and the third port in the list is port #2. 9600). 100).write('H'). } rect(50.

jtnimoy. green.println(analogRead(greenPin)). } Processing Code /** * Color Mixer * by David A. int greenPin = 1. Code int redPin = 0. void setup() { Serial. 1. Serial. the readings from three potentiometers are used to set the red. Serial.println(analogRead(bluePin)). int rval = 0. gval = 0.serial.print("B"). Serial. } void loop() { Serial. * * Created 8 February 2003 * Updated 2 April 2005 */ import processing. String buff = "". and 2. In this case. delay(100).print("G"). bval = 0. int bluePin = 2.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. Serial.print("R").begin(9600).println(analogRead(redPin)). Circuit Potentiometers connected to analog input pins 0. Mellis * * Created 2 December 2006 * * based on Analog In * by <a href="http://itp. Serial.com">Josh Nimoy</a>. and blue components of the background color of a Processing sketch.*. .

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

* * 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 * _ * */ . when the pin is set to an input. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive. They are accessible from software by using the digitalWrite() function.+5 volts in the Arduino's case) built into the Atmega chip upon which Freeduino's are based. * it will overwhelm the 200K resistor and the pin will report HIGH. The job of the 10K series resistor. In this case the scheme just reports that sw2 is pushed. but when the pullup resistor is turned on. 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. This sketch exploits the pullup resistors under software control. incidentally. When the internal pullup resistor is turned on however. /* * 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. it will overwhelm the external 200K resistor and the pin will report HIGH.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 . 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. is to prevent a short circuit if a pesky user pushes both buttons at once.

stateA = digitalRead(swPin). void setup() { Serial. } else if ( stateA == 0 && stateB == 0 ){ sw1 = 0. int sw1.#define swPin 2 int stateA. } else{ sw1 = 0. } void loop() { digitalWrite(swPin. sw2 = 0.switch 1 must be pushed // both states LOW .print(sw1). digitalWrite(swPin.switch 2 must be pushed // stateA HIGH and stateB LOW // no switches pushed . HIGH). } Serial.println(sw2). position sw2 = 0. delay(100). Serial. // pin for input .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. sw2 = 1. } // both states HIGH .begin(9600).print(" "). sw2. stateB = digitalRead(swPin).or center-off toggle in middle // pad some spaces to format print output Edit Page | Page History | Printable View | All Recent Site Changes . Serial. LOW).

Edit Page | Page History | Printable View | All Recent Site Changes . 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. This type of sensor is the environmental-friendly version of a mercuryswitch. 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. 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. by Anders Gran Code Use the Digital > Button example to read the tilt-sensor. The hardware was mounted and photographed by Anders Gran. 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.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. Circuit Picture of a protoboard supporting the tilt sensor. the software comes from the basic Arduino examples. 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. We have chosen the tilt sensor from Assemtech.

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 .

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

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. espera = 40.8. // slider variable connecetd to analog coordX = 0. // variable to read the value from the coordY = 0.4.y) * * The program then calculates to which of the 8 * possible zones belogns the coordinate (x.5.6. // variable to read the value from the a circle the leds pin 0 pin 1 analog pin 0 analog pin 1 . // Array of 8 leds mounted in ledVerde = 13.9 }.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. // Time you should wait for turning on joyPin1 = 0.7. // slider variable connecetd to analog joyPin2 = 1.3.

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

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

) * * Put 220 Ohm resistors in line with pots.begin()-style communication * * Control 3 LEDs with 3 potentiometers * If the LEDs are different colors. to prevent small changes in // pot values from triggering false reporting // FLAGS int PRINT = 1. orange. 10 and 11 10. the colors will mix together. and Blue. * * Standard colors for light mixing are Red. // Aggregate pot values int prevCheckSum = 0. // Loop counter int wait = (1000). // LEDs connected to digital pins 9. int bVal = 0. stop adjusting the pots. // (Connect power to 5V and ground to analog ground) 2. int sens = 3. green. though you can mix * with any three colors. as it uses Serial. // Sensitivity theshold. or placed in a paper coffee cup with a cut-out bottom and * a white plastic lid). and purple (though no yellow. // Values int aVal = 0. // sets the digital pins as output . // Delay between most recent pot adjustment and output int checkSum = 0. 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. * * When you mix a color you like. Green. // Set to 1 to turn on debugging output void setup() { pinMode(aOut. * The mix values that create that color will be reported via serial out. int cVal = 0. // Variables to store the input from the potentiometers // Variables for comparing values between loops int i = 0. and are directed at diffusing surface (stuck in a * a Ping-Pong ball. // Set to 1 to output values int DEBUG = 1. and 2 1. Red + Blue + White would let you mix shades of red. // (Connect cathodes to digital ground) 11. * blue. OUTPUT).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. 1. or blue-green. // Potentiometers connected to analog pins 0. pin settings 9.

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

// sets the digital pin as output // not really necessary. HIGH). * making two things happen at once. int blinking. printing fractions * * Physical setup: momentary switch connected to pin 4.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. /* StopWatch * Paul Badger 2008 * Demonstrates using millis(). int lastButtonState. ground. pins default to INPUT anyway // turn on pullup resistors. other side connected to ground * LED with series resistor between pin 13 and ground */ #define ledPin 13 #define buttonPin 4 int value = LOW. digitalWrite(buttonPin. OUTPUT). pullup resistors.start the clock startTime = millis().begin(9600). 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 . } void loop() { // check for button press buttonState = digitalRead(buttonPin). long elapsedTime . 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 . long startTime . // store the start time // turn on blinking while timing . int fractional.timer is timing blink interval . pinMode(ledPin. long interval = 100. blinking = true. INPUT). int buttonState. long previousMillis = 0.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().

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

g. Circuit An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino. The pins used are designed to be easily compatible with the breakout boards from Sparkfun. zpin = 1. 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. ADXL322. which is read by an analog input on the Arduino.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. powerpin = 19. ADXL321. ADXL320. ypin = 2. // // // // // analog analog x-axis y-axis z-axis input pin 4 input pin 5 of the accelerometer (only on 3-axis models) . ADXL330) accelerometer and communicates the acceleration to the computer. The ADXL3xx outputs the acceleration on each axis as an analog voltage between 0 and 5 volts. 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. xpin = 3.

pinMode(powerPin. // Provide ground and power by using the analog inputs as normal // digital pins. With the axis horizontal (i.void setup() { Serial. delay(1000). OUTPUT).print(analogRead(zpin)).print(analogRead(xpin)). you can remove these lines. but values at other angles will be different for a different accelerometer (e. LOW). pinMode(groundPin.g. the accelerometer reading should be around 512.print(" "). This makes it possible to directly connect the // breakout board to the Arduino.print(analogRead(ypin)). Serial. digitalWrite(groundPin. } void loop() { Serial. OUTPUT). HIGH). digitalWrite(powerPin. parallel to ground or 0°). Serial. the ADXL302 5g one).println().e. Serial. Serial. } Data Here are some accelerometer readings collected by the positioning the y-axis of an ADXL322 2g accelerometer at various angles from ground. but will vary based on the sensitivity of the device. If you use the normal 5V and // GND pins on the Arduino. Values should be the same for the other axes. Serial. 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 .print(" ").begin(9600).

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. who is Arduino's accelerometer technology researcher.Sweden @author: Marcos Yarza . the sensor counts with a temperature pin that can be used to compensate possible errors. The example shown here was mounted by Anders Gran. leaving the temperature pin open. while the the temperature should be taken as an analog input. The board is connected minimally.org copyleft 2005 K3 . makes the monitor LED blink once sent http://www. The pins dedicated to measure acceleration can be connected directly to digital inputs to the Arduino board. When making very accurate measurements. Spain.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. only the two axis pins are plugged to the board. 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. Protoboard with an Accelerometer.0j0.Malmo University . at the University of Zaragoza.

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

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. by M. Edit Page | Page History | Printable View | All Recent Site Changes . printInteger(accel). } Accelerometer mounted on prototyping board. digitalWrite(ledPin. LOW). Yarza The following example is an adaptation of the previous one. Here the code is exactly the same as before (changing the input pins to be 2 and 3). } printByte(sign). but the installation on the board allows to embed the whole circutry in a much smaller housing. printByte(' '). HIGH). //reads and represents acceleration X readAcceleration(yaccPin). } void loop() { readAcceleration(xaccPin).else { printByte('Y'). delay(300). //reads and represents acceleration Y digitalWrite(ledPin.

while the software was created by David Cuartielles.0 /* Ultrasound Sensor *-----------------* * Reads values (00014-01199) from an ultrasound sensor (3m sensor) * and writes the values to the serialport. // Ultrasound signal pin . The example shown here was mounted by Marcus Hannerstig.se | http://www. The sensor counts with 3 pins. Once the tone is received back. The width of that pulse will determine the distance to the object. while the third one is used both as input and output.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. The board is connected as explained using only wires coming from an old computer. Ultrasound sensor connected to an Arduino USB v1.0j0. the sensor will send a pulse over the same pin as earlier. 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. * * http://www.xlab. The pin dedicated to make the readings has to be shifting configuration from input to output according to the PING specification sheet.

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

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

} // . // = 5. 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. pinMode(qt401_di.qprox. pinMode(qt401_do. OUTPUT). pinMode(qt401_ss. digitalWrite(qt401_ss. pinMode(qt401_clk. // = 7.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.HIGH). INPUT). HIGH). 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. void qt401_init() { // define pin directions pinMode(qt401_drd. // = 8. pinMode(qt401_det. INPUT). OUTPUT).potemkin. INPUT). // = 3. pinMode(qt401_prx. // = 6. // data ready data in (from sensor) slave select clock data out (to sensor) detect proximity byte result. // = 4. // initialise pins digitalWrite(qt401_clk.

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

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

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

that supports the functionality of writing a PWM signal to it. We are taking advantage of the processors capability to produde PWM signals in order to play music. 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. 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. 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. and not just a plain HIGH or LOW value. Sometimes it is possible to acquire Piezo elements without a plastic housing. . commercial devices are usually having a red and a black wires indicating how to plug it to the board. The first example of the code will just send a square wave to the piezo.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. then they will just look like a metallic disc. The other thing to remember is that Piezos have polarity. We connect the black one to ground and the red one to the output. to create signature frequencies.

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

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

'b'. byte names[] = {'c'.* loop before stopping * ADD another octave * MOVE tempo. int MAX_COUNT = 24. int count2 = 0. for (count = 0. int count3 = 0.arduino.48) * 30. using analogWrite. 1432. } void loop() { analogWrite(speakerOut. * * 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. count < MAX_COUNT. it requires to know * about timing issues and about how to play tones. 1014. void setup() { pinMode(ledPin. statePin). 956}. 1700. 'C'}. Cuartielles for K3 */ int ledPin = 13. count++) { statePin = !statePin. 0). as with the second program at * http://www. 1519. OUTPUT). int speakerOut = 9.) * 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. count3++) { . byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". 1136. int statePin = LOW. // 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. for (count3 = 0. pause. count3 <= (melody[count*2] . with volume control set using analogWrite() /* Play Melody * ----------* * Program to play melodies stored in an array. 'e'. and rest_count to #define statements * RE-WRITE to include volume. 'a'. digitalWrite(ledPin. 'g'. 1275. 'd'. 'f'. int tones[] = {1915.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.

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

. Malmo University * @author: David Cuartielles. There is more information about this microchip that you will find in its datasheet. E.Experiential Vehicles */ int data = 9. if dato is 1.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. It is possible to daisy chain this chip increasing the total amount of LEDs by 8 each time. stored in "dato" on a set of 8 LEDs * * (copyleft) 2005 K3. if dato is 255 all the LEDs will light up. Marcus Hannerstig * @hardware: David Cuartielles.g. Example of connection of a 4794 /* Shift Out Data * -------------* * Shows a byte. We use the 4794 from Philips. An LED Driver has a shift register embedded that will take data in serial format and transfer it to parallel. int strob = 8. Marcos Yarza * @project: made for SMEE . The code example you will see here is taking a value stored in the variable dato and showing it as a decoded binary number. only the first LED will light up.

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

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

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

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

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

Ground. so keep them as short and tidy as possible. It is a lot of wires. 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. Look at the datasheet for your LCD board to figure out which pins are where. . and the contrast adjustment pin on your LCD.

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

init(). #include <LiquidCrystal.HIGH). //clear the display delay(1000).print('c'). //turn on an LED for debugging } void loop(void){ lcd.Now let's try something a little more interesting. lcd. //delay 1000 ms to view change lcd. //create a LiquidCrystal object to control an LCD void setup(void){ lcd. delay(1000). Compile and upload the following code to the Arduino. .h> //include LiquidCrystal library LiquidCrystal lcd = LiquidCrystal(). //initialize the LCD digitalWrite(13. //send individual letters to the LCD lcd.print('b').print('a').clear().//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.

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

this stepper: "[. 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.uiowa. The second example is coded in a more complex way. These motors can be found in old floppy drives and are easy to control. It is aiming those that have no knowledge in how to control stepper motors. and controlling both from a potentiometer.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. The prototyping board has been populated with a 10K potentiomenter that we connect to an analog input. The first example is the basic code to make the motor spin in one direction.html] . 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.. with 1.cs.. 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. with center taps brought out to separate leads [. but allows to make the motor spin at different speeds.] motor made by Copal Electronics.edu/~jones/step/example. and a ULN2003A driver... This chip has a bunch of transistors embedded in a single housing.]" [http://www. in both directions.8 degrees per step and 96 ohms per winding.

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

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

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

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 .

RXval = SWread(). This should be used when multiple serial connections are necessary. Make any other connections necessary for your device. NOT a specific device tutorial. Materials needed: Device to communicate with Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . SWprint(TXval2).optional. Connect ground on the breadboard to ground from the microcontroller. . Otherwise connect power and ground from an alternate power source to the breadboard in the same fashion. Returns a byte long integer value from the software serial connection Example: byte RXval. A tutorial on communicating with a computer is here. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. SWprint(TXval). SWprint(). 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. see the SoftwareSerial library included with Arduino 0007 and later. Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground. In this tutorial you will learn how to implement Asynchronous serial communication on the Arduino in software to communicate with other serial devices. The software serial connection can run at 4800 baud or 9600 baud reliably. Read on if you'd like to know how that library works. If your device uses 5v power connect 5v from the microcontoller to 5v on the breadboard. This is a general purpose software tutorial. For a good explanation of serial communication see Wikipedia. byte TXval2 = 126. for debugging Prepare the breadboard Insert the device you want to communicate with in the breadboard. Functions Available: SWread(). Device specific tutorials are on the Tutorial Page. If only one serial connection is necessary the hardware serial port should be used.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. Sends a byte long integer value out the software serial connection Example: byte TXval = 'h'.

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

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

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

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

Materials needed: Computer with a terminal program installed (ie. If you are using an LED connect it between pin 13 and ground. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 . Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller.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. . Zterm on Mac) Serial-Breadboard cable MAX3323 chip (or similar) 4 1uf capacitors Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . HyperTerminal or RealTerm on the PC.11 to 5V.optional. A general purpose software serial tutorial can be found here. 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. GND wires are black Connect a 1uF capacitor across pins 1 and 3. Connect your RX pin (6) to MAX3323 pin 9 (R1OUT). another across pins 4 and 5. +5v wires are red. Connect your TX pin (7) to MAX3323 pin 10 (T1IN). another between pin 1 and ground. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground). .+5v wires are red. and the last between pin 6 and ground.

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

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. Connect the TX line from your computer to pin 8 (R1IN) on the MAX233 and the RX line to pin 7 (T1OUT). . Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port. Heatshrink the wire connections to avoid accidental shorts.

mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx.h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 byte rx = 6. //debugging hello SWprint('i').OUTPUT). RX wires Blue.cc #include <ctype. byte SWval. Upload the following code into the Arduino microcontroller module: //Created August 23 2006 //Heather Dewey-Hagborg //http://www.INPUT). for (mask = 0x01. pinMode(tx.HIGH).LOW). digitalWrite(tx. digitalWrite(13. GND wires are black Program the Arduino Now we will write the code to enable serial data communication. delayMicroseconds(bit9600Delay). //turn on debugging LED SWprint('h').HIGH). // send 1 } else{ .arduino. //startbit digitalWrite(tx. //carriage return } void SWprint(int data) { byte mask.TX wires Green. +5v wires are red. SWprint(10). 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. mask>0. 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. void setup() { pinMode(rx.HIGH). byte tx = 7.

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

photos by Thomas Dexter Edit Page | Page History | Printable View | All Recent Site Changes . code and tutorial by Heather Dewey-Hagborg. 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.If this works.

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

7 and 8 to 5v and pin 4 to ground. runs at up to 10MHz at 5v and can run at slower speeds down to 1.Sets the SPI speed. but it can be read 1-128 bytes at a time. . Introduction to Serial EEPROM The AT25HP512 is a 65. Now that you have a feel for how SPI works. Instructions are sent as 8 bit operational codes (opcodes) and are shifted in on the rising edge of the data clock.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. The device is enabled by pulling the Chip Select (CS) pin low. Connect EEPROM pins 3. let's take a look at the details of the EEPROM chip. but we won't be covering those in this tutorial. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. It supports SPI modes 0 and 3. Prepare the Breadboard Insert the AT25HP512 chip into the breadboard.SPR1 and SPR0 . 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.8v. It can only be written 128 bytes at a time. 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.

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

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

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

system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR).HIGH).OUTPUT). byte eeprom_input_data=0. } 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. // return the received byte } void setup() { Serial.I<128. //send MSByte address first spi_transfer((char)(EEPROM_address)). //get data byte digitalWrite(SLAVESELECT. //sample on leading edge of clk.msb 1st.begin(9600). //disable device // SPCR = 01010000 //interrupt disabled. //release chip. //send LSByte address data = spi_transfer(0xFF). pinMode(DATAIN. signal end transfer return data. INPUT). byte clr.spi_transfer(READ).I++) { buffer[I]=I. //transmit read opcode spi_transfer((char)(EEPROM_address>>8)).clk low when idle. . //fill buffer with data fill_buffer(). digitalWrite(SLAVESELECT. OUTPUT). pinMode(SLAVESELECT. void fill_buffer() { for (int I=0.HIGH). // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }.spi enabled. pinMode(DATAOUT. clr=SPSR.OUTPUT). } } char spi_transfer(volatile char data) { SPDR = data. delay(10). pinMode(SPICLOCK. //data buffer char buffer [128]. int address=0. return SPDR. clr=SPDR.master.

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

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. For an explanation of SPI see the SPI EEPROM tutorial.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). 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. Example applications include LED dimming.

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.The AD5206 is a 6 channel digital potentiometer. 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. This means it has six variable resistors (potentiometers) built in for individual electronic control. pulling another side pin (pin A) low and taking the variable voltage output of the center pin (Wiper). . B1 and W1. Bx and Wx. There are three pins on the chip for each of the six internal variable resistors. A1. 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. The device is enabled by pulling the Chip Select (CS) pin low. ie. Data is shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. For example. The individual variable resistor pins are labeled Ax. and the interface runs much faster than the Arduino. The AD5206 is digitally controlled using SPI.

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

HIGH). This program will sequentially pulse each LED on and then fade it out gradually. pinMode(DATAIN. 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 .OUTPUT). the seventh bit enables the SPI. clr=SPSR. Although we are not reading any data back out of the AD5206 in this program. 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. DATAOUT.Program the Arduino Now we will write the code to enable SPI control of the AD5206. First we set our input and output pin modes and set the SLAVESELECT line high to start. byte resistance=0. . clr=SPDR. 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. the third bit sets the SPI to sample data on the rising edge of the data clock. pinMode(DATAOUT. This deselects the device and avoids any false transmission messages due to line noise: void setup() { byte clr. //disable device Now we set the SPI Control register (SPCR) to the binary value 01010000. INPUT).not used. DATAIN.OUTPUT). SPICLOCK and SLAVESELECT. We define the pins we will be using for our SPI connection. pinMode(SPICLOCK. We will walk through the code in small sections. the fourth bit sets the data clock idle when it is low. In the control register each bit sets a different functionality. digitalWrite(SLAVESELECT. 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). OUTPUT). the fifth bit puts the Arduino in Master mode. pinMode(SLAVESELECT. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). the sixth bit chooses transmission with the most significant bit going first. The eighth bit disables the SPI interrupt.

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

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

.

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. 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. low or “high impedance.begin() function which relies on the sender and the receiver to be set independently to an agreed upon specified data rate. that you delineate between bits.” Unlike the HIGH and LOW states. serial or parallel-out shift register with output latches. This is a pretty specialized thing to do -. Neither example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. 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’t set pins to their high impedance state individually. 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. Here is a table explaining the pin-outs adapted from the Phillip's datasheet.) How this all works is through something called “synchronous serial communication. 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. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. . This is in contrast to using the “asynchronous serial communication” of the Serial. the clock pin.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. active low Shift register clock pin Storage register clock pin (latch pin) Output enable. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. Vss Serial Out Master Reclear. You can only set the whole chip together. You can learn to do that from the second example. 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. It's by pulsing second pin.e. This is the “parallel output” part. “3 states” refers to the fact that you can set the output pins as either high. (Users may also wish to search for other driver chips with "595" or "596" in their part numbers. there are many. The STP16C596 for example will drive 16 LED's and eliminates the series resistors with built-in constant current sources.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 example is based on the 74HC595.” In other words. 3-state.” i. 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. The datasheet refers to the 74HC595 as an “8-bit serial-in.

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 clockPin and the latchPin respectively. 2. 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 Circuit 1. . Turning it on Make the following connections: GND (pin 8) to ground. You can get around this by controlling the MR and OE pins from your Arduino board too.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. 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. but this way will work and leave you with more open pins. Notice the 0.

3. 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. putting the anodes directly to power and the cathodes (ground pins) to the shift register outputs. If you have one of those it means you will have to flip the direction of the LEDs. Some shift registers can't source current. Add 8 LEDs. Using the shift register to supply power like this is called sourcing current. they can only do what is called sinking current. 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. Circuit Diagram .

The second program lights one LED at a time. As the data gets shifted in it is saved in an internal memory register. the shift register reads the state of the data pin.1 – Hello World Code Sample 1. lighting the LEDs. The logic table is what tells you that basically everything important happens on an up beat. The third cycles through an array. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. 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. Code Sample 1.2 – One by One . 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 Code Here are three code examples.

Starting from the previous example. Connect the 2 registers. . It should have the same leads to power and ground. The Circuit 1.3 – from Defined Array Example 2 In this example you’ll add a second shift register.Code Sample 1. 2. Add a second shift register. you should put a second shift register on the board. 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. doubling the number of output pins you have while still using the same number of pins from the Arduino. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires).

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

Circuit Diagram .

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

shiftOut(dataPin. clockPin. dataArrayGREEN defined up front.2. dataArrayRED. Edit Page | Page History | Printable View | All Recent Site Changes . This means that line data = dataArray[j].3's big difference from sample 1. becomes dataRED = dataArrayRED[j]. sample 2.3 also takes advantage of the new blinkAll_2bytes() function. dataGREEN = dataArrayGREEN[j]. dataRED). becomes shiftOut(dataPin. 2. and shiftOut(dataPin. data). 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.Like sample 2. clockPin. a dataGREEN. dataGREEN).

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

com Edit Page | Page History | Printable View | All Recent Site Changes .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.igoe at gmail.

h> void setup() { // write a 0 to all 512 bytes of the EEPROM for (int i = 0. // turn the LED on when we're done digitalWrite(13.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. 0).write(i. i++) EEPROM. Code #include <EEPROM. HIGH). } void loop() { } See also EEPROM Read example EEPROM Write example EEPROM library reference Edit Page | Page History | Printable View | All Recent Site Changes . i < 512.

Serial. Code #include <EEPROM. Serial. so if we're // on address 512. } void loop() { // read a byte from the current address of the EEPROM value = EEPROM.print(address). delay(500). byte value. // advance to the next address of the EEPROM address = address + 1. void setup() { Serial.print("\t").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. Serial. // there are only 512 bytes of EEPROM.println(). DEC). Serial.h> // start reading from the first byte (address 0) of the EEPROM int address = 0. wrap around to address 0 if (address == 512) address = 0.begin(9600).print(value. from 0 to 511. } See also EEPROM Clear example EEPROM Write example EEPROM library reference Edit Page | Page History | Printable View | All Recent Site Changes .read(address).

h> // the current address in the EEPROM (i. addr = addr + 1.write(addr.e. } See also EEPROM Clear example EEPROM Read example EEPROM library reference Edit Page | Page History | Printable View | All Recent Site Changes . so go back to 0 when we hit 512. // these values will remain there when the board is // turned off. delay(100). EEPROM. // advance to the next address. 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. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch. val). there are 512 bytes in // the EEPROM. which byte // we're going to write to next) int addr = 0. int val = analogRead(0) / 4.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. if (addr == 512) addr = 0. Code #include <EEPROM.

8. using one of the circuits on the linked pages.h> // change this to the number of steps on your motor #define STEPS 100 // create an instance of the stepper class. } void loop() { // get the sensor value int val = analogRead(0). 11). 9. and 11. } See also Stepper library reference Edit Page | Page History | Printable View | All Recent Site Changes . The unipolar or bipolar stepper is controlled with pins 8. 10. // the previous reading from the analog input int previous = 0.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. 10.setSpeed(30). Code #include <Stepper.step(val . 9. // move a number of steps equal to the change in the // sensor reading stepper. // remember the previous value of the sensor previous = val. specifying // the number of steps of the motor and the pins it's // attached to Stepper stepper(STEPS. void setup() { // set the speed of the motor to 30 RPMs stepper.

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

at 09:22 PM by David A. Mellis Changed line 15 from: BlinkWithoutDelay: blinking an LED without using the delay() function. Mellis . to: Blink Without Delay: blinking an LED without using the delay() function. The code is included in the tutorial. to: These are more complex examples for using particular electronic components or accomplishing specific tasks. The code is included on the page. 2008. to: Arduino Examples See the foundations page for in-depth description of core concepts of the Arduino hardware and software. 2008.moving the resources to the links page. Restore April 29. Added line 15: BlinkWithoutDelay: blinking an LED without using the delay() function.EEPROM Library EEPROM Clear: clear the bytes in the EEPROM. 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. 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. Deleted lines 43-44: Added lines 49-51: Timing & Millis Stopwatch Deleted lines 75-125: . and the links page for other documentation. For instructions on getting the board and environment up and running. EEPROM Write: stores values from an analog input to the EEPROM. EEPROM Read: read the EEPROM and send its values to the computer. see the Arduino Getting Started. at 06:55 PM by David A.

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

at 07:20 PM by David A. 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. 2008. 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. 2008. 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. Mellis Changed lines 73-78 from: Foundations has moved here Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches.(:if false:) Changed line 41 from: to: (:ifend:) Restore April 22. to: See the foundations page for explanations of the concepts involved in the Arduino hardware and software. 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 08:23 PM by David A. 2008. 2008. 2008. at 09:26 PM by Paul Badger Changed lines 73-75 from: to: . Mellis .moving TwoSwitchesOnePin to "other examples" since it's not (yet) in the distribution. at 08:22 PM by David A. Restore March 07.

Foundations has moved here Restore March 07. 2008. For instructions on getting the board and environment up and running. 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.) Serial Communication?: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs. 2008. 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. 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. Optimization?: What to do when your program runs too slowly. Mellis Changed lines 72-73 from: Tutorials to: Foundations Changed lines 108-109 from: More Tutorials to: Tutorials Restore February 13. 2008. SPI. at 09:24 PM by Paul Badger Changed lines 74-107 from: Memory: The various types of memory available on the Arduino board. see the Arduino guide. I2C. Numbers?: The various types of numbers available and how to use them. Interrupts?: Code that interrupts other code under certain conditions. Midi. Variables: How to define and use variables. . (:ifend:) to: Restore March 07. etc. Pointers?: Functions?: How to write and call functions. at 09:09 PM by Paul Badger Added lines 80-81: Foundations Restore February 15. 2008. Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins.

I2C. at 09:30 PM by David A. 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. For instructions on getting the board and environment up and running. at 09:58 PM by David A. (: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. Interrupts?: Code that interrupts other code under certain conditions. Mellis Added lines 90-99: Numbers?: The various types of numbers available and how to use them. Restore February 13. Mellis Restore February 13. Variables: How to define and use variables. at 09:41 PM by David A. Arrays?: How to store multiple values of the same type. 2008. Debugging?: Figuring out what's wrong with your hardware or software and how to fix it. Restore February 13. etc. 2008. Mellis Changed lines 80-81 from: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. Restore February 13. .) Serial Communication?: How to send serial data from an Arduino board to a computer or other device. at 09:31 PM by David A. Mellis Added lines 80-81: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. 2008. Pointers?: Functions?: How to write and call functions. at 09:36 PM by David A. Restore February 13. Restore February 13. to: Serial Communication?: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). 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. at 10:06 PM by David A. 2008. 2008. SPI. Midi. at 09:38 PM by David A. see the Arduino Getting Started. to: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. 2008. Mellis Added lines 100-103: Optimization?: What to do when your program runs too slowly.

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

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

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

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 .

at 06:59 PM by Paul Badger Added line 39: More sound ideas Restore April 24.cc/cgi-bin/yabb2/YaBB. 2007. 2007. 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. at 02:52 PM by Carlyn Maw Changed lines 52-54 from: Multiple digital ins with a CD4021 Shift Register to: Restore .LED as light sensor (en Francais) Arduino and the Asuro robot Using Arduino from the command line Restore May 11.cc/cgi-bin/yabb2/YaBB.pl?num=1171076259 |Use a couple of Arduino pins as a capacitive sensor]] Restore May 10. 2007.cc/cgi-bin/yabb2/YaBB.pl?num=1171076259 Use a couple of Arduino pins as a capacitive sensor Restore May 10. at 07:05 PM by Paul Badger Changed lines 36-37 from: http://www. at 07:07 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.arduino. 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.arduino. 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 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. 2007.arduino. 2007.arduino.pl?num=1171076259 Use a couple of Arduino pins as a capacitive sensor to: http://www. 2007.

Mellis Deleted line 46: Build your own DMX Master device Restore December 25. 2007. Mellis Added line 64: Arduino + MaxMSP Changed lines 67-68 from: to: Arduino + Ruby Restore November 18. 2006. at 10:43 AM by David A. at 11:57 PM by David A. at 10:49 AM by David A. at 03:37 PM by David A. 2006. at 06:04 AM by David A. Changed lines 69-70 from: to: Arduino + C Restore December 02. 2006. 2006.February 06.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. Mellis Added line 20: Using a pushbutton as a switch Restore December 07. Mellis . at 02:51 PM by Carlyn Maw Changed lines 52-53 from: to: Multiple digital ins with a CD4021 Shift Register Restore January 30. 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 Deleted line 53: . at 02:42 AM by David A. 2006. Mellis Added line 1: (:title Tutorials:) Restore November 21. at 10:13 AM by David A. 2007. 2006. at 12:25 PM 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. 2006.

to: Example labs from ITP Examples from Tom Igoe. see the Arduino guide?. or is there something you would like to see published in this site? Refer to the forum for further help. 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. For instructions on getting the board and environment up and running. 2006. Restore November 04. see the Arduino guide. 2006. 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. 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. Examples from Jeff Gray. Restore November 04. . at 12:24 PM 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. 2006. at 12:23 PM by David A. see the examples from Tom Igoe and those from Jeff Gray. Mellis Changed lines 50-51 from: Example labs from ITP to: Changed lines 77-78 from: Also. at 10:38 AM by David A. 2006. For instructions on getting the board and environment up and running. Restore November 04. at 12:24 PM by David A.Deleted line 54: Restore November 04.

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

adding links to todbot's class notes. at 05:46 PM by David A. at 12:52 PM by David A. illustrated tutorials from his Spooky Projects course: class 1 (getting started). 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. 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. class 3 (communication. 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 22. For instructions on getting the board and environment up and running. For instructions on getting the board and IDE up and running. at 12:51 PM by David A. at 05:45 PM by David A. illustrated tutorials from his Spooky Projects course: class 1 (getting started). to: This guide to the Arduino IDE (integrated development environment) explains the functions of the various buttons and menus. Restore October 08. Mellis Changed lines 59-62 from: This guide to the Arduino IDE? (integrated development environment) explains the functions of the various buttons and menus. Added lines 66-68: Course Guides todbot has some very detailed. and pwm). class 2 (input and sensors). 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 . The libraries page explains how to use libraries in your sketches and how to make your own. 2006. see the Howto. 2006. The libraries? page explains how to use libraries in your sketches and how to make your own. servos. 2006. Restore October 08. class 2 (input and sensors). to: todbot has some very detailed. see the Howto?. class 2 (input and sensors). illustrated tutorials from his Spooky Projects course: class 1 (getting started). see the Howto. 2006. 2006. Restore October 08. Restore October 21. at 05:38 PM by David A. For instructions on getting the board and IDE up and running. at 04:25 PM by David A. 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. Restore October 22. 2006. Mellis . Mellis Changed lines 67-68 from: todbot has some very detailed. For instructions on getting the board and IDE up and running.

(: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). .with it. The Arduino environment This guide to the Arduino IDE? (integrated development environment) explains the functions of the various buttons and menus. For instructions on getting the board and IDE up and running. see the Howto?. 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. The libraries? page explains how to use libraries in your sketches and how to make your own.

(:tableend:) Restore Edit Page | Page History | Printable View | All Recent Site Changes . hack a day has links to interesting hacks and how-to articles on various topics. Thanks to Pollie Barden for the great videos. or is there something you would like to see published in this site? Refer to the forum for further help.Video Lectures by Tom Igoe Watch Tom introduce Arduino. 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. see the examples from Tom Igoe and those from Jeff Gray. Do you need extra help? Is there a sensor you would like to see characterized for Arduino. External Resources Instant Soup is an introduction to electronics through a series of beautifully-documented fun projects. Make magazine has some great links in its electronics archive.

Graph: sending data to the computer and graphing it in Processing. Virtual Color Mixer: sending multiple variables from Arduino to the computer and reading them in Processing. 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. Debounce: read a pushbutton. Smoothing: smooth multiple readings of an analog Sound input. see processing. and the links page for other documentation. Communication These examples include code that allows the Arduino to talk to Processing sketches running on the computer. ASCII Table: demonstrates Arduino's advanced serial output functions. For more information or to download Processing. to open them.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. 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. Reading Knock: detect knocks with a piezo element. filtering noise. Loop: controlling multiple LEDs with a loop and an array. 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 . click the Open button on the toolbar and look in the examples folder. Dimmer: move the mouse to change the brightness of an LED.) Other Examples These are more complex examples for using particular electronic components or accomplishing specific tasks. 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).org. check the Arduino 0007 tutorials page. Examples Simple programs that demonstrate the use of the Arduino board. The code is included on the page. Blink Without Delay: blinking an LED without using the delay() function. 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. Read an Fading: uses an analog output (PWM pin) to fade sensor) an LED. These are included with the Arduino environment. (If you're looking for an older example. Button: use a pushbutton to control an LED.

EEPROM Library 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.arduino. (Printable View of http://www. 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.cc/en/Tutorial/HomePage) .

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. or if you have other suggestions. Foundations Page Edit Page | Page History | Printable View | All Recent Site Changes . Also. providing a single source for people looking for a longer discussion of a particular topic. feel free to take a shot at writing it up. current. 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. be sure to let us know if you think there's anything that we've forgotten. providing more in-depth explanations of the underlying functionality and principles involved. and there are many topics yet to be covered.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. These pages are cross-linked with the applicable language reference. This section is a work in progress. You can post works-in-progress to the playground and mention them on the forum. example. Don't worry if it's not finished or polished. and other pages.

the line from the Blink sketch above declares a variable with the name ledPin . and so on.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. Linux). * then off for one second. It's the unit of code that is uploaded to and run on an Arduino board. In this tutorial. Mac OS X. // LED connected to digital pin 13 the message "LED connected to digital pin 13" is a comment. how it works. It's a good practice to comment your sketches. single-line comments.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. you could store the value read from an input into a variable. 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. Turns on an LED on for one second. This helps other people to learn from or modify your code. the value of a variable will change while the sketch runs. In this case. its value will be retrieved. and isn't required). There's another style for short. Variables A variable is a place for storing a piece of data. These start with // and continue to the end of the line. it has either a built-in LED * or a built-in resistor so that you need only an LED. you uploaded a sketch that blinks an LED. For example.arduino. here's the definition of the setup() function from the Blink example: void setup() { . Often. 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. a type. For example. and a value. Sketch A sketch is the name that Arduino uses for a program. 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. and to keep the comments up-to-date when you modify the code. There's more information in the Variables tutorial. however. or why it's written the way it is. you'll learn how each part of that sketch works.. in the line: int ledPin = 13.. the type int. * * http://www. For example. Every time the name ledPin appears in the code. We use pin 13 because. * depending on your Arduino board. It's being used to indicate which Arduino pin the LED is connected to. Comments The first few lines of the Blink sketch are a comment: /* * Blink * * The basic Arduino example. It has a name. and an initial value of 13. For example. It's there for people reading the code: to explain what the program does.

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

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

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

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

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

puts 32 bytes into SRAM (each character takes a byte). for example. use the smallest data type necessary to store the values you need. reducing the load on the Arduino. 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. for example. If you have lookup tables or other large arrays. If you don't need to modify the strings or data while your sketch is running.". This might not seem like a lot. It's easy to use it all up by having lots of strings in your program. For example. while a byte uses only one (but can store a smaller range of values). but not run. To check if this is happening. you can try commenting out or shortening the strings or other data structures in your sketch (without changing the code). Flash memory and EEPROM memory are non-volatile (the information persists after the power is turned off). use the PROGMEM keyword. SRAM (static random access memory) is where the sketch creates and manipulates variables when it runs. to do this. To use the EEPROM. but it doesn't take long to get to 1024.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). If you run out of SRAM. is where the Arduino sketch is stored. you can try shifting data or calculations to the computer. an int takes up two bytes. SRAM is volatile and will be lost when the power is cycled. your program may fail in unexpected ways. you're probably running out of SRAM. If it then runs successfully. see the EEPROM library. or run strangely. 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. it will appear to upload successfully. you can store them in flash (program) memory instead of SRAM. Foundations Edit Page | Page History | Printable View | All Recent Site Changes . EEPROM is memory space that programmers can use to store long-term information. or a large lookup table. especially if you have a large amount of text to send to a display. a declaration like: char message[] = "I support the Cape Wind project.

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

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

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

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

2008. 2008. 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. Added line 27: Restore April 06. 2008. at 07:27 AM by Paul Badger Changed lines 51-52 from: GroupHead to: GroupHead Restore April 29. at 05:57 PM by Paul Badger Restore April 10. 2008. 2008. at 06:20 AM by Paul Badger Added lines 3-5: Reference Restore March 21. 2008. at 07:26 AM by Paul Badger Added lines 51-52: GroupHead Restore April 22. 2008. 2008.Restore April 29. at 07:28 AM by Paul Badger Changed lines 51-52 from: GroupHead to: Restore April 29. 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. Mellis . at 09:44 AM by David A. 2008. at 06:27 PM by Paul Badger Changed lines 13-14 from: Arduino Software . at 06:23 AM by Paul Badger Changed lines 1-4 from: Reference | Reference| Extended Reference to: Reference | Extended Reference Restore March 31. 2008.adding pwm tutorial Added lines 16-17: PWM: How the analogWrite() function simulates an analog output using pulse-width modulation.

to: Arduino Firmware Restore March 09. 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. 2008. at 11:11 PM by Paul Badger Changed lines 5-6 from: Chip Hardware to: Chip Level Documentation and Techniques Restore March 09. at 10:49 PM by Paul Badger Added lines 13-14: 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. . at 11:09 PM by Paul Badger Changed lines 5-6 from: Hardware to: Chip Hardware Restore March 09. 2008. 2008. 2008. at 10:48 PM by Paul Badger Deleted lines 6-7: Memory: The various types of memory available on the Arduino board. 2008. 2008. at 10:49 PM by Paul Badger Changed lines 13-14 from: Arduino Software to: Arduino Software Restore March 09.

Added lines 11-12: Memory: The various types of memory available on the Arduino board. at 09:25 PM by Paul Badger Changed lines 11-12 from: Foundations to: Restore March 07. 2008. 2008. at 09:24 PM by Paul Badger Changed lines 3-37 from: . 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. Deleted lines 25-26: Variables: How to define and use variables. 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. 2008. at 07:16 PM by David A. Mellis Changed lines 11-12 from: to: Variables: How to define and use variables. 2008. Page Discussion Restore March 07. Page Discussion Added lines 11-12: Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. Restore March 09. 2008. Page Discussion to: This page contains explanations of some of the elements of the Arduino hardware and software and the concepts behind them. at 10:47 PM by Paul Badger Added lines 5-6: Hardware Added lines 15-16: Programming Restore March 09. 2008. 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. Restore March 07. at 07:19 PM by David A.

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

Microcontrollers Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs. PWM: How the analogWrite() function simulates an analog output using pulse-width modulation.arduino. Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. Arduino Firmware Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. Port Manipulation: Manipulating ports directly for faster manipulation of multiple pins (Printable View of http://www. Programming Technique Variables: How to define and use variables.cc/en/Tutorial/Foundations) .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. Memory: The various types of memory available on the Arduino board. 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 .

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

communication. digital inputs. input / output. variables. and basic RGB color-mixing Lesson 4: The serial library and binary data . etc. using Arduino. resistors and LEDs. By ladyada.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. procedures and hacking code Lesson 3: Breadboards.Is your Arduino and computer ready? Lesson 1: The "Hello World!" of electronics.. Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino.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. pull-up and pull-down resistors.. (:cell width=50%:) Deleted lines 66-86: (:cell width=50%:) Books and Manuals . a simple blinking light Lesson 2: Sketches. Lesson 0: Pre-flight check. if/if-else statements. debouncing and your first contract product design. schematics. Learn electronics using Arduino: an introduction to programming.

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

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

2008. 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. Changed lines 60-73 from: Example labs from ITP . this one focusing on physical sensing and making motion.with one another by forming networks of smart devices that carry on conversations with you and your environment. arduino+processing. 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. stand-alone operation) Bionic Arduino: another Arduino class from TodBot. servos. 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. Curricula. Restore May 06. and pwm) (piezo sound & sensors. Examples from Tom Igoe Examples from Jeff Gray Changed lines 45-47 from: Manuals.

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

if/if-else statements. and pwm) (piezo sound & sensors. this one focusing on physical sensing and making motion. procedures and hacking code Lesson 3: Breadboards. debouncing and your first contract product design.Lesson 2: Sketches. Examples from Tom Igoe Examples from Jeff Gray Restore Edit Page | Page History | Printable View | All Recent Site Changes . 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. servos. and basic RGB color-mixing Lesson 4: The serial library and binary data . resistors and LEDs. digital inputs. arduino+processing. stand-alone operation) Bionic Arduino: another Arduino class from TodBot. schematics.getting chatty with Arduino and crunching numbers Lesson 5: Buttons & switches. pull-up and pull-down resistors.

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

sensors. Examples from Tom Igoe Examples from Jeff Gray (Printable View of http://www. stand-alone operation) Bionic Arduino: another Arduino class from TodBot. microcontrollers. actuators. etc.cc/en/Tutorial/Links) . Schematics to circuits: from Wiring. Wiring electronics reference: circuit diagrams for connecting a variety of basic electronic components. arduino+processing. books. 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. and pwm) class 4 (piezo sound & sensors.arduino. a guide to transforming circuit diagrams into physical circuits.Tom Igoe's Physical Computing Site: lots of information on electronics. this one focusing on physical sensing and making motion. servos.

in intervals of 2 seconds.0j0. LEDs have polarity. 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. Arduino doesn't have any pre-established output devices.de based on an orginal by H.berlios. credits are to be found in the comments. As a microcontroller. 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. Barragan for the Wiring i/o board . and should connect to pin 13. Code The example code is very simple. Ideally we use pin 13 on the Arduino board because it has a resistor attached to it. The long leg is typically positive. 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. The short leg connects to GND. If the LED doesn't light up. which means they will only light up if you orient the legs properly.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. needing only an LED Created 1 June 2005 copyleft 2005 DojoDave <http://www.org> http://arduino. what allows the immediate connection of a LED between that pin and ground. Willing to provide newcomers with some help while debugging programs.

} void loop() { digitalWrite(ledPin. OUTPUT). 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 . void setup() { pinMode(ledPin. digitalWrite(ledPin. LOW). HIGH).*/ int ledPin = 13. delay(1000).

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

greenVal).print("R:").print("\t"). Serial. // Print red value Serial.print(redVal). blueVal).println(blueVal).print(i). // 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. // Reset the counter Serial.print("\t"). Serial. Serial. and start the fades again { i = 1. // println.print("G:"). redVal).. // Print a tab Serial. } analogWrite(redPin.print("B:"). // Write current values to LED pins analogWrite(greenPin. // Print a tab Serial. // Repeat for green and blue. // Indicate that output is red value Serial.print("\t"). to end with a carriage return } } delay(wait).blueVal -= 1. if (DEBUG) { // If we want to read the output DEBUG += 1.print(greenVal).. Serial. // Serial commands in 0004 style Serial. // Increment the DEBUG counter if (DEBUG > 10) // Print every 10 loops { DEBUG = 1.

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

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

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

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

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. The second example shows how to use a for(. Aaron Hallborg */ . The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. The first code example will make the LEDs blink in a sequence. it would be interesting to use the Knight Rider as a metaphor. Malmo University * @author: David Cuartielles * @hardware: David Cuartielles. Thus we decided that in order to learn more about sequential programming and good programming techniques for the I/O board.HIGH/LOW) and delay(time). Example for Hasselhoff's fans Knight Rider 1 /* Knight Rider 1 * -------------* * Basically an extension of Blink_LED.7 on the board using 220 Ohm resistors. The third and last example concentrates in the visual effect of turning the LEDs on/off in a more softer way. This example makes use of 6 LEDs connected to the pins 2 . * * * (cleft) 2005 K3. one by one using only digitalWrite(pinNum.) construction to perform the very same thing. but in fewer lines..

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

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

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

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. You will be able to controle how fast the 'star' shoots. through a 220 Ohm resistance (see image above). and in the end it seems like a solid ray that crosses the LED line. or more poetically a Shooting Star. 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" . Of course you can increase the number of LEDs using an LED driver (see tutorial) and therefore. allow longer tails. go through a line of LEDs. and how long its 'tail' is. The program starts lighting up LEDs until it reaches the number of LEDs equal to the size you have stablished for the tail.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. It isn't very elegant because the tail is as bright as the star. to make sure we see the tail (otherwise we would just light up the whole line of leds. and will start erasing from the right. 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.

} } // Main loop void loop() { int i. for (i=0. i<lineSize. i++) { pinMode(pinArray[i]. // This time variable controles how fast I light them upm. 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. lineSize = 11. // I make sure I enter the loop indicating it with this LED for (i=0.5. // I set up the tail length in a counter digitalWrite(controlLed.LOW).HIGH).9.8. i++) { digitalWrite(pinArray[i].11. controlLed = 13.* * 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. HIGH). i< lineSize. // This time variable controles how fast I light them up if (tailCounter == 0) { digitalWrite(pinArray[i-tailLength].3. } for (i=(lineSize-tailLength). pinMode (controlLed.4. // I turn off the LEDs depending on my tailLength } else if (tailCounter > 0) tailCounter--.6.LOW). // 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.Rennes .12 }.10.France . i++) { digitalWrite(pinArray[i]. // I light up consecutively the LEDs delay(waitNextLed). OUTPUT). tailLength = 4. OUTPUT). int tailCounter = tailLength. waitNextLed = 100. and turn off as well } } @idea: Cristina Hoffmann @code: Cristina Hoffmann @pictures and graphics: Cristina Hoffmann @date: 20060203 . i<lineSize.7. // I turn off the LEDs delay(waitNextLed).

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

so the pin is connected to 5 volts (through the pull-up resistor) and we read a HIGH. When the button is closed (pressed). when pressing a pushbutton attached to pin 7.org> * http://arduino.) /* Basic Digital Read * -----------------* * turns on and off a light emitting diode(LED) connected to digital * pin 13. The second goes from the corresponding leg of the pushbutton to ground. so that we read a LOW.de * */ int ledPin = 13. It illustrates the * concept of Active-Low. The example turns on an LED when you press the button.berlios.2 KOhms) to the 5 volt supply. // choose the pin for the LED int inPin = 7. The first goes from one leg of the pushbutton through a pull-up resistor (here 2. but the resistor in-between them means that the pin is "closer" to ground. connecting the pin to ground. * * 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. We connect three wires to the Arduino board. (The pin is still connected to 5 volts. When the pushbutton is open (unpressed) there is no connection between the two legs of the pushbutton. // choose the input pin (for a pushbutton) int val = 0. which consists in connecting buttons using a * 1K to 10K pull-up resistor. 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.0j0. // variable for reading the pin status .

OUTPUT). INPUT). } else { digitalWrite(ledPin. HIGH). pinMode(inPin.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 . } // declare LED as output // declare pushbutton as input void loop(){ val = digitalRead(inPin). LOW). // if (val == HIGH) { // digitalWrite(ledPin.

without which pressing the button once would appear to the code as multiple presses. the output pin is toggled from LOW to HIGH or HIGH to LOW. because of a push-button * press). // 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 state = HIGH. Code /* switch * * Each time the input pin goes from LOW to HIGH (e. int outPin = 13. to ignore * noise).e. Mellis * 21 November 2006 */ int inPin = 2. There's * a minimum delay between toggles to debounce the circuit (i. int previous = LOW. Circuit A push-button on pin 2 and an LED on pin 13.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 LED (or whatever) is turned on (if it's off) or off (if on). int reading. measured in miliseconds. . * * David A.g. It also debounces the input.

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

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

delay(val). digitalWrite(ledPin. HIGH). // 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. int val = 0. } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin). OUTPUT). LOW). digitalWrite(ledPin.int potPin = 2. } // // // // // 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 . int ledPin = 13. delay(val).

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

0j0. The kind of program that we need to monitor the joystick has to make a polling to two of the analog pins. Potentiometers are variable resistors and. they act as sensors providing us with a variable voltage depending on the rotation of the device around its shaft. OUTPUT). This allows to easily send the information into e. joyPin2 = 1. in a way. 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. We can send these values back to the computer.de * copyleft 2005 DojoDave for DojoCorp */ int int int int int ledPin = 13.org | http://arduino. /* 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. but then we face the classic problem that the transmission over the communication port has to be made with 8bit values. Finally we make the LED blink with the values read from the sensors as a direct visual feedback of how we control the joystick. value1 = 0. while our DAC (Digital to Analog Converter . value2 = 0. Flash and parse it inside your own code.that is messuring the values from the potentiometers in the joystick) has a resolution of 10bits.g. In other words this means that our sensors are characterized with a value between 0 and 1024.berlios. beginSerial(9600). // // // // 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. this will take the form: * Jxy\r\n * * x and y are integers and sent in ASCII * * http://www.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. } int treatValue(int data) { // initializes digital pins 0 to 7 as outputs . joyPin1 = 0.

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

We connect the black one to ground and the red one to the input. it will send the string "Knock!" back to the computer over the serial port. In the case of the Arduino boards. In order to see this text you could either use a terminal program. and not just a plain HIGH or LOW. 0 represents 0volts. We are taking advantage of the processors capability to read analog signals through its ADC . The code example will capture the knock and if it is stronger than a certain threshold.analog to digital converter. commercial devices are usually having a red and a black wires indicating how to plug it to the board.1024. we transform the voltage into a value in the range 0. In our example we are plugging the Piezo on the analog input pin number 0. then they will just look like a metallic disc and are easier to use as input sensors. Example of connection of a Piezo to analog pin 0 with a resistor /* Knock Sensor * ---------------* . Sometimes it is possible to acquire Piezo elements without a plastic housing.. The other thing to remember is that Piezos have polarity. while 1024 represents 5volts at the input of one of the six analog pins. which will read data from the serial port and show it in a window. or make your own program in e. A Piezo is nothing but an electronic device that can both be used to play tones and to detect tones. Processing. that supports the functionality of reading a value between 0 and 5volts. 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.g. 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. We also have to connect a resistor in the range of the Megaohms in parallel to the Piezo element.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.

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

// 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. } else { val = 0.read()).length()-1).substring(1.available() > 0) { serialEvent(port. } void serialEvent(int serial) { if(serial != NEWLINE) { buff += char(serial). "COMXX". } background(val). } } // <-. 9600). buff. // Open your serial port port = new Serial(this. 200). // Clear the value of "buff" buff = "". } else { buff = buff. } println(buff).SUBSTITUTE COMXX with your serial port name!! Edit Page | Page History | Printable View | All Recent Site Changes .void setup() { size(200. } void draw() { // Process each one of the serial port events while (port.

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

// Print a tab Serial.print("G:"). grnVal). analogWrite(grnPin..println(bluVal). if (DEBUG > 100) { DEBUG = 1. // Red off grnVal = 256 .potVal. // Red from off to full grnVal = 1.. // Blue from full to off } analogWrite(redPin. // Repeat for grn and blu. to end with a carriage return } } } Edit Page | Page History | Printable View | All Recent Site Changes . redVal).print("\t").redVal = 1. Serial. analogWrite(bluPin. // println. // Indicate that output is red value Serial. if (DEBUG) { // If DEBUG += 1.print(grnVal). // Green from full to off bluVal = potVal. // Normalize to 0-255 redVal = potVal.print("R:"). // Print red value Serial.print("B:"). // Blue from off to full } else // Upper third of potentiometer"s range (682-1023) { potVal = ( (potVal-683) * 3) / 4.potVal. bluVal).print(redVal). // 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. Serial. // Green off bluVal = 256 . Serial.print("\t"). Serial.

An example of a parallel to serial register is the CD4021B. For each of the inputs I’m expecting. like hearing a musical cord.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. This is called Asynchronous Parallel Input.Clock Data from Arduino |_____| <.” The third pin attached to the Arduino is a “Parallel to Serial Control” pin. sometimes referred to as an “8-Stage Static Shift Register. Make sure the register has the latest information from its parallel inputs (i. “Asynchronous” because the CD4021B is doing all this data collection at its own pace without coordinating with the Arduino. 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. 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. “Input” because you are collecting information.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. that the latch pin is HIGH) 2. is heavily reliant on what is referred to as a clock pin. When the latch pin is HIGH the shift register is listening to its 8 parallel ins.” This means you can read the state of up to 8 digital inputs attached to the register all at once.” The clock pin is the metronome of the conversation between the shift register and the Arduino. You can keep extending this daisy-chain of shift registers until you have all the inputs you need. _______ | | | C | | D | | 4 | -> Serial Data to Arduino | 0 | | 2 | | 1 | <. pulse the clockPin and then check to see if the data pin is low or high This is a basic diagram. _______ . Tell the register that I’m ready to get the information serially (latch pin LOW) 3. That means every time the latch pin transitions from HIGH to LOW the shift register will start passing its most current switch information. When it is LOW it is listening to the clock pin and passing information serially. referred to as the data pin. “Parallel” because it is all at once. 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. within reason. 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. 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. That is what makes it “synchronous. input or output. You can think of it as a latch pin. The second example will cover this situation. 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. This pin should be connected to an input pin on your Arduino Board. Synchronous Serial communication. The pseudo code to coordinate this all looks something like this: 1. '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.e.

and before you start wiring up your board here is the pin diagram of the CD4021 from the Texas Instruments Datasheet PINS 1. Power Connections Make the following connections: GND (pin 8) to ground. Q8 is the only one used in these examples. Q7.Latch Data from Arduino |_____| There is more information about shifting in the ShiftOut tutorial. 12. The Circuit 1. 3 PIN 8 PIN 9 PIN 10 PIN 11 PIN 16 P1 – P8 (Pins 07) Parallel Inputs Q6.switch switch switch switch switch switch switch switch -> -> -> -> -> -> -> -> | | | C | | D | | 4 | | 0 | | 2 | | 1 | |_____| -> Serial Data to Arduino <.Clock Data from Arduino <.47. VDD (pin 16) to 5V . 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.Clock Data from Arduino | 1 | <.Latch Data from Arduino <-----| | | | Serial Data Passed to First | Shift Register | | ______| switch switch switch switch switch switch switch switch -> -> -> -> -> -> -> -> _______ | | | C | | D | | 4 | | 0 | | 2 | <. Q8 Serial Output Pins from different steps in the sequence. 1315 PINS 2. Q7 is a pulse behind Q8 and Q6 is a pulse behind Q7.

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.2. the clockPin and the latchPin respectively. 3. Add 8 Switches .

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

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. doubling the number of input pins while still using the same number of pins on the Arduino. .Code Sample 1. The Circuit 1. Connect the 2 registers. 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).4 – Is it pressed? (sub-function) Example 2: Daisy Chained In this example you’ll add a second shift register.

Add a second set of Switches.3. Notice that there is one momentary switch and the rest are toggle switches. . like a preference file. rather than as event triggers. 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.

Diagram .

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

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 June 11. (: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 . Mellis . see the Arduino guide.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. at 11:10 PM by David A. For instructions on getting the board and environment up and running.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.HomePage-0007 History Hide minor edits . 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).

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. 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 . see the Arduino guide. For instructions on getting the board and environment up and running.

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. 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.cc/en/Tutorial/HomePage-0007) .

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

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.Blink to: Blinking LED Restore January 28. at 04:26 AM by David A. Mellis Changed line 21 from: * ----------to: * -----------Restore January 28. at 04:27 AM by David A. Mellis Changed line 19 from: [= to: [@ Added line 44: . 2007. 2007. Mellis Changed line 21 from: * -----------to: * ----------Deleted line 43: if (1 & 0) Restore January 28. 2007. Mellis Changed line 44 from: if (1 < 0) to: if (1 & 0) Restore January 28. at 04:27 AM by David A. at 05:06 AM by David A. 2007. at 04:27 AM by David A. 2007.

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

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

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

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

delay(1000). } (Printable View of http://www. delay(1000).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 . } void loop() { digitalWrite(ledPin. LOW).arduino. HIGH). OUTPUT). digitalWrite(ledPin.void setup() { pinMode(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 .

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

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

Here's some code that demonstrates how to blink the LED without using delay().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). (millis() . It keeps track of the last time it turned the LED on or off. // // // if check to see if it's time to blink the LED. long interval = 1000. that is. Code int ledPin = 13.cc/en/Tutorial/BlinkWithoutDelay) LED is off turn it on and vice-versa.if it has. That means you can't use delay(). long previousMillis = 0. // remember the last time we blinked the LED // if the if (value value = else value = } } (Printable View of http://www. value). Then. 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. it turns the LED off if it was on and vice-versa. int value = LOW. each time through loop() it checks if a sufficient interval has passed . OUTPUT).arduino. digitalWrite(ledPin. == LOW) HIGH. } // // // // 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. .previousMillis > interval) { previousMillis = millis(). LOW. void setup() { pinMode(ledPin. or you'd stop everything else the program while the LED blinked.

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 .

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

// choose the input pin (for a pushbutton) int val = 0.arduino. * */ int ledPin = 13. // choose the pin for the LED int inPin = 2. LOW). OUTPUT). when pressing a pushbutton attached to pin 7. pinMode(inPin. } } 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 . INPUT). HIGH).cc/en/Tutorial/Invert> * * turns on and off a light emitting diode(LED) connected to digital * pin 13. // variable for reading the pin status void setup() { pinMode(ledPin. // if (val == HIGH) { // digitalWrite(ledPin. which consists in connecting buttons using a * 1K to 10K pull-up resistor.Code /* invert * <http://www. } // declare LED as output // declare pushbutton as input void loop(){ val = digitalRead(inPin). } else { digitalWrite(ledPin. It illustrates the * concept of Active-Low.

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

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

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

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

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

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

invert the output . // the last time the output pin was toggled long debounce = 200. OUTPUT). // if we just pressed the button (i. measured in miliseconds.. Makes use of the millis() function to keep track of the time when the button is pressed. long time = 0. } void loop() { reading = digitalRead(inPin). Circuit A push-button on pin 7 and an LED on pin 13. int outPin = 13.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.. the LED (or whatever) is turned on (if it's off) or off (if on).e.time > debounce) { // . int reading. // the debounce time. It also debounces the input.. int state = HIGH. // and we've waited long enough since the last press to ignore any noise. increase if the output flickers void setup() { pinMode(inPin. the input went from LOW to HIGH). if (reading == HIGH && previous == LOW && millis() . pinMode(outPin. Code int inPin = 7. // 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. without which pressing the button once would appear to the code as multiple presses.. INPUT). int previous = LOW. // will quickly become a bigger number than can be stored in an int.

and remember when the last button press was time = millis().if (state == HIGH) state = LOW.cc/en/Tutorial/Debounce) . state). else state = HIGH. } digitalWrite(outPin. previous = reading.arduino... // . } (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 .

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

2007. digitalWrite(i. 2007. at 11:39 AM by David A. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. at 04:28 AM by David A. 2007. Mellis Changed lines 1-4 from: Examples > Digital I/O loop to: Examples > Digital I/O Loop Restore January 28. } Restore April 15. 2007. 2007. Restore January 29. HIGH). at 04:40 AM by David A. Mellis Changed lines 1-2 from: Knight Rider to: Examples > Digital I/O loop Restore January 28. Mellis - . at 05:01 AM by David A. 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. delay(timer). Mellis Changed lines 3-4 from: Loop to: Knight Rider Restore January 28. at 10:33 AM by David A. 2007. Mellis Added lines 11-12: Circuit Added lines 15-16: Code Restore January 28. 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. at 04:40 AM by David A. delay(timer).digitalWrite(i. LOW).

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

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

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

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 .

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

LOW). OUTPUT). digitalWrite(ledPin. delay(val).* a potentiometer to analog pin 2. delay(val). */ int potPin = 2. } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin). HIGH). digitalWrite(ledPin. // 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. int ledPin = 13. } // // // // // 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 . int val = 0.

that value controls the rate at which an LED blinks. The second goes from 5 volts to the other outer pin of the potentiometer. // 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. int ledPin = 13. */ int potPin = 2.org> * * Turns on and off a light emitting diode(LED) connected to digital * pin 13. giving us a different analog input. 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. there are 5 volts going to the pin and we read 1023. which we can read into the Arduino board as an analog value. The first goes to ground from one of the outer pins of the potentiometer. The amount of time the LED will be on and off depends on * the value obtained by analogRead(). In this example. By turning the shaft of the potentiometer. int val = 0. and we read 0. We connect three wires to the Arduino board.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). In the easiest case we connect * a potentiometer to analog pin 2. In between.0j0. 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. there are 0 volts going to the pin. analogRead() returns a number between 0 and 1023 that is proportional to the amount of voltage being applied to the pin. } . we change the amount of resistence on either side of the wiper which is connected to the center pin of the potentiometer. Circuit Code /* * AnalogInput * by DojoDave <http://www.

cc/en/Tutorial/AnalogInput) .arduino.void loop() { val = analogRead(potPin). digitalWrite(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 (Printable View of http://www. delay(val). digitalWrite(ledPin. delay(val). HIGH). LOW).

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

value). value+=5) { analogWrite(ledpin. Code int value = 0. Circuit An LED connected to digital pin 9.arduino.Arduino : Tutorial / Fading Learning Examples | Foundations | Hacking | Links Examples > Analog I/O Fading Demonstrates the use of analog output (PWM) to fade an LED. } for(value = 255. value <= 255. value). value >=0.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-=5) { analogWrite(ledpin. } } (Printable View of http://www. void setup() { // nothing for setup } void loop() { for(value = 0 . delay(30). int ledpin = 9. delay(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 .

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

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

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

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

size(200. } void draw() { // Process each one of the serial port events while (port. } void serialEvent(int serial) { if(serial != NEWLINE) { buff += char(serial). // Open your serial port port = new Serial(this.length()-1). 9600). } } // <-. } else { buff = buff. buff. 200). "COMXX". } background(val). } else { val = 0. } println(buff).available() > 0) { serialEvent(port. // 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.read()).SUBSTITUTE COMXX with your serial port name!! Restore Edit Page | Page History | Printable View | All Recent Site Changes . // Clear the value of "buff" buff = "".substring(1.

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

begin(9600). if (val >= THRESHOLD) { statePin = !statePin.arduino.cc/en/Tutorial/Knock) . statePin).arduino. } } // 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.println("Knock!"). OUTPUT). byte val = 0. * * http://www. followed by // short delay to avoid overloading the serial port (Printable View of http://www. to toggle the light threshold value to decide when the detected sound is a knock or not void setup() { pinMode(ledPin. time cycles) digitalWrite(ledPin. int THRESHOLD = 100.cc/en/Tutorial/Knock */ int ledPin = 13. newline delay(10). int knockSensor = 0. It writes * "knock" to the serial port if the Threshold is crossed. // declare the ledPin as as OUTPUT Serial. Serial.* if the signal goes over a certain threshold. // // // // // 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. int statePin = LOW. * and toggles the LED on pin 13. // use the serial port } void loop() { val = analogRead(knockSensor).

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

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

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

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

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

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 .

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

port.import processing. port. Serial.list()[0]. The first port in the list is // port #0 and the third port in the list is port #2.write('H'). 100.list()). 100). } rect(50. 9600). } // 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 .write('L'). // You will need to choose the port that the Arduino board is // connected to from this list. void setup() { size(200.serial. // List all the available serial ports in the output pane.*. 200). if(mouseOverRect()) { fill(#BBBBB0). 50. } else { fill(#666660). println(Serial. noStroke(). frameRate(10). Serial port. } void draw() { background(#222222). } // function to test if mouse is over square boolean mouseOverRect() { return ((mouseX >= 50)&&(mouseX <= 150)&&(mouseY >= 50)&(mouseY <= 150)). // 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.

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

port. 100). } else { fill(#666660).cc/en/Tutorial/PhysicalPixel) .write('L'). 9600).arduino.list()[0]. 50.write('H'). if(mouseOverRect()) { fill(#BBBBB0). 100. } // function to test if mouse is over square boolean mouseOverRect() { return ((mouseX >= 50)&&(mouseX <= 150)&&(mouseY >= 50)&(mouseY <= 150)).// 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. } void draw() { background(#222222). port. } rect(50. Serial. } // 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.

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 .

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

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

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

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

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

They are accessible from software by using the digitalWrite() function. 2008. 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. * Restore April 08. The job of the 10K series resitor is to prevent * a short circuit if pesky user pushes both buttons at once. In this case the scheme just reports that sw2 is pushed. at 08:24 PM by David A. The job of the 10K series resistor. 2008. The job of the 10K series resistor incidentally is to prevent a short circuit if a pesky user pushes both buttons at once.Show changes to markup April 08. at 07:59 PM by Paul Badger Changed lines 9-12 from: if both buttons are pushed at the same time. 2008. Restore April 08. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive. Swap the 10k * resistor to the bottom of the schematic if you want it to favor sw1.TwoSwitchesOnePin History Hide minor edits .+5 volts in the Freeduino's case) built into the Atmega chip upon which Freeduino's are based.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. 2008. to: 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 . 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.+5 volts in the Arduino's case) built into the Atmega chip upon which Freeduino's are based. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. Mellis . incidentally. 2008. at 07:56 PM by Paul Badger Changed line 16 from: . In this case the scheme just reports sw2 is pushed. They are accessible from software by using the digitalWrite() function. when the pin is set to an input. at 08:23 PM by David A. In this case the scheme just reports that sw2 is pushed. is to prevent a short circuit if a pesky user pushes both buttons at once. Restore April 08. when the pin is set to an input.

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

begin(9600). stateA = digitalRead(swPin).* 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. stateB. HIGH). * * 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. * it will overwhelm the 200K resistor and the pin will report HIGH. int sw1. but when the pullup resistor is turned on. } void loop() { digitalWrite(swPin. In this case the scheme just reports sw2 is pushed. Swap the 10k * resistor to the bottom of the schematic if you want it to favor sw1. 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.switch 1 must be pushed . stateB = digitalRead(swPin). void setup() { Serial. digitalWrite(swPin.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. // both states HIGH . The job of the 10K series resitor is to prevent * a short circuit if pesky user pushes both buttons at once. // pin for input . It can be ommitted on a center-off slide or toggle * where states are mutually exclusive. sw2.

sw2 = 1. position sw2 = 0. } 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 .print(sw1). Serial. } Serial. delay(100).switch 2 must be pushed // stateA HIGH and stateB LOW // no switches pushed .println(sw2). } else if ( stateA == 0 && stateB == 0 ){ sw1 = 0.print(" "). Serial.sw2 = 0. } // both states LOW .

when the pin is set to an input. sw2.begin(9600). LOW). The job of the 10K series resistor. stateB. It can be omitted on a center-off slide or toggle switch where the states are mutually exclusive.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 . * it will overwhelm the 200K resistor and the pin will report HIGH. When the internal pullup resistor is turned on however. it will overwhelm the external 200K resistor and the pin will report HIGH. // pin for input . incidentally. void setup() { Serial. In this case the scheme just reports that sw2 is pushed. This sketch exploits the pullup resistors under software control. /* * 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. They are accessible from software by using the digitalWrite() function. 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. is to prevent a short circuit if a pesky user pushes both buttons at once. int sw1. } void loop() { digitalWrite(swPin.+5 volts in the Arduino's case) built into the Atmega chip upon which Freeduino's are based. 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. * * 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. but when the pullup resistor is turned on.note: no semicolon after #define // variables to store pin states // variables to represent switch states // make sure the puillup resistors are off .

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

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 .

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. to: Use the Digital > Button example to read the tilt-sensor. OUTPUT). 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).Show changes to markup June 12. 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. Cuartielles * */ int ledPin = 13. 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. int inPin = 7. } void loop() { value = digitalRead(inPin). at 08:53 AM by David A. void setup() { pinMode(ledPin. Restore June 12. Mellis Changed line 17 from: Use the 'Digital > Button example to read the tilt-sensor. int value = 0. } // initializes digital pin 13 as output // initializes digital pin 7 as input // reads the value at a digital input to: Code . pinMode(inPin. at 08:53 AM by David A. digitalWrite(ledPin. value).Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 2007.TiltSensor History Hide minor edits . 2007. * * (cleft) David Cuartielles for DojoCorp and K3 * @author: D.

39 Added lines 1-42: Tilt Sensor The tilt sensor is a component that can detect the tilting of an object. int inPin = 7. to: The prototyping board has been populated with a 1K resitor to make the pull-up and the sensor itself. 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. 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. by Anders Gran Restore January 04. int value = 0. the software comes from the basic Arduino examples. The prototyping board has been populated with a 1K resitor to make the pull-up and the sensor itself. However it is only the equivalent to a pushbutton activated through a different physical mechanism.246. Changed lines 11-12 from: Picture of a protoboard supporting the tilt sensor. * * (cleft) David Cuartielles for DojoCorp and K3 * @author: D. http://static. // initializes digital pin 13 as output . This type of sensor is the environmental-friendly version of a mercuryswitch. 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. void setup() { pinMode(ledPin. the software comes from the basic Arduino examples. 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. 2006. by Anders Gran to: Picture of a protoboard supporting the tilt sensor. We have chosen the tilt sensor from Assemtech.com/30/65458903_d9a89442a9.jpg Picture of a protoboard supporting the tilt sensor. which datasheet can be found here. The hardware was mounted and photographed by Anders Gran. at 06:27 AM by 193.flickr. by Anders Gran /* Tilt Sensor * ----------* * Detects if the sensor has been tilted or not and * lights up the LED if so. Restore December 01. We have chosen the tilt sensor from Assemtech. the software comes from the basic Arduino examples. 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. We have chosen the tilt sensor from Assemtech. Cuartielles * */ int ledPin = 13. The hardware was mounted and photographed by Anders Gran. which datasheet can be found here. which datasheet can be found here.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. OUTPUT).Use the 'Digital > Button example to read the tilt-sensor. 2006.

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

However it is only the equivalent to a pushbutton activated through a different physical mechanism.arduino. The code example is exactly as the one we would use for a pushbutton but substituting this one with 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. which datasheet can be found here. This type of sensor is the environmental-friendly version of a mercury-switch.cc/en/Tutorial/TiltSensor) . 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. (Printable View of http://www. The prototyping board has been populated with a 1K resitor to make the pull-up and the sensor itself. 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. We have chosen the tilt sensor from Assemtech. by Anders Gran Code Use the Digital > Button example to read the tilt-sensor. The hardware was mounted and photographed by Anders Gran. Circuit Picture of a protoboard supporting the tilt sensor. 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. the software comes from the basic Arduino examples.

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 .

Then. the joystick gives a coordinate (x.com/35/94946013_ba47fe116e.y) back to arduino.49. This way.3.6. when the joystick gives us a coordinate.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. This circle will be from now on our 'Pie' (see bottom right of the first image).flickr.com/39/94946015_aaab0281e8.y) * * The program then calculates to which of the 8 * possible zones belogns the coordinate (x.9 }.124. int ledVerde = 13. As you can see looking to the joystick is that the space in which he moves is a circle.ControleLEDcircleWithJoystick History Hide minor edits .5. at 10:31 AM by 193. The only thing we need now to understand is that we have divided our Pie in 8 pieces. To each piece will correspond an LED.107 Added lines 1-163: Controlling a circle of LEDs with a Joystick The whole circuit: http://static.flickr.flickr. the program always lights up the LED corresponding to the pie in which the joystick is.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.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial.flickr.8.com/19/94946024_f7fd4b55ec.jpg Detail of the arduino wiring http://static. it will necesarilly belong to one of the pies.jpg Detail of the LED wiring http://static.com/42/94946020_2a1dd30b97.Show changes to markup February 03. (See figure below).4. // Array of 8 leds mounted in a circle . http://static.jpg How this works As you know from the Interfacing a Joystick tutorial.7. 2006.

} // function that calculates in which of the 8 possible zones is the coordinate x y. previousZone = 0. beginSerial(9600). coordY = 0. OUTPUT). centerY = 500. int x2.cy). OUTPUT). i++) { pinMode(ledPins[i]. i< 8. else return 5.int int int int int int int int int espera = 40. cx. cy int calculateZone (int x. } else // fourth cuadrant { if (alpha > -1) return 6. y2 int calculateSlope(int x1. joyPin1 = 0. pinMode (ledVerde. // // // // // // 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. actualZone = 0. centerX = 500. coordX = 0. thus higher part of the first quadrant return 0. else return 1. // 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 y2) { return ((y1-y2) / (x1-x2)). else return 3. for (i=0. y1 and x2. . given the center cx. int y1.y. } } else { if (y < cy) // third cuadrant { if (alpha > 1) return 4. } } // function that calculates the slope of the line that passes through the points // x1. int cy) { int alpha = calculateSlope(x. int cx. int y. joyPin2 = 1. // Otherwise the point is in the lower part of the first quadrant } else // second cuadrant { if (alpha > -1) return 2.

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

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 .

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

// Array of 8 leds mounted in a circle ledVerde = 13. .y) * * The program then calculates to which of the 8 * possible zones belogns the coordinate (x.5. // slider variable connecetd to analog pin 0 joyPin2 = 1.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. actualZone = 0. previousZone = 0. // variable to read the value from the analog pin 1 centerX = 500.9 }. // slider variable connecetd to analog pin 1 coordX = 0.8.7. // Time you should wait for turning on the leds joyPin1 = 0.4. // we measured the value for the center of the joystick centerY = 500.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. // variable to read the value from the analog pin 0 coordY = 0.3. espera = 40.6.

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

// delay (500). serialWrite(13). // But this is necesary so. // print space printInteger(coordX). // we print int the terminal. // print space printInteger(actualZone). and the zone where it belongs. serialWrite(32). serialWrite(10). // print space printInteger(coordY). serialWrite(32).if (actualZone != previousZone) digitalWrite (ledPins[previousZone].Spain (Printable View of http://www. don't delete it! previousZone = actualZone. LOW). serialWrite(32).Madrid . } @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). the cartesian value of the coordinate.cc/en/Tutorial/ControleLEDcircleWithJoystick) .arduino. //This is not necesary for a standalone version serialWrite('C'). serialWrite(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 .

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

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

analogWrite(cOut. Serial.and if the PRINT flag is set. OUTPUT). { Serial. } } else { PRINT = 1.println(PRINT).begin(9600). } } } Restore Edit Page | Page History | Printable View | All Recent Site Changes .print("\t"). pinMode(bOut.. { checkSum = aVal+bVal+cVal.add up the 3 values. analogWrite(aOut.print("\tPrint: ").print(bVal). 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.. Serial. } void loop() { i += 1.prevCheckSum) <= sens ) // If old and new values are // within sens points.print("<=>").then print the values.. // read input pins. Serial. cVal).print(prevCheckSum). cVal = analogRead(cIn) / 4. Serial. analogWrite(bOut. Serial.. OUTPUT). bVal = analogRead(bIn) / 4.. { Serial. Serial.println(cVal). pinMode(cOut.print("B: ").. // Count loop aVal = analogRead(aIn) / 4. { if (PRINT) // . // Update the values if (DEBUG) // If we want debugging output as well. PRINT = 0. Serial. Serial. Serial. aVal).print("C: "). // .print(checkSum). OUTPUT)...print("\t"). Serial..print(aVal).. bVal). // Re-set the flag } prevCheckSum = checkSum....void setup() { pinMode(aOut. // . Serial. Serial. if ( abs(checkSum ..print("A: ").

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

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

2008. // check for button press to: // check for button press Restore April 21. Restore April 18. pullup resistors.5. 2008. at 09:45 PM by Paul Badger Changed lines 70-71 from: // routine to report elapsed time to: // routine to report elapsed time . printing fractions Restore April 18. 2008. 2008. printing fractions to: * Demonstrates using millis(). switch debounce time) to: elapsedTime = millis() .Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. // 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. making two things happen at once. 2008. at 07:24 AM by Paul Badger Added lines 1-105: .this breaks when delays are in single or double digits.startTime.Show changes to markup April 21. 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. 2008. at 07:25 AM by Paul Badger Changed lines 10-11 from: * Demonstrates using millis(). pullup resistors.Stopwatch History Hide minor edits . Fix this as a coding exercise. to: buttonState = digitalRead(buttonPin).startTime) . Restore April 21. * making two things happen at once. at 09:47 PM by Paul Badger Changed line 64 from: elapsedTime = (millis() . at 09:49 PM by Paul Badger Changed lines 47-48 from: buttonState = digitalRead(buttonPin).

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 . long interval = 100. ground. other side connected to ground * LED with series resistor between pin 13 and ground */ #define ledPin 13 #define buttonPin 4 int value = LOW.startTime) . to . long elapsedTime .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. pinMode(ledPin.start the clock startTime = millis(). digitalWrite(buttonPin. pinMode(buttonPin. INPUT). HIGH).begin(9600). // 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. pullup resistors. // check for button press buttonState = digitalRead(buttonPin). pins default to INPUT anyway // turn on pullup resistors. long previousMillis = 0. // sets the digital pin as output // not really necessary. OUTPUT). making two things happen at once. long startTime . int blinking.stop the clock and report elapsedTime = (millis() . printing fractions * * Physical setup: momentary switch connected to pin 4.5. int buttonState.timer is timing blink interval . blinking = true. int lastButtonState. /* StopWatch * Paul Badger 2008 * Demonstrates using millis(). 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 . // 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 . delay(5). int fractional.Stopwatch A sketch that demonstrates how to do two (or more) things at once by using millis(). lastButtonState = buttonState. } void loop() { // here is where you'd put code that needs to be running all the time.

to blink routine .print(". lastButtonState = buttonState. 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. to // routine to report elapsed time Serial.print( (int)(elapsedTime / 1000L) ). all done timing // store buttonState in lastButtonState. if ( (millis() . if (value == LOW) value = HIGH. digitalWrite(ledPin. cast to an int to print Serial. else value = LOW.switch debounce time) blinking = false. } else{ digitalWrite(ledPin. that is. LOW). fractional = (int)(elapsedTime % 1000L).println(fractional)."). } } } // 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 . // if the LED is off turn it on and vice-versa.blink the LED while timing check to see if it's time to blink the LED. compare next time } // // // // // divide by 1000 to convert to seconds . compare next time // turn off blinking. value).previousMillis > interval) ) { if (blinking == true){ previousMillis = millis(). of time Serial.then // print decimal point // use modulo operator to get fractional part // print fractional part of time // store buttonState in lastButtonState. } else{ lastButtonState = buttonState.

pins default to INPUT anyway // turn on pullup resistors. other side connected to ground * LED with series resistor between pin 13 and ground */ #define ledPin 13 #define buttonPin 4 int value = LOW. long elapsedTime . timing lastButtonState = buttonState. int blinking.startTime. int lastButtonState. // 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 . pullup resistors.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(). delay(5). long previousMillis = 0. lastButtonState = buttonState. pinMode(buttonPin.begin(9600). . blinking = true. Fix this as a coding exercise. INPUT). long interval = 100. pinMode(ledPin. } void loop() { // check for button press buttonState = digitalRead(buttonPin). int fractional. // 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 . to compare next time // store buttonState in // store elapsed time // turn off blinking. int buttonState. HIGH).timer is timing blink interval . 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 . all done // // // // store the start time turn on blinking while timing short delay to debounce switch store buttonState in // routine to report elapsed time . digitalWrite(buttonPin. lastButtonState. OUTPUT).start the clock startTime = millis(). lastButtonState. pin to ground. printing fractions * * Physical setup: momentary switch connected to pin 4.this breaks when delays are in single or double digits. long startTime . /* StopWatch * Paul Badger 2008 * Demonstrates using millis().stop the clock and report elapsedTime = millis() . * 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. blinking = false.

if (value == LOW) value = HIGH.arduino. 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.println(fractional).print(".print( (int)(elapsedTime / 1000L) ). lastButtonState. LOW). value).then cast to an int to print Serial.cc/en/Tutorial/Stopwatch) // remember the last time we blinked // turn off LED when not blinking . } } } (Printable View of http://www.Serial.previousMillis > interval) ) { if (blinking == true){ previousMillis = millis(). else value = LOW. digitalWrite(ledPin.blink the LED while timing check to see if it's time to blink the LED. seconds . } else{ lastButtonState = buttonState. fractional = (int)(elapsedTime % 1000L). that is. } else{ digitalWrite(ledPin. the LED // if the LED is off turn it on and vice-versa. if ( (millis() ."). 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 . fractional part of time 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 .

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

2008. 2008. Mellis - PM by David A. 2008. at 01:41 Changed line 13 from: to: Changed line 17 from: to: Restore July 02. Mellis - An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an Arduino. at 01:42 PM by David A. Mellis Changed lines 58-66 from: @] to: @] Data Here are some accelerometer readings from the y-axis of an ADXL322 2g accelerometer. at 01:40 Changed line 13 from: to: Changed line 17 from: to: Restore July 02. at 01:40 Changed line 17 from: to: Restore July 02. Mellis - PM by David A. at 01:40 Changed line 13 from: to: Restore July 02. 2008. 2008. Changed lines 14-21 from: Accelerometer Pin Arduino Pin Self-Test Z-Axis Analog Input 0 Analog Input 1 . Mellis Added lines 13-14: Pinout for the above configuration: Added lines 19-20: Or. 2008. 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:49 PM by David A. 2008. Mellis Changed line 15 from: to: Restore July 02. Mellis - PM by David A. Mellis Changed line 21 from: to: Restore July 02. if you're using just the accelerometer: Restore July 02. at 01:43 PM by David A. Values should be the same for the other axes. 2008. Mellis - PM by David A. at 01:40 Added lines 11-12: PM by David A.Changed line 64 from: to: Restore July 02. but will vary based on the sensitivity of the device. at 01:43 PM by David A. 2008.

2008. at 01:33 PM by David A. ADXL320. 2008. 2008. Mellis Added line 11: Restore July 02. at 01:32 PM by David A. ADXL321. 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. at 01:33 PM by David A. Circuit . Mellis Added lines 1-52: Examples > Devices ADXL3xx Accelerometer Reads an Analog Devices ADXL3xx series (e. ADXL322.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. ADXL330) accelerometer and communicates the acceleration to the computer. The pins used are designed to be easily compatible with the breakout boards from Sparkfun.g.

print(" "). xpin = 3. Serial.print(analogRead(zpin)). Serial.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. } void loop() { Serial. If you use the normal 5V and // GND pins on the Arduino.print(" "). This makes it possible to directly connect the // breakout board to the Arduino. digitalWrite(powerPin. Serial. LOW). } . pinMode(groundPin. delay(1000). OUTPUT). HIGH). Serial.println(). pinMode(powerPin. // // // // // 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. Serial. zpin = 1. // Provide ground and power by using the analog inputs as normal // digital pins. OUTPUT).begin(9600). you can remove these lines. powerpin = 19. digitalWrite(groundPin. ypin = 2.print(analogRead(ypin)).print(analogRead(xpin)).

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

ADXL320. xpin = 3. powerpin = 19. zpin = 1. ADXL330) accelerometer and communicates the acceleration to the computer. ypin = 2.Arduino : Tutorial / ADX L3xx Learning Examples | Foundations | Hacking | Links Examples > Analog I/O ADXL3xx Accelerometer Reads an Analog Devices ADXL3xx series (e. 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. ADXL321. 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. // // // // // analog analog x-axis y-axis z-axis input pin 4 input pin 5 of the accelerometer (only on 3-axis models) void setup() . 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.g. which is read by an analog input on the Arduino. ADXL322.

parallel to ground or 0°). digitalWrite(powerPin. If you use the normal 5V and // GND pins on the Arduino. you can remove these lines. LOW). but will vary based on the sensitivity of the device. } void loop() { Serial.print(analogRead(xpin)). OUTPUT).println().print(" ").print(analogRead(zpin)). Serial.g. With the axis horizontal (i.print(analogRead(ypin)). Serial. This makes it possible to directly connect the // breakout board to the Arduino. // Provide ground and power by using the analog inputs as normal // digital pins.print(" "). } Data Here are some accelerometer readings collected by the positioning the y-axis of an ADXL322 2g accelerometer at various angles from ground. delay(1000). Serial. digitalWrite(groundPin. HIGH). 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. the ADXL302 5g one). Values should be the same for the other axes.cc/en/Tutorial/ADXL3xx) .arduino.begin(9600). but values at other angles will be different for a different accelerometer (e. pinMode(groundPin. OUTPUT). the accelerometer reading should be around 512.{ Serial.e. Serial. pinMode(powerPin. 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 .

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

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

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

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

The acceleration pins send the signals back to the computer in the form of pulses which width represents the acceleration. at the University of Zaragoza. int xaccPin = 7. The example shown here was mounted by Anders Gran. When making very accurate measurements.Experiential Vehicles * @sponsor: Experiments in Art and Technology Sweden. Protoboard with an Accelerometer.Sweden * @author: Marcos Yarza * @hardware: Marcos Yarza * @project: SMEE .org * copyleft 2005 K3 .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.Malmo University . 1:1 Scale */ int ledPin = 13. the sensor counts with a temperature pin that can be used to compensate possible errors. Spain. while the the temperature should be taken as an analog input. . The pins dedicated to measure acceleration can be connected directly to digital inputs to the Arduino board. 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.0j0. The board is connected minimally. leaving the temperature pin open. while the software was created by Marcos Yarza. makes * the monitor LED blink once sent * * * http://www. who is Arduino's accelerometer technology researcher. only the two axis pins are plugged to the board.

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

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

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 .

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

LOW). // Wait for 5 microseconds digitalWrite(ultraSoundSignal. LOW). // Append signal value to val while(val == LOW) { // Loop until pin reads a high value to: pinMode(ultraSoundSignal. // Switch signalpin to output Deleted line 29: Deleted line 30: Changed lines 33-42 from: digitalWrite(ultraSoundSignal. // Wait for 2 microseconds digitalWrite(ultraSoundSignal. LOW). // Send low pulse delayMicroseconds(2). // Switch signalpin to input val = digitalRead(ultraSoundSignal). pinMode(ultraSoundSignal. // Example identifier for the sensor to: ultrasoundValue = timecount. // Append echo pulse time to ultrasoundValue serialWrite('A'). // Send low pulse delayMicroseconds(2). OUTPUT). // Send high pulse delayMicroseconds(5). // Switch signalpin to input val = digitalRead(ultraSoundSignal). // Holdoff to: digitalWrite(ultraSoundSignal. // Send high pulse delayMicroseconds(5). val = 0. HIGH).timecount = 0. // 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: } . INPUT). // Wait for 5 microseconds digitalWrite(ultraSoundSignal. INPUT). // Append echo pulse time to ultrasoundValue serialWrite('A'). // 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. // Wait for 2 microseconds digitalWrite(ultraSoundSignal. LOW). // Holdoff Deleted line 39: Deleted line 40: Changed lines 43-48 from: pinMode(ultraSoundSignal. HIGH).

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

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

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

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

pinMode(qt401_clk. // = 3.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. // = 6. void qt401_init() { // define pin directions pinMode(qt401_drd.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. pinMode(qt401_di. // data ready data in (from sensor) slave select clock data out (to sensor) detect proximity byte result. INPUT). // = 7. INPUT). // = 8. OUTPUT).Qt401 History Hide minor edits . 2006.18.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. OUTPUT).potemkin. INPUT). pinMode(qt401_det.Show changes to markup January 19.162 Added lines 1-5: qt401 sensor full tutorial coming soon Restore January 19.81.81. pinMode(qt401_ss. OUTPUT). at 06:19 AM by 85.18.162 Added lines 1-195: /* qt401 demo * -----------* * the qt401 from qprox http://www. at 06:19 AM by 85. pinMode(qt401 prx. pinMode(qt401_do. // = 5. 2006. // = 4. INPUT). .qprox.

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

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

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

void qt401_init() { // define pin directions pinMode(qt401_drd.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.potemkin. // = 8. pinMode(qt401_clk.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. digitalWrite(qt401_ss. // initialise pins digitalWrite(qt401_clk. // = 3. // = 4. pinMode(qt401_det. pinMode(qt401_ss. HIGH). byte mask = 0. } // // wait for the qt401 to be ready // void qt401_waitForReady(void) { while(!digitalRead(qt401_drd)){ continue. OUTPUT). } } mapping = 2. OUTPUT).qprox. OUTPUT). // = 6. INPUT). pinMode(qt401_prx. . INPUT). // 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. // = 5. pinMode(qt401_do. // = 7.HIGH). INPUT). pinMode(qt401_di. INPUT).Arduino : Tutorial / Qt 401 Learning Examples | Foundations | Hacking | Links qt401 sensor full tutorial coming soon /* qt401 demo * -----------* * the qt401 from qprox http://www.

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

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

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 .

OUTPUT). 1519. 2006. // 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. 1014. byte names[] = {'c'. 2006. 956}. 'f'. 'a'.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 1432. void setup() { pinMode(ledPin. byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". } . 'g'.PlayMelody History Hide minor edits . int count3 = 0. 1275. at 04:15 PM by Clay Shirky Changed line 169 from: [= to: [= Restore October 02. int speakerOut = 9. int tones[] = {1915. int count2 = 0. Cuartielles for K3 */ int ledPin = 13. 1136. int statePin = LOW. 'e'. int MAX_COUNT = 24. 1700. * * 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. 'C'}. it requires to know * about timing issues and about how to play tones. 'd'. at 04:15 PM by Clay Shirky Added lines 165-234: =] Second version.Show changes to markup October 02. 'b'. with volume control set using analogWrite() [= /* Play Melody * ----------* * Program to play melodies stored in an array.

Changed lines 26-33 from: * to: * Each note has a frequency. then LOW * for 'pulse-width' microseconds. to create signature frequencies. analogWrite(speakerOut.void loop() { analogWrite(speakerOut. count3 <= (melody[count*2] . * We calculate the pulse-width to be half the period. * This pulsing creates a vibration of the desired frequency.count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. for (count3 = 0. 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 . } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut. count++) { statePin = !statePin. measured in microseconds. 0).count2<8. statePin). digitalWrite(ledPin. delayMicroseconds(tones[count2]). We'll use pulse-width * modulation (PWM) to create that vibration. count < MAX_COUNT.500). it requires to know * about timing issues and about how to play tones.48) * 30. } } } } } Restore October 02. we pulse * the speaker HIGH for 'pulse-width' microseconds.Re-wrote Example #1 Changed lines 21-22 from: * Program to play melodies stored in an array. count3++) { for (count2=0. delayMicroseconds(tones[count2]). 0). 0). 2006. delayMicroseconds(500). 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. at 04:10 PM by Clay Shirky . created by varying the period of * vibration. for (count = 0.

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

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

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. it requires to know about timing issues and about how to play tones. int speakerOut = 9.' rest_count creates a loop variable to bring 'rest' beats in line with 'tone' beats of the same length. 956}. 1136.arduino. 1700. 'a'. Light fuse and get away. 'C'}. . Lies lies lies! It holds for at least 'duration' microseconds. 1519. 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. Cuartielles for K3 Deleted lines 164-205: int ledPin = 13. 'b'.) 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. pause. 'g'. 'f'. int statePin = LOW. int MAX_COUNT = 24. _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. // maximum volume is 1000 byte names[] = {'c'. int count3 = 0. int count2 = 0. as with the second program at http://www. and rest_count to #define statements RE-WRITE to include volume. 'e'. as well as overhead from any program mods. // 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. rest_count will be affected by chip architecture and speed. Your mileage may vary. using analogWrite.[= /* Play Melody .FV * * * * * * * * * * * * * * * * * * * * * * * * * to: /* * * * * * * * * * * * * * * * * * * * * * * * * * * NOTES The program purports to hold a tone for 'duration' microseconds. 1275. int tones[] = {1915. '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. 1014. a tone of 'duration' plays much more slowly than a rest of 'duration. int volume = 300. Past behavior is no guarantee of future performance. 1432. byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p".

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

void setup() { pinMode(ledPin.HIGH). LOW).FV * ---------------* * Program to play melodies stored in an array. 'a'. 0). 'd'. // 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. to: digitalWrite(speakerOut. byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". * * 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. 1275. int volume = 300.500). // maximum volume is 1000 byte names[] = {'c'. } void loop() { . it requires to know * about timing issues and about how to play tones. 956}. Cuartielles for K3 */ int ledPin = 13. int count3 = 0. 1432. 1519.analogWrite(speakerOut. to: digitalWrite(speakerOut. int speakerOut = 9. 0). int tones[] = {1915. 1136. 'b'. 1014. OUTPUT). Changed line 77 from: analogWrite(speakerOut. 'f'. Added lines 85-157: =] Example 2: Play Melody _ faded volume [= /* Play Melody . int statePin = LOW. to: digitalWrite(speakerOut. int count2 = 0. Changed line 72 from: analogWrite(speakerOut. 1700. 'e'. 0). int MAX_COUNT = 24. 'g'. 'C'}.

2005. delayMicroseconds(tones[count2]). } } } } } Restore October 17.25 Added lines 1-76: Play Melody This example makes use of a Piezo Speaker in order to play melodies.178. at 05:21 PM by 195. 0).flickr. commercial devices are usually having a red and a black wires indicating how to plug it to the board. 0). 2005.count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. count3++) { for (count2=0. delayMicroseconds(tones[count2]). at 05:29 PM by 195. 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: . digitalWrite(ledPin. and not just a plain HIGH or LOW value.229. 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. We are taking advantage of the processors capability to produde PWM signals in order to play music.analogWrite(speakerOut.25 Changed lines 7-8 from: to: http://static. We connect the black one to ground and the red one to the output. delayMicroseconds(500).jpg Example of connection of a Piezo to pin 10 Restore October 17.com/31/53523608_3d4268ba68. Sometimes it is possible to acquire Piezo elements without a plastic housing.count2<8.178. count < MAX_COUNT. In our example we are plugging the Piezo on the pin number 10. count3 <= (melody[count*2] . for (count3 = 0.229.48) * 30.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. for (count = 0. /* * * * * * * * * * * * * Play Melody ----------Program to play melodies stored in an array. at 05:32 PM by 195.25 Added lines 7-8: The other thing to remember is that Piezos have polarity.volume). Restore October 17. count++) { statePin = !statePin. 0).178. statePin). } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut. then they will just look like a metallic disc. analogWrite(speakerOut. 2005.

'g'. 'b'. Cuartielles for K3 int ledPin = 13. statePin). // 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 speakerOut = 9.500). 1519. byte melody[] = "2d2a1f2c2d2a2d2c2f2d2a2c2d2a1f2c2d2a2a2g2p8p8p8p". 0). 1700.count2<8. count < MAX_COUNT. 'e'. 'C'}. 1014.* 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. 'a'. 'f'. int count2 = 0. 'd'. } void loop() { analogWrite(speakerOut. int count3 = 0. 1275. delayMicroseconds(tones[count2]). int MAX_COUNT = 24. } if (melody[count*2 + 1] == 'p') { // make a pause of a certain size analogWrite(speakerOut.48) * 30. 0). 0). int tones[] = {1915. 956}. count++) { statePin = !statePin. void setup() { pinMode(ledPin. 1136. byte names[] = {'c'. OUTPUT). delayMicroseconds(500). digitalWrite(ledPin. analogWrite(speakerOut. int statePin = LOW. 1432. count3++) { for (count2=0. for (count3 = 0. for (count = 0. delayMicroseconds(tones[count2]). count3 <= (melody[count*2] .count2++) { if (names[count2] == melody[count*2 + 1]) { analogWrite(speakerOut. } } } } } Restore Edit Page | Page History | Printable View | All Recent Site Changes .

commercial devices are usually having a red and a black wires indicating how to plug it to the board. measured in microseconds. The other thing to remember is that Piezos have polarity. The first example of the code will just send a square wave to the piezo. 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. We are taking advantage of the processors capability to produde PWM signals in order to play music.Arduino : Tutorial / Play Melody Learning Examples | Foundations | Hacking | Links Play Melody This example makes use of a Piezo Speaker in order to play melodies. In our example we are plugging the Piezo on the pin number 9. 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. then they will just look like a metallic disc. Each note has a frequency. that supports the functionality of writing a PWM signal to it. We connect the black one to ground and the red one to the output. while the second one will make use of the PWM functionality to control the volume through changing the Pulse Width. We'll use pulse-width . created by varying the period of vibration. to create signature frequencies. Sometimes it is possible to acquire Piezo elements without a plastic housing.

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

' rest_count creates a loop variable to bring 'rest' beats * in line with 'tone' beats of the same length. pause. report loop. duration = beat * tempo. } } } /* * NOTES * The program purports to hold a tone for 'duration' microseconds. Your mileage may vary.. as well as * overhead from any program mods. delayMicroseconds(pause). and rest_count to #define statements * RE-WRITE to include volume. Serial. // Set up timing playTone(). Serial.print(beat).println(duration). Light fuse and get away. i++) { tone = melody[i]. Serial.print(" ").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.) * 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. if (DEBUG) { // If debugging. beat.arduino. tone. Past behavior is no guarantee of future * performance. * Lies lies lies! It holds for at least 'duration' microseconds.. using analogWrite.print(i). as with the second program at * http://www. and duration Serial. i<MAX_COUNT. Serial.print(tone).} } // LET THE WILD RUMPUS BEGIN ============================= void loop() { // Set up a counter to pull from melody[] and beats[] for (int i=0. Serial.print(":").print(" "). Serial. a tone of 'duration' plays much more slowly than a rest * of 'duration. * * 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. * * rest_count will be affected by chip architecture and speed. // A pause between notes. _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. 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 . beat = beats[i]. it requires to know about timing issues and about how to play tones. with volume control set using analogWrite() /* * * * * * * * * * * * * * * * * * Play Melody ----------Program to play melodies stored in an array.

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

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

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

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

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

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 .

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

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

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

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

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

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

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 .

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

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

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

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

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

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

so keep them as short and tidy as possible. and choose "LiquidCrystal". 2006. and choose "LiquidCrystal". 2006.h> should pop up at the top of your sketch. Look at the datasheet for your LCD board to figure out which pins are where. Restore August 02. at 11:39 AM by Heather Dewey-Hagborg Changed lines 24-27 from: Connect wires from the breadboard to the arduino input sockets.delay(1000). The phrase #include should pop up at the top of your sketch. If you turn the potentiometer too far in one direction black blocks will appear. to: First start by opening a new sketch in Arduino and saving it. scroll down to "import library". to: delay(1000). Look at the datasheet for your LCD board to figure out which pins are where. 2006. to: If all went as planned both the LCD and the LED should turn on. Now go to the Sketch menu. scroll down to "import library". at 11:19 AM by Heather Dewey-Hagborg Changed lines 80-81 from: . 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. Restore August 02. 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. 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. //repeat forever Restore August 02. 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. On the Arduino module. The pinout is as follows: to: Connect wires from the breadboard to the arduino input sockets. at 11:32 AM by Heather Dewey-Hagborg Restore August 02. There should be a small spot in the middle where the cursor appears crisp and dark. 2006. use the 5V and any of the ground connections. It is a lot of wires. 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. 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. 2006. 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. 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.

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

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

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

optional. 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) . 2006. 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.} to: @] Restore August 02. for debugging Prepare the breadboard Added lines 22-23: Added lines 38-39: .

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

and to send commands directly to the HD44780 chip. 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. Materials needed: * * * * * * Solderless breadboard Hookup wire Arduino Microcontoller Module Potentiometer Liquid Crystal Display (LCD) with HD44780 chip interface Light emitting Diode (LED) .HIGH). digitalWrite(13. use the 5V and any of the ground connections: Connect wires from the breadboard to the arduino input sockets. The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset. to print characters and strings.printIn(string1). to: lcd. Look at the datasheet for your LCD board to figure out which pins are where. such as those available from Sparkfun. and the contrast adjustment pin on your LCD. 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. Insert the LCD header into the breadboard and connect power and ground on the breadboard to power and ground from the microcontroller.init(). Program the Arduino .printIn(string1). delay(1000). lcd.commandWrite(2). On the Arduino module. This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions. Changed lines 109-110 from: } to: @] Restore August 02. delay(1000). delay(1000). lcd. Functions are provided to initialize the screen.optional. to clear the screen.lcd. Additionally you may want to connect an LED for debugging purposes between pin 13 and Ground. Ground. delay(1000). It currently implements 8-bit control and one line display of 5x7 characters. Changed lines 104-107 from: lcd. for debugging Prepare the breadboard Solder a header to the LCD board if one is not present already. 2006.commandWrite(2).

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

This tutorial will walk you through the steps of wiring an LCD to an Arduino microcontroller board and implementing each of these functions.optional. It currently implements 8-bit control and one line display of 5x7 characters. Functions are provided to initialize the screen. 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.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. On the Arduino module. Materials needed: Solderless breadboard Hookup wire Arduino Microcontoller Module Potentiometer Liquid Crystal Display (LCD) with HD44780 chip interface Light emitting Diode (LED) . 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". use the 5V and any of the ground connections. The library provides functions for accessing any LCD using the common HD44780 parallel interface chipset. Prepare the breadboard Solder a header to the LCD board if one is not present already. such as those available from Sparkfun. Unzip the files and place the whole LiquidCrystal folder inside your arduino-0004\lib\targets\libraries folder. to print characters and strings. . for debugging Install the Library For a basic explanation of how libraries work in Arduino read the library page. Download the LiquidCrystal library here.

It is a lot of wires. 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. so keep them as short and tidy as possible. . Ground. Look at the datasheet for your LCD board to figure out which pins are where. and the contrast adjustment pin on your LCD. 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.

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

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

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

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 .

178.25 Changed lines 3-4 from: This page shows two examples on how to drive a bipolar stepper motor. at 05:38 AM by 195. Restore October 21.229.StepperUnipolar History Hide minor edits . at 12:55 PM by 195.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. OUTPUT).178.Show changes to markup December 16.25 Deleted line 107: pinMode(ledPin. These motors can be found in old floppy drives and are easy to control.178. 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.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 2005. These motors can be found in old floppy drives and are easy to control. at 05:37 AM by 195. to: This page shows two examples on how to drive a unipolar stepper motor.229.25 Added lines 1-160: . 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. 2005.

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

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

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

but allows to make the motor spin at different speeds..html] It is a unipolar stepper motor with 5 wires: ..cs.] motor made by Copal Electronics. These motors can be found in old floppy drives and are easy to control. and a ULN2003A driver.8 degrees per step and 96 ohms per winding. It is aiming those that have no knowledge in how to control stepper motors. this stepper: "[. in both directions. 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. The first example is the basic code to make the motor spin in one direction. I have it at 5V and works fine . with 1.]" [http://www.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.red: power connector. This chip has a bunch of transistors embedded in a single housing. with center taps brought out to separate leads [. and controlling both from a potentiometer. The prototyping board has been populated with a 10K potentiomenter that we connect to an analog input. The second example is coded in a more complex way. 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...orange and black: coil 1 . 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.brown and yellow: coil 2 .edu/~jones/step/example.uiowa.

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

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

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 .

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

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

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

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

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

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

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

//define our transmit pin data = 170. //our bitmask bitDelay = 100. let's take the value 170. binary 10101010 mask = 1. } void loop() { for (mask = 00000001. In this example the pin needs to change it's state from high to low for each bit in the byte to be transmitted. This is accomplished using what are known as bitwise operations and a bit mask. binary 10101010. 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. 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. //value to transmit. void setup() { pinMode(transmit. // send 1 } . For a practical example. Standard bitwise operations include AND (&) OR (|) Left Shift (<<) and Right Shift (>>). mask>0. mask <<= 1) { //iterate through bit mask if (data & mask){ // if bitwise AND resolves to true digitalWrite(transmit. Bitwise operations perform logical functions that take affect on the bit level. This is often useful as a method of iteration. for example when sending a byte of data serially out a single pin. 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. 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. To pulse this value out of pin 7 the code might look as follows: byte byte byte byte transmit = 7. The AND (&) operator will result in a 1 at each bit position where both input values were 1.HIGH).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.OUTPUT).

so our operation looks like: 00000010 & 10101010 ________ 00000010 And our output pin gets set to 1. // send 0 } delayMicroseconds(bitDelay). shifting the value one position left each time through the loop. We then perform a bitwise AND operation on the value and the bitmask. 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. //delay } } Here we use a FOR loop to iterate through a bit mask value. 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. Then all 8 bits have been sent and our loop exits.else{ //if bitwise and resolves to false digitalWrite(transmit. 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. Second time throught he loop the mask = 00000010. So in this example. 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.LOW). 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 .

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

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

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

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

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

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

Changed lines 27-28 from: Now we will write the code to enable serial data transmission. at 11:44 AM by Heather Dewey-Hagborg Restore August 15. 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. Restore August 15. If only one serial connection is necessary the hardware serial port should be used. First the transmit line is pulled low to signal a start bit. NOT a specific device tutorial. Finally we pull the line high again to signal a stop bit. 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. 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. Finally we pull the line high again to signal a stop bit. at 11:40 AM by Heather Dewey-Hagborg Restore August 15. Device specific tutorials are on the Tutorial Page. A tutorial on communicating with a computer is here. Device specific tutorials are on the Tutorial Page. 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:42 AM by Heather Dewey-Hagborg Changed lines 78-79 from: This is the SWprint function.jpg Changed lines 23-24 from: picture of device with serial connections to: Attach: ser_wires_web. to: This is the SWprint function. Using software serial allows you to create a serial connection on any of the digital i/o pins on the Arduino. to: other serial devices. 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. 2006. To use 4800 simply replace the variable bit9600Delay with bit4800Delay. This should be used when multiple serial connections are necessary. NOT a specific device tutorial. We will walk through the code in small sections. In this example we are using a 9600 baudrate. 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. A tutorial on communicating with a computer is here. 2006. 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. For a good explanation of serial communication see Wikipedia. To use 4800 simply replace the variable bit9600Delay with bit4800Delay.Attach: pwr_wires_web. For each bit we transmit we hold the line high or low for the specified delay.jpg Restore August 15. First the transmit line is pulled low to signal a start bit. 2006. 2006. We will walk through the code in small sections. This should be used when multiple serial connections are necessary. at 11:22 AM by Heather Dewey-Hagborg - . This is a general purpose software tutorial. Restore August 15. 2006. If only one serial connection is necessary the hardware serial port should be used. This is a general purpose software tutorial.

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

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

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

[@#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: .

arduino. to: If this works. congratulations! Your serial connection is working as planned. You can now use your new serial/computer connection to print debugging statements from your code. congratulations! Your serial connection is working as planned. 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: . at 02:05 PM by Heather Dewey-Hagborg Changed lines 135-137 from: If this works.cc Restore August 23. and to send commands to your microcontroller. 2006. 2006. You can now use your new serial/computer connection to print debugging statements from your code. 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. 2006. 2006. at 02:09 PM by Heather Dewey-Hagborg Added lines 61-64: //Created August 23 2006 //Heather Dewey-Hagborg //http://www. Photos by Thomas Dexter Restore August 23.Restore August 23. and to send commands to your microcontroller.

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

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

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 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).

another between pin 1 and ground. If you are using an LED connect it between pin 13 and ground. at 01:11 PM by Heather Dewey-Hagborg Changed lines 20-21 from: Insert the MAX3323 chip in the breadboard.11 to 5V. 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.Restore August 23. 2006. another across pins 4 and 5. 2006. and the last between pin 6 and ground. and the last between pin 6 and ground. another across pins 4 and 5. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground). Added lines 24-27: Connect a 1uF capacitor across pins 1 and 3.11 to 5V. PICTURE Restore August 23. 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). 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. 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: . Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 . to: Insert the MAX3323 chip in the breadboard. Connect a 1uF capacitor across pins 1 and 3. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 . Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller.

Connect pin 10 to pin 16 pin 11 to pin 15 and pin 12 to pin 17 on the breadboard. another between pin 1 and ground. to: Insert the MAX3323 chip in the breadboard. and the last between pin 6 and ground. with corresponding pins referred to as T1IN. 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. Connect pin 6 and pin 9 on the MAX233 chip to ground and pin 7 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. R1IN and R1OUT in the MAX233 schematic. For the purposes of this tutorial we will only being using one port. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller.11 to 5V. If you are using polarized capacitors make sure the negative pins connect to the negative sides (pins 3 and 5 and ground). Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines.Insert the MAX233 chip in the breadboard. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. Connect your RX pin . another across pins 4 and 5. Connect your TX pin (7) to MAX233 pin 2 (T1IN). Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 . Connect a 1uF capacitor across pins 1 and 3. T1OUT.

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

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

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

8 data bits. another free application with more advanced options. 1 stop bit. Here are two shots of what it might look like. 8 data bits. Added lines 117-121: Now. 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. another free application with more options. You should see the letter you typed return to you in uppercase. no parity. try typing a lowercase character into the terminal window. 2006. no hardware flow control. Press the reset button on the arduino board. 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. one in Hyperterminal the free pre-installed windows terminal application. no parity.to: Restore August 17. one in Hyperterminal the free pre-installed windows terminal application. and one in Realterm. . no hardware flow control. Here are two shots of what it might look like. The word "hi" should appear in the terminal window followed by a line feed character and/or an advancement to the next line. 1 stop bit. and one in Realterm. Press the reset button on the arduino board.

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

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

HIGH). delayMicroseconds(bit9600Delay). } int SWread() { byte val = 0. //wait for start bit if (digitalRead(rx) == LOW) { delayMicroseconds(halfBit9600Delay).OUTPUT). delayMicroseconds(bit9600Delay). digitalWrite(13. SWprint(10). 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. offset < 8.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. mask>0.INPUT). mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx. } //stop bit digitalWrite(tx. //debugging hello SWprint('i').HIGH).LOW). byte SWval.LOW). void setup() { pinMode(rx. HIGH). // send 0 } delayMicroseconds(bit9600Delay). for (int offset = 0. // send 1 } else{ digitalWrite(tx.h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 byte rx = 6. pinMode(tx. //turn on debugging LED SWprint('h'). byte tx = 7.HIGH). for (mask = 0x01. Upload the follwoing code into the Arduino microcontroller module: #include <ctype. digitalWrite(tx. . while (digitalRead(rx)). //carriage return } void SWprint(int data) { byte mask. val |= digitalRead(rx) << offset. 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. offset++) { delayMicroseconds(bit9600Delay). //startbit digitalWrite(tx.

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

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

Attach:rs232pwr_web.jpg Δ The MAX233 chip has two sets of RS-232 line shifters built in and can handle two simultaneous duplex serial ports. 2006.jpg Δ . with corresponding pins referred to as T1IN. For the purposes of this tutorial we will only being using one port. Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. R1IN and R1OUT in the MAX233 schematic. Connect pin 10 to pin 16 pin 11 to pin 15 and pin 12 to pin 17 on the breadboard. Connect pin 6 and pin 9 on the MAX233 chip to ground and pin 7 to 5V.optional. 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. for debugging Prepare the breadboard Insert the MAX233 chip in the breadboard. Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. PICTURE Restore August 15. Connect your TX pin (7) to MAX233 pin 2 (T1IN).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). T1OUT.optional. for debugging to: Light emitting Diode (LED) . Attach:rs232ttl_web. 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) . Connect your RX pin (6) to MAX233 pin 3 (R1OUT). In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting.

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. Restore August 15. HyperTerminal or RealTerm on the PC. 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. for debugging Restore August 15. Zterm on Mac) MAX233 chip 1uf polarized capacitor Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . Instructions for doing this can be found . 2006. HyperTerminal or RealTerm on the PC. you need to make a cable to connect from the serial port (or USB-serial adapter) on your computer and the breadboard. for debugging Restore Edit Page | Page History | Printable View | All Recent Site Changes . Zterm on Mac) MAX233 chip 1uf polarized capacitor Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) .optional. HyperTerminal or RealTerm on the PC.If you do not have one already.optional. Zterm on Mac) MAX233 chip 1uf polarized capacitor Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) .optional. at 03:23 PM by Heather Dewey-Hagborg Changed lines 6-13 from: * * * * * * * to: Computer with a terminal program installed (ie. 2006.

A general purpose software serial tutorial can be found here.optional. Connect pin 15 on the MAX233 chip to ground and pins 16 and 14 .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. . Zterm on Mac) Serial-Breadboard cable MAX3323 chip (or similar) 4 1uf capacitors Solderless breadboard Hookup wire Arduino Microcontroller Module Light emitting Diode (LED) . for debugging Prepare the breadboard Insert the MAX3323 chip in the breadboard.11 to 5V. 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. HyperTerminal or RealTerm on the PC. If you are using an LED connect it between pin 13 and ground.

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

Pick three different colors of wire. RX wire Blue. pick up a female DB9 connector from radioshack. To do this.TX wire Green. one for TX. GND wires are black Cables (DB9 Serial Connector Pin Diagram) If you do not have one already. and one for ground. RX wire to pin 3 and Ground to pin 5. +5v wires are red. Solder your TX wire to pin 2 of the DB9 connector. . 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.

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

//carriage return } void SWprint(int data) { byte mask. mask>0. byte SWval.cc #include <ctype. . //startbit digitalWrite(tx. // send 1 } else{ digitalWrite(tx. delayMicroseconds(bit9600Delay). SWprint(10). for (mask = 0x01. Upload the following code into the Arduino microcontroller module: //Created August 23 2006 //Heather Dewey-Hagborg //http://www.HIGH). 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. 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. digitalWrite(tx. //debugging hello SWprint('i'). pinMode(tx. RX wires Blue. //turn on debugging LED SWprint('h').LOW). byte tx = 7. HIGH). digitalWrite(13. // send 0 } delayMicroseconds(bit9600Delay).HIGH). +5v wires are red.INPUT).arduino. } //stop bit digitalWrite(tx.HIGH).h> #define #define #define #define bit9600Delay 84 halfBit9600Delay 42 bit4800Delay 188 halfBit4800Delay 94 byte rx = 6.OUTPUT). mask <<= 1) { if (data & mask){ // choose bit digitalWrite(tx.LOW). void setup() { pinMode(rx. GND wires are black Program the Arduino Now we will write the code to enable serial data communication. delayMicroseconds(bit9600Delay).TX wires Green.

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

photos by Thomas Dexter (Printable View of http://www.arduino. code and tutorial by Heather Dewey-Hagborg. You can now use your new serial/computer connection to print debugging statements from your code. congratulations! Your serial connection is working as planned.cc/en/Tutorial/ArduinoSoftwareRS232) . 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 .

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

SS). EEPROM pin 5 to Arduino pin 11 (Master Out Slave In).Connect EEPROM pin 1 to Arduino pin 10 (Slave Select). 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: .MOSI).MISO). MISO wire is yellow. and EEPROM pin 6 to Arduino pin 13 (Serial Clock). to: Connect EEPROM pin 1 to Arduino pin 10 (Slave Select . EEPROM pin 5 to Arduino pin 11 (Master Out Slave In . Restore August 31. 2006. EEPROM pin 2 to Arduino pin 12 (Master In Slave Out . MOSI wire is blue.SCK). EEPROM pin 2 to Arduino pin 12 (Master In Slave Out). 2006. at 01:17 PM by Heather Dewey-Hagborg Changed lines 68-69 from: to: +5v wires are red. and EEPROM pin 6 to Arduino pin 13 (Serial Clock . SCK wire is green Restore August 31.

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 . and return the data. 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). thus starting the SPI transmission. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask.127 for each index in the array. 2006. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. First we set the SLAVESELECT line low to enable the device. 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. Then we transmit a READ instruction. followed by the 16-bit address we wish to read from. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. and return the data. 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. 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). An explanation of bit masks can be found here. First we set the SLAVESELECT line low to enable the device. 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. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. Most Significant Bit first. SPIF. SPIF. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. 2006.Restore August 30. 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. An explanation of bit masks can be found here. at 11:08 AM by Heather Dewey-Hagborg Changed lines 2-3 from: (IN PROGRESS) to: Restore August 30. Then we transmit a READ instruction. followed by the 16-bit address we wish to read from. Most Significant Bit first. 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 . It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask.127 for each index in the array.

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

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

I<128. //get data byte digitalWrite(SLAVESELECT. //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. //release chip. signal end transfer return data.DEC). // 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. } } @] This function simply fills our data array with numbers 0 .Restore August 30. Serial.@] to: delay(1000).I++) { buffer[I]=I. // return the received byte } This function loads the output data into the data transmission register. char spi_transfer(volatile char data) { SPDR = data.print(eeprom_output_data. to: eeprom_output_data = read_eeprom(address). spi_transfer(READ). [@ void setup() { Changed lines 163-164 from: delay(1000).127 for each index in the array. return SPDR. digitalWrite(SLAVESELECT. }@] Changed line 169 from: byte read_eeprom(int EEPROM_address) to: void loop() Changed lines 171-179 from: //READ EEPROM int data. SPIF. The following setup function is long so we will take it in parts. An explanation of bit masks can be found here.HIGH). . This function could easily be changed to fill the array with data relevant to your application. 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. //transmit read opcode spi_transfer((char)(EEPROM_address>>8)). //send LSByte address data = spi_transfer(0xFF).LOW). 2006. thus starting the SPI transmission.

Serial. 3.print('\n'. Most Significant Bit first.127 for each index in the array. 4. Each time through the loop we increment the eeprom address to read. address++. and return the data. define define define define DATAOUT 11//MOSI DATAIN 12//MISO SPICLOCK 13//sck SLAVESELECT 10//ss //opcodes 1. 2. Each time through the loop we increment the eeprom address to read. byte eeprom_input_data=0. 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 . 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). When the address increments to 128 we turn it back to 0 because we have only filled 128 addresses in the EEPROM with data. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. int address=0.DEC). define define define define define define WREN 6 WRDI 4 RDSR 5 WRSR 1 READ 3 WRITE 2 byte eeprom_output_data. 5.print(eeprom_output_data. 3. When the address increments to 128 we turn it back to 0 because we have only filled 128 addresses in the EEPROM with data. //data buffer char buffer [128]. } Changed lines 189-193 from: Finally we get to our main loop. We add a line feed and a pause for readability. . delay(500). byte clr. 6. address++.I++) { buffer[I]=I. Serial. We add a line feed and a pause for readability.BYTE). 2. Serial.print('\n'. to: In our main loop we just read one byte at a time from the EEPROM and print it out the serial port. Then we transmit a READ instruction. //pause for readability Changed lines 178-179 from: This function allows us to read data back out of the EEPROM. Changed lines 192-212 from: 1. Finally we pull the SLAVESELECT line high again to release the device after reading one byte.BYTE). //pause for readability to: for (int I=0.I<128. delay(500). 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. 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. First we set the SLAVESELECT line low to enable the device. Changed line 181 from: void loop() to: void fill_buffer() Changed lines 183-187 from: eeprom_output_data = read_eeprom(address). 4. up to 128 times for a full page of data.

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

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

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

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

The clock pulses which synchronize data transmission generated by the master.The Master line for sending data to the peripherals. Master Out Slave In (MOSI) . such as speed or polarity. the seventh bit of the SPI status register (SPSR) gets set to 1 when a value is shifted in or out of the SPI. 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. A register is just a byte of microcontroller memory that can be read from or written to. Usually each bit in a control register effects a particular setting.The Slave line for sending data to the master.The Slave line for sending data to the master. and the data which has just been shifted in the MISO line. each of which control a particular SPI setting. It can also be used for communication between two microcontrollers. Master In Slave Out (MISO) . the SPI data register (SPDR) holds the byte which is about to be shifted out the MOSI line. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. The SPI control register (SPCR) has 8 bits.The clock pulses which synchronize data transmission generated by the master. data and status. Typically there are three lines common to all the devices. For example.allocated on each device which the master can use to enable and disable specific devices and avoid false transmissions due to line noise. and Serial Clock (SCK) . Master In Slave Out (MISO) . The SPCR has 8 bits each of which control a particular SPI setting. 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. 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.August 30. Registers generally serve three purposes. 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. 2006. control. It can also be used for communication between two microcontrollers. Now that you have a feel for how SPI works. Master Out Slave In (MOSI) . let's take a look at the EEPROM chip. For example. and Slave Select pin . 2006. to: All SPI settings are determined by the Arduino SPI Control Register (SPCR). Typically there are three lines common to all the devices. Control registers code control settings for various microcontroller functionalities. 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). Status registers change their state based on various microcontroller conditions.The Master line for sending data to the peripherals. Restore August 30. 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. . 2006. 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. Serial Clock (SCK) . Data registers simply hold bytes. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices.

3. but we won't be covering those in this tutorial. 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. and whether the clock is idle when high or low. the seventh bit enables the SPI. The SPCR has 8 bits each of which control a particular SPI setting. runs at up to 10MHz at 5v and can run at slower speeds down to 1. .3. and whether the clock is idle when high or low.The Master line for sending data to the peripherals. Instructions are 8 bit opcodes and are shifted in on the rising edge of the data clock. the fourth bit sets the data clock idle when it is low. It can also be used for communication between two microcontrollers. so a 10ms pause should follow each EEPROM write routine. Changed lines 33-35 from: The eighth bit sets the SPI interrupt. Master In Slave Out (MISO) . It supports SPI modes 0 and 3. Master Out Slave In (MOSI) . The difficult part about SPI is that the standard is loose and each device implements it a little differently. This means you have to pay special attention to the datasheet when writing your interface code. and whether the clock is idle when high or low. It takes the EEPROM about 10 milliseconds to write a page (128 bytes) of data. the third bit sets the SPI to sample data on the rising edge of the data clock. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal.536 byte serial EEPROM. 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. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). 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. and Serial Clock (SCK) . but it can be read 1-128 bytes at a time.The clock pulses which synchronize data transmission generated by the master. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal. It's memory is organized as 512 pages of 128 bytes each. 2006. to: The difficult part about SPI is that the standard is loose and each device implements it a little differently. These modes control whether data is shifted in and out on the rising or falling edge of the data clock signal. 2006.The Slave line for sending data to the master. Generally speaking there are three modes of transmission numbered 0 . It can only be written 128 bytes at a time. Restore August 29.Restore August 29. With an SPI connection there is always one master device (usually a microcontroller) which controls the peripheral devices. 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. the fifth bit puts the Arduino in Master mode. Generally speaking there are three modes of transmission numbered 0 . 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. The device is enabled by pulling the Chip Select (CS) pin low. All SPI settings are determined by the Arduino SPI Control Register (SPCR). The device also offers various degerees of write protection and a hold pin. 2006.8v.3. It can also be used for communication between two microcontrollers. Typically there are three lines common to all the devices. Restore August 29. 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. at 06:51 PM by Heather Dewey-Hagborg Added lines 46-49: The AT25HP512 is a 65.

With an SPI connection Restore August 29. and the second and first bits set the speed of the SPI to system speed / 4 (the fastest). slave mode when 0 CPOL . the sixth bit chooses transmission with the most significant bit going first or Least Significant. to: [@ byte eeprom_output_data. idle when low if set to 0 CPHA . 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. rising edge when 0 SPR1 and SPR0 . the seventh bit enables the SPI.Sets the Arduino in master mode when 1.Sets the SPI speed.SPCR | 7 | 6 | SPIE | SPE | 5 | 4 | 3 | 2 | 1 | 0 | | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 | SPIE . most Significant Bit first when 0 MSTR . the third bit sets the SPI to sample data on the rising edge of the data clock.Sets the data clock to be idle when high if set to 1.Sends data least Significant Bit First when 1. the fifth bit puts the Arduino in Master mode. 00 is fastest (4MHz) 11 is slowest (250KHz) The eighth bit sets the SPI interrupt. the fourth bit sets the data clock idle when it is low. Restore August 29. 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 . at 02:45 PM by Heather Dewey-Hagborg Changed lines 33-34 from: [@#define DATAOUT 11//MOSI to: [@ 1. 2006. define DATAOUT 11//MOSI Changed lines 51-52 from: [@byte eeprom_output_data.Samples data on the falling edge of the data clock when 1.Enables the SPI when 1 DORD . It can also be used for communication between two microcontrollers.Enables the SPI interrupt when 1 SPE . 2006.

BYTE).print('h'. 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. at 02:43 PM by Heather Dewey-Hagborg Changed lines 162-164 from: Finally we get to our main loop. to: [@ Serial. We add a line feed and a pause for readability. When the address increments to 128 we turn it back to 0 because we have only filled . 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. When the address increments to 128 we turn it back to 0 since we have only filled 128 addresses in the EEPROM with data.BYTE). Each time through the loop we increment the eeprom address to read. to: Finally we get to our main loop.print('h'. 2006. Each time through the loop we increment the eeprom address to read. Changed lines 139-140 from: [@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: [@ delay(10). 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.

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

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

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

Serial. Pre-processor directives are processed before the actual compilation begins. SPICLOCK and SLAVESELECT.DEC). Opcodes are control commands. byte eeprom_output_data. DATAOUT. signal end transfer return data. First we define the pins we will be using for our SPI connection. //get data byte digitalWrite(SLAVESELECT. #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. address++.LOW). delay(500). . Serial. In the main loop it reads that data back out.print('i'. } void loop() { eeprom_output_data = read_eeprom(address). //send MSByte address first spi_transfer((char)(EEPROM_address)). //pause for readability } Restore August 29. one byte at a time and prints that byte out the built in serial port. 2006. } byte read_eeprom(int EEPROM_address) { //READ EEPROM int data. We will walk through the code in small sections.BYTE).//debug delay(1000). Serial. or one page of the EEPROM with data.HIGH). byte eeprom_input_data=0.BYTE).HIGH). spi_transfer(READ). They start with a "#" and do not end with semi-colons. Then we define our opcodes for the EEPROM. //release chip.print(eeprom_output_data. //send LSByte address data = spi_transfer(0xFF).print('h'.print('\n'.BYTE). Serial. //transmit read opcode spi_transfer((char)(EEPROM_address>>8)). 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. digitalWrite(SLAVESELECT. //release chip //wait for eeprom to finish writing delay(3000).{ spi_transfer(buffer[I]). In the setup routine this program fills 128 bytes. //write data byte } digitalWrite(SLAVESELECT. if (address == 128) address = 0. DATAIN.print('\n'.BYTE). Serial.

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

Materials Needed: 1.Restore August 27. 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. and the steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. EEPROM chips such as this are very useful for data storage. 2006. 2006. Arduino Microcontroller Module Serial Peripheral Interface Restore Edit Page | Page History | Printable View | All Recent Site Changes . Hookup wire 3. 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. AT25HP512 Serial EEPROM chip (or similar) 2.

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. A register is just a byte of microcontroller memory that can be read from or written to. The SPI control register (SPCR) has 8 bits. idle when low if set to 0 . Data registers simply hold bytes. It can also be used for communication between two microcontrollers. EEPROM chips such as this are very useful for data storage.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. Registers generally serve three purposes.Sets the data clock to be idle when high if set to 1.The clock pulses which synchronize data transmission generated by the master. and the steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. data and status. 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. For example. For example. most Significant Bit first when 0 MSTR . and the data which has just been shifted in the MISO line. Serial Clock (SCK) . slave mode when 0 CPOL . each of which control a particular SPI setting. the seventh bit of the SPI status register (SPSR) gets set to 1 when a value is shifted in or out of the SPI.The Slave line for sending data to the master.3. so follow this tutorial only if you need more space than it provides.Sends data least Significant Bit First when 1. Typically there are three lines common to all the devices. The difficult part about SPI is that the standard is loose and each device implements it a little differently. Note that the chip on the Arduino board contains an internal EEPROM. Status registers change their state based on various microcontroller conditions. control.Enables the SPI when 1 DORD .allocated on each device which the master can use to enable and disable specific devices and avoid false transmissions due to line noise. the SPI data register (SPDR) holds the byte which is about to be shifted out the MOSI line. such as speed or polarity. All SPI settings are determined by the Arduino SPI Control Register (SPCR). and Slave Select pin . Usually each bit in a control register effects a particular setting. 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. Generally speaking there are three modes of transmission numbered 0 . Master Out Slave In (MOSI) . This means you have to pay special attention to the datasheet when writing your interface code. Control registers code control settings for various microcontroller functionalities.The Master line for sending data to the peripherals. Master In Slave Out (MISO) . SPCR | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | | SPIE | SPE | DORD | MSTR | CPOL | CPHA | SPR1 | SPR0 | SPIE .Enables the SPI interrupt when 1 SPE .

Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. 7 and 8 to 5v and pin 4 to ground. 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. let's take a look at the details of the EEPROM chip. It's memory is organized as 512 pages of 128 bytes each. . but it can be read 1-128 bytes at a time. It can only be written 128 bytes at a time. so a 10ms pause should follow each EEPROM write routine.Sets the SPI speed. Now that you have a feel for how SPI works. but we won't be covering those in this tutorial. runs at up to 10MHz at 5v and can run at slower speeds down to 1. Instructions are sent as 8 bit operational codes (opcodes) and are shifted in on the rising edge of the data clock. The device also offers various degerees of write protection and a hold pin. rising edge when 0 SPR1 and SPR0 . It supports SPI modes 0 and 3. Prepare the Breadboard Insert the AT25HP512 chip into the breadboard.Samples data on the falling edge of the data clock when 1. Connect EEPROM pins 3. The device is enabled by pulling the Chip Select (CS) pin low. It takes the EEPROM about 10 milliseconds to write a page (128 bytes) of data.8v. Introduction to Serial EEPROM The AT25HP512 is a 65.CPHA .536 byte serial EEPROM.

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

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

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

delay(10). //disable device // SPCR = 01010000 //interrupt disabled. delay(10). clr=SPSR. INPUT).//READ EEPROM int data. pinMode(SLAVESELECT. digitalWrite(SLAVESELECT.clk low when idle. //fill eeprom w/ buffer digitalWrite(SLAVESELECT.I<128.msb 1st. //sample on leading edge of clk.LOW).OUTPUT).begin(9600). spi_transfer(WREN). } } char spi_transfer(volatile char data) { SPDR = data. signal end transfer return data. //data buffer char buffer [128]. //fill buffer with data fill_buffer(). // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. pinMode(SPICLOCK.LOW). digitalWrite(SLAVESELECT. //write enable digitalWrite(SLAVESELECT. //release chip. // return the received byte } void setup() { Serial. spi_transfer(WRITE). digitalWrite(SLAVESELECT. spi_transfer(READ). //get data byte digitalWrite(SLAVESELECT. //send LSByte address data = spi_transfer(0xFF). int address=0. //send LSByte address //write 128 bytes . clr=SPDR. byte clr. spi_transfer((char)(address>>8)).I++) { buffer[I]=I. OUTPUT). pinMode(DATAOUT.HIGH). void fill_buffer() { for (int I=0. return SPDR. //write instruction address=0. byte eeprom_input_data=0.system clock/4 rate (fastest) SPCR = (1<<SPE)|(1<<MSTR).master. pinMode(DATAIN.spi enabled.OUTPUT).LOW).HIGH). //transmit read opcode spi_transfer((char)(EEPROM_address>>8)). } 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. //send MSByte address first spi_transfer((char)(address)). //send MSByte address first spi_transfer((char)(EEPROM_address)).HIGH).

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

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

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. 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. at 09:22 AM by Heather Dewey-Hagborg Changed lines 7-10 from: PICTURE pins PICTURE pin functions to: .

.

Restore September 05. This makes room to add the resistance value which occupies the least significant eight bits of the data byte. 2006. at 03:07 PM by Heather Dewey-Hagborg Restore September 05. 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. 2006. at 03:11 PM by Heather Dewey-Hagborg Added lines 130-131: VIDEO ? LEDs Restore September 05.

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

milliseconds each iteration to make the steps visible. An explanation of bit masks can be found here. 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. 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. This makes room to add the resistance value which occupies the least significant eight bits of the data byte. We set the SLAVSELECT line high again to release the chip and signal the end of our data transfer. //send MSByte address first a0a1a2d0d1d2d3d4 . When we sum the two together we get our 11 bit opcode to transmit: byte write_pot(int address. digitalWrite(SLAVESELECT. to: write_pot(pot. // 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. delay(10). // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. 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. address<<=8. int value) { int opcode=0. } Added lines 102-205: @] The spi_transfer function loads the output data into the data transmission register. return SPDR. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. } if (pot==6) { pot=0. resistance++. 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.resistance). ie.LOW). //10111111111 We set the SLAVESELECT line low to enable the device. return SPDR. //2 byte opcode spi_transfer((char)(opcode>>8)). 101 = 10100000000 opcode = address+value. if (resistance==255) { pot++. while (!(SPSR & (1<<SPIF))) { }. thus starting the SPI transmission. //shift pot address 8 left. SPIF.

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

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

14. and they can be interfaced with just as you would use a mechanical potentiometer. at 01:59 PM by Heather Dewey-Hagborg Changed lines 11-12 from: The AD5206 is a 6 channel digital potentiometer. 11. The data clock is idle when low. Added lines 26-52: Finally. The device is enabled by pulling the Chip Select (CS) pin low. The data clock is idle when 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. so we don't need to worry about pre-scaling to slow down the transmission. This means it has six variable resistors built in for individual electronic control. to: The AD5206 is digitally controlled using SPI. or flat side of the LED connects to ground. 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. This program will sequentially pulse each LED on and then fade it out gradually. The device is enabled by pulling the Chip Select (CS) pin low. Although we are not reading any data back out of the AD5206 in this program. Prepare the Breadboard . B1 and W1. ie. DATAIN. We define the pins we will be using for our SPI connection. The data clock is idle when low. and the interface runs much faster than the Arduino. so we don't need to worry about pre-scaling to slow down the transmission. PICTURE leds Program the Arduino Now we will write the code to enable SPI control of the AD5206. The individual variable resistor pins are labeled Ax. to: The AD5206 is a 6 channel digital potentiometer. 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. so we don't need to worry about pre-scaling to slow down the transmission. and the interface runs much faster than the Arduino. 2006. 20 and 23) and ground so that the long pin of the LED connects to the wiper and the short pin. 17. connect an LED between each Wiper pin (AD5206 pins 2.to: The AD5206 is digitally controlled using SPI. This means it has six variable resistors built in for individual electronic control. Restore September 05. Changed lines 15-25 from: The AD5206 is digitally controlled using standard SPI. SPICLOCK and SLAVESELECT. 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. and the interface runs much faster than the Arduino. 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 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.not used. 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. Bx and Wx. There are three pins on the chip for each of the six internal variable resistors. byte resistance=0. We will walk through the code in small sections. A1. DATAOUT. 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. In this example we will use a six channel digital potentiometer to control the brightness of six LEDs. and the interface runs up to speeds of 100Mhz. Digital potentiometers are useful when you need to vary the resistance in a ciruit electronically rather than by hand. The data clock is idle when low. The AD5206is controlled using standard SPI. pulling another side pin (pin A) low and taking the variable voltage output of the center pin (Wiper). The device is enabled by pulling the Chip Select (CS) pin low. 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). audio signal conditioning and tone generation. Example applications include LED dimming. at 01:30 PM by Heather Dewey-Hagborg Changed line 15 from: The AD5206is controlled using standard SPI. Introduction to the AD5206 Digital Potentiometer PICTURE pins PICTURE pin functions The AD5206 is a 6 channel digital potentiometer.MOSI). 9. 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. 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. to: The AD5206 is digitally controlled using standard SPI. to: The AD5206 is digitally controlled using standard SPI. in this tutorial we will be using each variable resistor as a voltage divider by pulling one side pin (pin B) high. PICTURE power Connect AD5206 pin 5 to Arduino pin 10 (Slave Select .Insert the AD5206 chip into the breadboard. 15. The steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. Connect AD5206 pins 3. and the interface runs up to speeds of 100Mhz. The device is enabled by pulling the Chip Select (CS) pin low. For example. 2006. 13. 12. 6.SCK). The data clock is idle when low. 4. 10. 16. The data clock is idle when low. The device is enabled by pulling the Chip Select (CS) pin low. 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. AD5206 pin 7 to Arduino pin 11 (Master Out Slave In . 2006. This means it has six variable resistors built in for individual electronic control. 21 and 24 to 5v and pins 1. 19. Restore September 05. and 22 to ground. and AD5206 pin 8 to Arduino pin 13 (Serial Clock . and the interface runs much faster than the Arduino. The device is enabled by pulling the Chip Select (CS) pin low.SS). We are connecting all the A pins to ground and all of the B pins to 5v to create 6 voltage dividers. Restore Edit Page | Page History | Printable View | All Recent Site Changes . Connect 5V power and ground from the breadboard to 5V power and ground from the microcontroller. Restore September 05. There are three pins on the chip for each of the six internal variable resistors. 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. 18. Instructions are sent as 8 bit operational codes (opcodes) and are shifted in on the rising edge of the data clock. 2006. PICTURE datacom Restore September 05. and they can be interfaced with just as you would use a mechanical potentiometer. at 01:34 PM by Heather Dewey-Hagborg Changed line 15 from: The AD5206 is digitally controlled using standard SPI.

.

Digital potentiometers are useful when you need to vary the resistance in a ciruit electronically rather than by hand.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). In this example we will use a six channel digital potentiometer to control the brightness of six LEDs. 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. For an explanation of SPI see the SPI EEPROM tutorial. audio signal conditioning and tone generation. Example applications include LED dimming.

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. There are three pins on the chip for each of the six internal variable resistors. and they can be interfaced with just as you would use a mechanical potentiometer. Bx and Wx. This means it has six variable resistors (potentiometers) built in for individual electronic control. The AD5206 is digitally controlled using SPI. in this tutorial we will be using each variable resistor as a voltage divider by pulling one side pin (pin B) high. B1 and W1. Data is shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. pulling another side pin (pin A) low and taking the variable voltage output of the center pin (Wiper). For example. The individual variable resistor pins are labeled Ax. A1. The device is enabled by pulling the Chip Select (CS) pin low.The AD5206 is a 6 channel digital potentiometer. . ie.

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

SPICLOCK and SLAVESELECT. First we set our input and output pin modes and set the SLAVESELECT line high to start. the sixth bit chooses transmission with the most significant bit going first. In the control register each bit sets a different functionality. INPUT). digitalWrite(SLAVESELECT. OUTPUT). 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. the fourth bit sets the data clock idle when it is low. byte resistance=0.OUTPUT). 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: . and the second and first bits set the speed of the SPI to system speed / 4 (the fastest).HIGH). Although we are not reading any data back out of the AD5206 in this program. the fifth bit puts the Arduino in Master mode.Program the Arduino Now we will write the code to enable SPI control of the AD5206. //disable device Now we set the SPI Control register (SPCR) to the binary value 01010000. pinMode(DATAIN. DATAOUT. the third bit sets the SPI to sample data on the rising edge of the data clock. pinMode(SLAVESELECT. This deselects the device and avoids any false transmission messages due to line noise: void setup() { byte clr. pinMode(DATAOUT. DATAIN. 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 program will sequentially pulse each LED on and then fade it out gradually. We will walk through the code in small sections. We define the pins we will be using for our SPI connection. pinMode(SPICLOCK. 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 eighth bit disables the SPI interrupt. the seventh bit enables the SPI.OUTPUT).not used.

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

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

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

1). i--) { digitalWrite(myClockPin. if ( myDataOut & (1<<i) ) { pinState= 1. //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. 0).digitalWrite(myClockPin. for (i=7.. } Edit Page | Page History | Printable View | All Recent Site Changes . 0). } else { pinState= 0. i>=0. 0).. pinState). 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. } //stop shifting digitalWrite(myClockPin. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. 0). //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin. //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.

j++) { lightShiftPinA(j). One By One // // Author : Carlyn Maw. void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin.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. //Pin connected to SH_CP of 74HC595 int clockPin = 12. OUTPUT). delay(1000). delay(1000).500). j++) { lightShiftPinB(j).500). // light each pin one by one using a function A for (int j = 0. 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. } blinkAll(2. //holder for infromation you're going to pass to shifting function byte data = 0. 2006 // // Version : 1. // light each pin one by one using a function A for (int j = 0. Tom Igoe // // Date : 25 Oct. j < 8. } } //This function uses bitwise math to move the pins up void lightShiftPinA(int p) { . ////Pin connected to DS of 74HC595 int dataPin = 11. } void loop() { //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll(1.

digitalWrite(myClockPin. int pinState. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. x < p. //start with the pin = 1 so that if 0 is passed to this //function pin 0 will light. 0). //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. 0). } //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. x++) { pin = pin * 2. . 0). //on the rising edge of the clock. byte myDataOut) { // This shifts 8 bits out MSB first. pinMode(myClockPin. //move 'em out shiftOut(dataPin. clockPin. 0). pinMode(myDataPin. //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin. //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. //this is line uses a bitwise operator //shifting a bit left using << is the same //as multiplying the decimal number by two. pin = 1<< p. //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. //clock idles low //internal function setup int i=0. pin). clockPin. //move 'em out shiftOut(dataPin. for (int x = 0. pin). OUTPUT).//defines a local variable int pin. 1). 1). OUTPUT). pin = 1. } //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. int myClockPin. } // the heart of the program void shiftOut(int myDataPin.

shiftOut(dataPin. //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin. clockPin. 255). if ( myDataOut & (1<<i) ) { pinState= 1. delay(d). delay(d). digitalWrite(latchPin. 1).. 0). delay(200). for (int x = 0. clockPin. i>=0. 0). clockPin. x++) { digitalWrite(latchPin. pinState). } //stop shifting digitalWrite(myClockPin. 1). 1).for (i=7. int d) { digitalWrite(latchPin. digitalWrite(latchPin. void blinkAll(int n. digitalWrite(latchPin. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin.. digitalWrite(latchPin. 0). shiftOut(dataPin. //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. 0). 0). 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. 0). 1). } else { pinState= 0. shiftOut(dataPin. } //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. 0). x < n. } } Edit Page | Page History | Printable View | All Recent Site Changes . 0). i--) { digitalWrite(myClockPin. //if the value passed to myDataOut and a bitmask result // true then.

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

//clock idles low //internal function setup int i=0. 0). pinMode(myDataPin. } } // the heart of the program void shiftOut(int myDataPin. 1). for (i=7.. //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. digitalWrite(myClockPin. i>=0. 1). pinState). int pinState. //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin. //if the value passed to myDataOut and a bitmask result // true then. //on the rising edge of the clock. if ( myDataOut & (1<<i) ) { pinState= 1. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. OUTPUT). } //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. i--) { digitalWrite(myClockPin. data). 0).//move 'em out shiftOut(dataPin. delay(1000). 0). //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin. //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. } else { pinState= 0. 0). clockPin. int myClockPin. 0). int d) { digitalWrite(latchPin. byte myDataOut) { // This shifts 8 bits out MSB first. 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. . pinMode(myClockPin. } //stop shifting digitalWrite(myClockPin. void blinkAll(int n. 0).. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. OUTPUT).

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

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

pinMode(myDataPin. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. //clear everything out just in case to . i>=0. digitalWrite(myClockPin.. 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. //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. //prepare shift register for bit shifting digitalWrite(myDataPin. pinState). 0). 0). } else { pinState= 0. } //stop shifting digitalWrite(myClockPin. //if the value passed to myDataOut and a bitmask result // true then. //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin. if ( myDataOut & (1<<i) ) { pinState= 1. for (i=7. //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. } Edit Page | Page History | Printable View | All Recent Site Changes . 0). 1). OUTPUT).. i--) { digitalWrite(myClockPin. 0). 0). .

//holder for infromation you're going to pass to shifting function byte data = 0. OUTPUT). } void loop() { //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll_2Bytes(1. j < 8. . 0). //Pin connected to SH_CP of 74HC595 int clockPin = 12. } // light each pin one by one using a function A for (int j = 0. j++) { //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. //red LEDs lightShiftPinA(7-j). // void setup() { //set pins to output because they are addressed in the main loop pinMode(latchPin. Dual One By One // Author : Carlyn Maw. // light each pin one by one using a function A for (int j = 0.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. 2006 // // Version : 1. j++) { //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. ////Pin connected to DS of 74HC595 int dataPin = 11. //green LEDs lightShiftPinA(j). j < 8. delay(1000).500). 0). Tom Igoe // // Date : 25 Oct. 1).

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

//if the value passed to myDataOut and a bitmask result // true then. void blinkAll_2Bytes(int n. 1). x++) { digitalWrite(latchPin. } } Edit Page | Page History | Printable View | All Recent Site Changes . clockPin. shiftOut(dataPin. 0). 255). clockPin. clockPin. delay(d). 0). shiftOut(dataPin. //register shifts bits on upstroke of clock pin digitalWrite(myClockPin. digitalWrite(latchPin. 1). 255). 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. digitalWrite(latchPin. 0). 0). 0). clockPin. shiftOut(dataPin. for (i=7. clockPin..//This means that %00000001 or "1" will go through such //that it will be pin Q0 that lights. 0). } //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. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. int d) { digitalWrite(latchPin. delay(d). } //stop shifting digitalWrite(myClockPin. shiftOut(dataPin. 0). if ( myDataOut & (1<<i) ) { pinState= 1. clockPin. digitalWrite(latchPin. for (int x = 0. 1). i>=0. x < n. delay(200). digitalWrite(latchPin. 0). } else { pinState= 0. shiftOut(dataPin. shiftOut(dataPin. pinState). 1). 0). i--) { digitalWrite(myClockPin.. 0). //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin.

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

i>=0.. //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin.. } void loop() { for (int j = 0. i--) { digitalWrite(myClockPin. } } // the heart of the program void shiftOut(int myDataPin. OUTPUT). if ( myDataOut & (1<<i) ) { pinState= 1. shiftOut(dataPin. //clear everything out just in case to //prepare shift register for bit shifting digitalWrite(myDataPin. j < 10. int myClockPin. dataRED). pinMode(myClockPin. clockPin. int pinState. byte myDataOut) { // This shifts 8 bits out MSB first. digitalWrite(myClockPin. 1). 0). pinMode(myDataPin. //clock idles low //internal function setup int i=0. delay(300). 0). pinState). //move 'em out shiftOut(dataPin. j++) { //load the light sequence you want from array dataRED = dataArrayRED[j]. clockPin. } //Sets the pin to HIGH or LOW depending on pinState digitalWrite(myDataPin. for (i=7. //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. //on the rising edge of the clock. OUTPUT). //if the value passed to myDataOut and a bitmask result // true then. 0). 0).500). } else { pinState= 0. //00000111 //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll_2Bytes(2.dataArrayGREEN[9] = 0x07. dataGREEN). dataGREEN = dataArrayGREEN[j]. . //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin.

} //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. 0). clockPin. clockPin. 255). shiftOut(dataPin. 255). 1). digitalWrite(latchPin. delay(d). 0). clockPin. 0). 1). shiftOut(dataPin. //zero the data pin after shift to prevent bleed through digitalWrite(myDataPin. clockPin. } } Edit Page | Page History | Printable View | All Recent Site Changes . 0). delay(200). 1). shiftOut(dataPin. clockPin.//register shifts bits on upstroke of clock pin digitalWrite(myClockPin. for (int x = 0. shiftOut(dataPin. x < n. int d) { digitalWrite(latchPin. x++) { digitalWrite(latchPin. digitalWrite(latchPin. 0). shiftOut(dataPin. delay(d). clockPin. 0). 1). 0). 0). } //stop shifting digitalWrite(myClockPin. digitalWrite(latchPin. shiftOut(dataPin. digitalWrite(latchPin. 0). void blinkAll_2Bytes(int 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 .

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

Added lines 124-127: Circuit Diagram .

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

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

you can’t set pins to their high impedance state individually. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. Changed lines 90-97 from: 595 Timing Diagram 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. The second program lights one LED at a time. the shift register reads the state of the data pin. you can’t set pins to their high impedance state individually. When the clockPin goes from low to high. Neither example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it.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. This is a pretty specialized thing to do -. 2006. low or “high impedance. 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. low or “high impedance. The second program lights one LED at a time.” Unlike the HIGH and LOW states. 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. As the data gets shifted in it is saved in an internal memory register. The logic table is what tells you that basically everything important happens on an up beat. The logic table is what tells you that basically everything important happens on an up beat.” Unlike the HIGH and LOW states. You can only set the whole chip together. lighting the LEDs.Restore November 09. the shift register reads the state of the data pin. The third cycles through an array. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. Niether example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. As the data gets shifted in it is saved in an internal memory register. lighting the LEDs. to: “3 states” refers to the fact that you can set the output pins as either high. 2006. Added lines 96-97: . 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.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. at 03:07 PM by Carlyn Maw Restore November 09. When the clockPin goes from low to high. 2006. The third cycles through an array. at 03:07 PM by Carlyn Maw Added lines 87-88: Here are three code examples. This is a pretty specialized thing to do -.

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

595 Logic Table 595 Logic Table .

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

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

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

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. and the anode (long pin) of each LED to its respective shift register output pin. Deleted lines 108-109: Added lines 112-113: . you should put a second shift register on the board. It should have the same leads to power and ground. 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. Some shift registers won't supply power. Deleted lines 107-108: Starting from the previous example. Deleted lines 80-81: In this case you should connect the cathode (short pin) of each LED to a common ground. and the anode (long pin) of each LED to its respective shift register output pin. you should put a second shift register on the board. Added lines 104-105: Starting from the previous example. It should have the same leads to power and ground. 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. You should check the your specific datasheet if you aren’t using a 595 series chip.

at 02:41 PM by Carlyn Maw Changed line 18 from: (:cell rowspan=9 :) to: . 2006.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. at 02:41 PM by Carlyn Maw Restore November 09.

(: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.

2006.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.

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

Added lines 104-105: .

Added lines 109-110: Added lines 115-117: Attach:Exmp2_3. 2006. 2006.gif Δ Restore November 09. at 02:08 PM by Carlyn Maw Changed lines 15-17 from: Here is a table explaining the pin-outs adapted from the 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 . (:table border=1 bordercolor=#CCCCCC cellpadding=5 cellspacing=0:) Restore November 09. (:table border=1 cellpadding=5 cellspacing=0:) to: Here is a table explaining the pin-outs adapted from the Phillip's datasheet.

” Unlike the HIGH and LOW states. 2006. low or “high impedance.(: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. Niether example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. low or “high impedance. This is a pretty specialized thing to do -. 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. 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. 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. You can only set the whole chip together. 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. 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’t set pins to their high impedance state individually.” Unlike the HIGH and LOW states. This is a . you can’t set pins to their high impedance state individually. (:cell rowspan=9 :) Vss (:cellnr:) PIN 8 (:cell:) GND (:cell:) Ground.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. 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.

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

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

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

Starting from the previous example. dataArrayRED. Add a second shift register. Code Sample 2.1 – Dual Binary Counters to: Code Sample 2. Tom Igoe to: Started by Carlyn Maw and Tom Igoe Nov. Restore November 01. dataGREEN = dataArrayGREEN[j].1 – Dual Binary Counters\\ Added lines 75-97: Code Sample 2. 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.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. 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. 06 Changed line 73 from: Code Sample 2. dataGREEN). the one directly attached to the Arduino. you should put a second shift register on the board. becomes dataRED = dataArrayRED[j]. at 06:45 PM by Carlyn Maw Changed lines 3-4 from: Carlyn Maw. and shiftOut(dataPin. clockPin.November 01. Here they need to be moved back into the main loop to accommodate needing to run each subfunction twice in a row. dataArrayGREEN defined up front. If you are curious. 2006. dataRED). at 06:41 PM by Carlyn Maw Added lines 53-74: Example 2 The Circuit 1.Dual Defined Arrays 2. you might want to try the samples from the first example with this circuit set up just to see what happens. 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. Code Sample 2. once for the green LEDs and once for the red ones. data). This forces the first shift register.3 also takes advantage of the new blinkAll_2bytes() function. a dataGREEN. This means that later on line data = dataArray[j]. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires). 2006. Connect the 2 registers. Add a second set of LEDs. It should have the same leads to power and ground. to pass . 2. 3. clockPin.3 .1 – Dual Binary Counters There is only one extra line of code compared to the first code sample from Example 1. Its big difference from 1. shiftOut(dataPin. 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. becomes shiftOut(dataPin. Also. in version 1 the pulsings of the latchPin were situated inside the subfunctions lightShiftPinA and lightShiftPinB().

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

you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. You can learn to do that from the second example. This is in contrast using the “asynchronous serial communication” of the Serial. Notice the 0. to: I’m going to refer to them from now on as the dataPin. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. The Circuit 1. for example. it will output whatever voltage you have connected to the Vcc pin. 2006. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. you can only set the whole chip together. so you don’t need to spend a lot of time on it now. 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. This is the “parallel output” part. Unlike the HIGH and LOW states. 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. Example 1: One Shift Register The first step is to extend your Arduino with one shift register. Neither example takes advantage of this feature. a second register attached in parallel to the original circuit you could do so without competition. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. The datasheet refers to the 74HC595 as an “8-bit serial-in. 2006. This example is based on the 74HC595. you can’t set pins to their high impedance state individually.e. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. 3-state. How this all works is through something called “synchronous serial communication. 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. >>>>>>> to: This set up makes all of the output pins active and addressable all the time. Restore November 01. that you delineate between bits. the shift register isn’t actively set to either a high or low voltage. Notice the 0. Notice the 0. 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. When a pin is in a high impedance state. the clockPin and the latchPin respectively. 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.” In other words.” When you set a pin set high by sending a 1 bit to that address. Restore November 01. low or “high impedance. serial or parallel-out shift register with output latches.1µf capacitor on the latchPin. 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.From now on those will be refered to as the dataPin. 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 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 clockPin and the latchPin respectively.1µf capacitor on the latchPin. the clock pin. Turning it on Make the following connections: GND (pin 8) to ground. 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.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate.1µf capacitor on the latchPin. You can link multiple registers together to extend your output even more. 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. 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. ======= At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out.” i. When you set low it will output zero volts (Vss). and it is a pretty specialized thing to do. Its by pulsing second pin. the clockPin and the latchPin respectively.

Example 1: One Shift Register The first step is to extend your Arduino with one shift register. When you set low it will output zero volts (Vss). 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. 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. This is the “parallel output” part. a second register attached in parallel to the original circuit you could do so without competition. The Circuit 1. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. How this all works is through something called “synchronous serial communication. you can only set the whole chip together. that you delineate between bits.the program starts to run. 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. the clock pin. serial or parallel-out shift register with output latches. at 06:13 PM by Carlyn Maw Added lines 2-4: by Carlyn Maw Deleted line 6: <<<<<<< Restore November 01. Turning it on . You can link multiple registers together to extend your output even more. Notice the 0.” In other words. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. 2. 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. the clockPin and the latchPin respectively. to: This set up makes all of the output pins active and addressable all the time. you can’t set pins to their high impedance state individually.e. 2006. low or “high impedance. When a pin is in a high impedance state. having all the pins do what you want them to do all at once. Restore November 01. 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. so you don’t need to spend a lot of time on it now. 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. The 3 states refers to the fact that you can set the output pins as either high. ======= At sometime or another you may run out of pins on your Arduino board and need to extend it with shift registers. Neither example takes advantage of this feature. it will output whatever voltage you have connected to the Vcc pin. for example. You can learn to do that from the second example. but this will work and leave you with more open pins.” i. Unlike the HIGH and LOW states. 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. 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. 2006. 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.” When you set a pin set high by sending a 1 bit to that address. The datasheet refers to the 74HC595 as an “8-bit serial-in. Think of an LED array that might need to be controlled by different microcontrollers depending on a mode built into your project. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. Its by pulsing second pin. and it is a pretty specialized thing to do. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate. This example is based on the 74HC595.1µf capacitor on the latchPin. 3-state. You can get around this by also controlling the MR and OE pins from your Arduino board.

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.” i. for example. 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. low or “high impedance. that you delineate between bits. This is in contrast using the “asynchronous serial communication” of the Serial. The datasheet refers to the 74HC595 as an “8-bit serial-in. Turning it on Make the following connections: GND (pin 8) to ground. Its by pulsing second 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 learn to do that from the second example. serial or parallel-out shift register with output latches. You can link multiple registers together to extend your output even more. Neither example takes advantage of this feature. 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. The 3 states refers to the fact that you can set the output pins as either high. You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. How this all works is through something called “synchronous serial communication. 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. and it is a pretty specialized thing to do. the clock pin. Unlike the HIGH and LOW states. 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 Circuit 1.” In other words. the shift register isn’t actively set to either a high or low voltage. you can’t set pins to their high impedance state individually. you can only set the whole chip together. When a pin is in a high impedance state. Restore Edit Page | Page History | Printable View | All Recent Site Changes . you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. having all the pins do what you want them to do all at once. 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. This is the “parallel output” part.” When you set a pin set high by sending a 1 bit to that address. 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. 2006. Restore November 01. >>>>>>> Restore November 01. 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.Make the following connections: GND (pin 8) to ground. so you don’t need to spend a lot of time on it now. it will output whatever voltage you have connected to the Vcc pin. This example is based on the 74HC595. 3-state. a second register attached in parallel to the original circuit you could do so without competition. 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.e. 2006. 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 low it will output zero volts (Vss).begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate.

.

Neither example takes advantage of this feature and you won’t usually need to worry about getting a chip that has it. It's by pulsing second pin. low or “high impedance. 3-state. This is in contrast to using the “asynchronous serial communication” of the Serial. 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. Here is a table explaining the pin-outs adapted from the Phillip's datasheet. there are many. 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.” i. The STP16C596 for example will drive 16 LED's and eliminates the series resistors with built-in constant current sources. active low Serial data input Positive supply voltage . This is the “parallel output” part.” Unlike the HIGH and LOW states.e.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 learn to do that from the second example. 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. You can only set the whole chip together.) How this all works is through something called “synchronous serial communication.” 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. active low Shift register clock pin Storage register clock pin (latch pin) Output enable. 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. The datasheet refers to the 74HC595 as an “8-bit serial-in. This is a pretty specialized thing to do -. the clock pin. you can’t set pins to their high impedance state individually.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 example is based on the 74HC595. having all the pins do what you want them to do all at once. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. “3 states” refers to the fact that you can set the output pins as either high. Vss Serial Out Master Reclear.begin() function which relies on the sender and the receiver to be set independently to an agreed upon specified data rate. PINS 1-7. that you delineate between bits. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit. serial or parallel-out shift register with output latches. (Users may also wish to search for other driver chips with "595" or "596" in their part numbers.

Example 1: One Shift Register The first step is to extend your Arduino with one shift register. 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. . The Circuit 1. 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. You can get around this by controlling the MR and OE pins from your Arduino board too. Turning it on Make the following connections: GND (pin 8) to ground. 2. 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.1µf capacitor on the latchPin. Notice the 0. 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.

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. Using the shift register to supply power like this is called sourcing current. and the anode (long pin) of each LED to its respective shift register output pin. If you have one of those it means you will have to flip the direction of the LEDs. You should check the your specific datasheet if you aren’t using a 595 series chip. Circuit Diagram . Some shift registers can't source current. Don’t forget to add a 220-ohm resistor in series to protect the LEDs from being overloaded.3. In this case you should connect the cathode (short pin) of each LED to a common ground.

The first is just some “hello world” code that simply outputs a byte value from 0 to 255. doubling the number of output pins you have while still using the same number of pins from the Arduino. The second program lights one LED at a time. Add a second shift register. the shift register reads the state of the data pin.The Code Here are three code examples. 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. 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. lighting the LEDs. When the clockPin goes from low to high.1 – Hello World Code Sample 1. 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. The Circuit 1.2 – One by One Code Sample 1. As the data gets shifted in it is saved in an internal memory register. .

Starting from the previous example. In this case I added green ones so when reading the code it is clear which byte is going to which set of LEDs . Add a second set of LEDs. 3. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires). 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. you should put a second shift register on the board. Connect the 2 registers. It should have the same leads to power and ground.

Circuit Diagram .

to pass the first byte sent through to the second register. This forces the first shift register. It sends out a second byte. Here they need to be moved back into the main loop to accommodate needing to run each . the one directly attached to the Arduino. you might want to try the samples from the first example with this circuit set up just to see what happens. The blinkAll() function has been changed to the blinkAll_2Bytes() function to reflect the fact that now there are 16 LEDs to control. If you are curious. Code Sample 2. The second byte will then show up on the red LEDs. in version 1 the pulsings of the latchPin were situated inside the subfunctions lightShiftPinA and lightShiftPinB(). Also.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. lighting the green LEDs. Code Sample 2.The Code Here again are three code samples.

shiftOut(dataPin.Dual Defined Arrays Like sample 2.cc/en/Tutorial/ShiftOut) .3 .3's big difference from sample 1. dataGREEN). dataRED). clockPin. This means that line data = dataArray[j]. data). clockPin. becomes dataRED = dataArrayRED[j]. dataArrayRED. Code Sample 2. (Printable View of http://www.subfunction twice in a row.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. and shiftOut(dataPin.arduino.2. sample 2. 2. dataArrayGREEN defined up front. clockPin. becomes shiftOut(dataPin. dataGREEN = dataArrayGREEN[j]. once for the green LEDs and once for the red ones. a dataGREEN.

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

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

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

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

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.igoe at gmail.A through F: house code values. 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) .

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 .

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

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

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

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

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

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

Code #include <EEPROM.write(addr.h> // the current address in the EEPROM (i. Mellis Added lines 1-40: 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. EEPROM. addr = addr + 1. // these values will remain there when the board is // turned off.Show changes to markup May 21. if (addr == 512) . so go back to 0 when we hit 512.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. there are 512 bytes in // the EEPROM. Mellis Changed lines 40-46 from: @] to: @] See also EEPROM Clear example EEPROM Read example EEPROM library reference Restore May 21. // write the value to the appropriate byte of the EEPROM.e. at 09:30 PM by David A. These values will stay in the EEPROM when the board is turned off and may be retrieved later by another sketch. 2008. 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. val). at 09:33 PM by David A.EEPROMWrite History Hide minor edits . // advance to the next address. 2008. int val = analogRead(0) / 4.

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

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

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

} void loop() { // get the sensor value int val = analogRead(0).// create an instance of the stepper class. } Restore Edit Page | Page History | Printable View | All Recent Site Changes . // remember the previous value of the sensor previous = val. 8. // 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. 9.previous).setSpeed(30). 11). specifying // the number of steps of the motor and the pins it's // attached to Stepper stepper(STEPS. void setup() { // set the speed of the motor to 30 RPMs stepper.step(val .

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

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

at 09:22 PM by David A. Restore April 29. EEPROM Write: stores values from an analog input to the EEPROM.moving the resources to the links page. Mellis . Added line 15: BlinkWithoutDelay: blinking an LED without using the delay() function. to: Arduino Examples See the foundations page for in-depth description of core concepts of the Arduino hardware and software. to: Blink Without Delay: blinking an LED without using the delay() function. at 06:55 PM by David A. 2008. Deleted lines 43-44: Added lines 49-51: Timing & Millis Stopwatch Deleted lines 75-125: . 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. Restore May 21. 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. see the Arduino Getting Started. The code is included on the page. 2008.EEPROM Library EEPROM Clear: clear the bytes in the EEPROM. to: These are more complex examples for using particular electronic components or accomplishing specific tasks. Mellis Changed line 15 from: BlinkWithoutDelay: blinking an LED without using the delay() function. and the links page for other documentation. The code is included in the tutorial. EEPROM Read: read the EEPROM and send its values to the computer. For instructions on getting the board and environment up and running.

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

moving TwoSwitchesOnePin to "other examples" since it's not (yet) in the distribution. 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. . Restore March 07. at 07:20 PM by David A. 2008. at 05:56 PM by Paul Badger Added lines 40-41: TimeSinceStart: Restore April 18. 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. 2008. 2008. 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. 2008. at 09:26 PM by Paul Badger Changed lines 73-75 from: to: Foundations has moved here 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. at 08:22 PM by David A. Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs.(:if false:) Changed line 41 from: to: (:ifend:) Restore April 22. 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 .

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

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

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

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

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

pl?num=1171076259 Use a couple of Arduino pins as a capacitive sensor Restore May 10.pl?num=1171076259 |Use a couple of Arduino pins as a capacitive sensor]] Restore May 10.cc/cgi-bin/yabb2/YaBB.arduino.cc/cgi-bin/yabb2/YaBB. 2007. Mellis Deleted line 46: .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. at 07:07 PM by Paul Badger Changed lines 36-37 from: http://www. at 12:02 PM by Carlyn Maw Changed lines 52-53 from: to: Multiple digital inputs with a CD4021 Shift Register Restore February 06. at 07:05 PM by Paul Badger Changed lines 36-37 from: http://www. 2007.PWM all of the digital pins in a sinewave pattern Restore May 10. at 03:37 PM by David A. 2007. 2007. 2007.arduino.cc/cgi-bin/yabb2/YaBB. 2007.arduino.cc/cgi-bin/yabb2/YaBB. at 06:59 PM by Paul Badger Added line 39: More sound ideas Restore April 24. 2007. 2007.pl?num=1171076259 Use a couple of Arduino pins as a capacitive sensor to: http://www.arduino. 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 02:52 PM by Carlyn Maw Changed lines 52-54 from: Multiple digital ins with a CD4021 Shift Register to: Restore February 06. 2007. at 07:04 PM by Paul Badger Changed lines 36-37 from: to: http://www. at 02:51 PM by Carlyn Maw Changed lines 52-53 from: to: Multiple digital ins with a CD4021 Shift Register Restore January 30.

Mellis Added line 64: Arduino + MaxMSP Changed lines 67-68 from: to: Arduino + Ruby Restore November 18. Mellis Added line 1: (:title Tutorials:) Restore November 21. at 10:43 AM by David A. 2006. 2006.Build your own DMX Master device Restore December 25. at 12:25 PM by David A. Changed lines 69-70 from: to: Arduino + C Restore December 02. at 03:10 PM by Carlyn Maw Changed lines 50-51 from: to: Multiple digital outs with a 595 Shift Register Restore November 06. Mellis Added line 20: Using a pushbutton as a switch Restore December 07. at 10:13 AM by David A. at 06:04 AM by David A. 2006. 2006. at 10:49 AM by David A. at 12:24 PM by David A. at 11:57 PM by David A. Mellis Deleted line 53: Deleted line 54: Restore November 04. 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 Added lines 51-58: Other Arduino Examples Example labs from ITP . 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. at 02:42 AM by David A. 2006. Mellis .

see the Arduino guide. For instructions on getting the board and environment up and running. The Arduino environment .Examples from Tom Igoe Examples from Jeff Gray Deleted lines 83-89: Other Arduino Examples Example labs from ITP Examples from Tom Igoe. Examples from Jeff Gray. 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.lots of content moved to the new guide. 2006. Restore November 04. For instructions on getting the board and environment up and running. to: Example labs from ITP Examples from Tom Igoe. 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. see the examples from Tom Igoe and those from Jeff Gray. at 12:23 PM by David A. Deleted lines 52-67: The Arduino board This guide to the Arduino board explains the functions of the various parts of the board. 2006. 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. at 10:38 AM by David A. see the Arduino guide?. Examples from Jeff Gray. 2006. Restore November 04. Restore November 04. Mellis Changed lines 50-51 from: Example labs from ITP to: Changed lines 77-78 from: Also. Restore November 04. Mellis . or is there something you would like to see published in this site? Refer to the forum for further help. at 12:24 PM by David A. at 10:37 AM by David A.

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

illustrated tutorials from his Spooky Projects course: class 1 (getting started). Restore October 21. The libraries page explains how to use libraries in your sketches and how to make your own. at 12:51 PM by David A.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). 2006. at 05:46 PM by David A. 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. class 2 (input and sensors). servos. Mellis . 2006. 2006. The libraries? page explains how to use libraries in your sketches and how to make your own. class 2 (input and sensors). to: todbot has some very detailed.adding links to todbot's class notes. at 05:38 PM by David A. 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. Added lines 66-68: Course Guides todbot has some very detailed. Restore October 22. Mellis Changed lines 67-68 from: todbot has some very detailed. For instructions on getting the board and IDE up and running. see the Howto?. class 3 (communication. 2006. Restore October 08. For instructions on getting the board and environment up and running. 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. Mellis Changed lines 59-62 from: 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 . to: This guide to the Arduino IDE (integrated development environment) explains the functions of the various buttons and menus. class 2 (input and sensors). 2006. see the Howto. and pwm). see the Howto?. Restore October 08. see the Howto. For instructions on getting the board and IDE up and running. at 04:25 PM by David A. at 05:45 PM by David A. For instructions on getting the board and IDE up and running. Restore October 08. illustrated tutorials from his Spooky Projects course: class 1 (getting started).

Thanks to Pollie Barden for the great videos.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. The libraries? page explains how to use libraries in your sketches and how to make your own. Video Lectures by Tom Igoe Watch Tom introduce Arduino. 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.

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. 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. (:tableend:) Restore Edit Page | Page History | Printable View | All Recent Site Changes . Make magazine has some great links in its electronics archive. External Resources Instant Soup is an introduction to electronics through a series of beautifully-documented fun projects. hack a day has links to interesting hacks and how-to articles on various topics. see the examples from Tom Igoe and those from Jeff Gray.

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

to: !!Arduino Examples ''See the '''[[Tutorial/Foundations | foundations page]]''' for in-depth description of core concepts of the Arduino hardware and software. at 06:55 PM by David A.cc/playground/Main/ArduinoCoreHardware | Board Setup and Configuration]]: Information about the components and usage of Arduino hardware. [[http://www.arduino.arduino.'' Added line 15: * [[BlinkWithoutDelay | BlinkWithoutDelay]]: blinking an LED without using the delay() function.cc/playground/Main/InterfacingWithHardware#Output | Output]] * [[http://www. .cc/playground/Main/InterfacingWithHardware | Interfacing With Hardware]]: Code.arduino.cc/playground/Main/InterfacingWithHardware#Storage | Storage]] * [[http://www. Hosted on the publicly-editable [[http://www.cc/playground/Main/GeneralCodeLibrary | Code Library and Tutorials]]: Arduino functions for performing specific tasks and other programming tutorials. The code is included on the page.cc/playground/Main/InterfacingWithSoftware | Interfacing with Software]]: how to get an Arduino board talking to software running on the computer (e.arduino. 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.arduino.cc/playground/ | playground wiki]]. and the '''[[Tutorial/Links | links page]]''' for other documentation. Max/MSP).arduino.arduino.Restore April 29. The code is included in the tutorial. Flash.cc/playground/Main/ElectroInfoResources | Electronics Techniques]]: tutorials on soldering and other electronics resources. [[http://www.arduino.cc/playground/Main/InterfacingWithHardware#Communication | Communication]] [[http://www. see the Arduino [[Guide/HomePage | Getting Started]]. !!!Tutorials Tutorials created by the Arduino community.g. 2008.cc/playground/Main/InterfacingWithHardware#Interaction | Interaction]] * [[http://www. For instructions on getting the board and environment up and running. * [[http://www. 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. Mellis .arduino.cc/playground/Main/InterfacingWithHardware#Input | Input]] * [[http://www. 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. to: These are more complex examples for using particular electronic components or accomplishing specific tasks. [[http://www. [[http://www. Processing.arduino. PD. circuits. and instructions for using various electronic components with an Arduino board.moving the resources to the links page.arduino.

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

at 08:23 PM by David A. Midi. * [[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. at 07:20 PM by David A. SPI. 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. . 2008. etc. 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. at 08:22 PM by David A. * [[Numbers]]: The various types of numbers available and how to use them. I2C. 2008. 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.) * [[Serial | Serial Communication]]: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). at 09:24 PM by Paul Badger Changed lines 74-107 from: * [[Memory]]: The various types of memory available on the Arduino board. * [[Foundations]] (:if false:) * [[PWM | PWM (Pulse-Width Modulation)]]: The method used by analogWrite() to simulate an analog output with digital pins. 2008. * [[Communication]]: An overview of the various ways in which an Arduino board can communicate with other devices (serial. 2008. 2008. 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. Mellis . Restore March 07.Restore April 08. * [[Interrupts]]: Code that interrupts other code under certain conditions. to: See the [[Foundations| foundations page]] for explanations of the concepts involved in the Arduino hardware and software.moving TwoSwitchesOnePin to "other examples" since it's not (yet) in the distribution. 2008. * [[Analog Input Pins]]: Details about the analog-to-digital conversion and other uses of the pins.

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

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

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

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

cc/playground/Interfacing/Ruby | Arduino + Ruby]] * [[http://todbot.arduino.cc/playground/Interfacing/Director | Arduino + Director]] * [[http://www. (:cell width=50%:) !!!Tutorials These are more complex tutorials for using particular electronic components or accomplishing specific tasks.cc/playground/Interfacing/Processing | Arduino + Processing]] * [[http://www.arduino.cc/playground/Interfacing/VVVV | Arduino + VVVV]] * [[http://www.cc/playground/Interfacing/MaxMSP | Arduino + MaxMSP]] * [[http://www.arduino.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.cc/playground/Interfacing/Flash | Arduino + Flash]] * [[http://www.arduino.pl?num=1171076259 | Use two Arduino pins as a capacitive sensor]] to: Deleted line 54: * [[http://www.cc/cgi-bin/yabb2/YaBB. * [[Virtual Color Mixer]]: sending multiple variables from Arduino to the computer and reading them in Processing. * [[Physical Pixel]]: turning on and off an LED by sending data from Processing.nyu.com/blog/2006/12/06/arduino-serial-c-code-to-talk-to-arduino/ | Arduino + C]] .arduino.arduino.com/blog/category/arduino/ | Spooky Arduino and more from Todbot]] Deleted lines 78-105: (:cell width=50%:) !!!Interfacing with Other Software * [[http://itp.arduino.edu/physcomp/Labs/Serial | Introduction to Serial Communication]] (from [[http://itp.arduino.arduino. The code is included in the tutorial.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/Learning/Tutorials | Tutorials from the Arduino playground]] Added line 75: * [[http://todbot.nyu.cc/playground/Interfacing/PD | Arduino + PD]] * [[http://www.arduino.nyu.arduino.cc/playground/Main/PWMallPins | PWM all of the digital pins in a sinewave pattern]] !!!! Digital Input * [[http://itp.nyu.edu/physcomp/Labs/DigitalInOut | Digital Input and Output]] (from [[http://itp.* [[Graph]]: sending data to the computer and graphing it in Processing.edu/physcomp/Labs/Labs | ITP physcomp labs]]) * [[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.

arduino.pl?num=1171076259 | Use two Arduino pins as a capacitive sensor]] Restore May 10.danslchamp. 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.cc/cgi-bin/yabb2/YaBB.pl?num=1171076259]] Use a couple of Arduino pins as a capacitive sensor to: * [[http://www.cc/playground/Learning/Tutorial01 | Bluetooth]] * [[http://mrtof.cc/cgi-bin/yabb2/YaBB.arduino.cc/cgi-bin/yabb2/YaBB.arduino. 2007.arduino.arduino.arduino.cc/cgi-bin/yabb2/YaBB.cc/cgi-bin/yabb2/YaBB.arduino.arduino.pl?num=1171076259]] |Use a couple of Arduino pins as a capacitive sensor]] Restore May 10.arduino.arduino.arduino.cc/cgi-bin/yabb2/YaBB. at 06:06 AM by Paul Badger Changed lines 17-18 from: to: * [[ http://www.cc/playground/Learning/BuildProcess | Arduino build process]] * [[http://www.pl?num=1147888882 | Software serial]] (serial on pins besides 0 and 1) * [[http://www.org/AXIC | Zigbee]] * [[http://www.pl?num=1171076259]] |Use a couple of Arduino pins as a capacitive sensor]] to: *[[http://www.arduino.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. 2007.!!!Tech Notes (from the [[http://www.pl?num=1138892708 | Power supplies]] * [[http://www. 2007.arduino. 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.pl?num=1146679536 | LED as light sensor]] (en Francais) * [[http://www.arduino. 2007.pl?num=1135701338 | Hex inverter]] * [[http://www.cc/cgi-bin/yabb2/YaBB. at 07:04 PM by Paul Badger Changed lines 36-37 from: to: * [[http://www.pl?num=1138310274 | L297 motor driver]] * [[http://www.cc/playground/Code/OSXISPMKII | AVRISP mkII on the Mac]] * [[http://www. 2007.cc/playground/Learning/CommandLine | Using Arduino from the command line]] Restore May 11. 2007.pl?num=1139161553 | The components on the Arduino board]] * [[http://www.cc/playground/Learning/Asuro | Arduino and the Asuro robot]] * [[http://www.cc/cgi-bin/yabb2/YaBB. 2007. at 07:05 PM by Paul Badger Changed lines 36-37 from: * [[http://www.arduino.cc/playground/ | playground]]) * [[http://www.arduino.cc/playground/Code/EEPROM-Flash | Non-volatile memory (EEPROM)]] * [[http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1138666403 | Analog multiplexer]] * [[http://www.cc/cgi-bin/yabb2/YaBB.cc/playground/Main/PWMallPins | PWM all of the digital pins in a sinewave pattern]] Restore May 10. at 07:07 PM by Paul Badger Changed lines 36-37 from: * [[http://www. 2007.pl | forums]] or [[http://www. 2007.arduino.cc/playground/Main/Freqout|More sound ideas]] Restore April 24. at 02:51 PM by Carlyn Maw Changed lines 52-53 from: . at 06:59 PM by Paul Badger Added line 39: * [[http://www.arduino.cc/cgi-bin/yabb2/YaBB.cc/cgi-bin/yabb2/YaBB.arduino.arduino.pl?num=1171076259]] Use a couple of Arduino pins as a capacitive sensor Restore May 10.cc/cgi-bin/yabb2/YaBB.

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

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

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

Added lines 66-68: !!!Course Guides [[http://todbot. at 05:46 PM by David A.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class1. at 05:38 PM by David A. The [[libraries]] page explains how to use libraries in your sketches and how to make your own.com/blog | todbot]] has some very detailed. to: [[http://todbot. [[http://todbot.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class2.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class1. Restore October 08. and pwm)]]. For instructions on getting the board and IDE up and running. see the [[Howto]].com/blog/spookyarduino/ | Spooky Projects]] course: [[http://todbot. servos. to: This [[Main/Environment | guide to the Arduino IDE]] (integrated development environment) explains the functions of the various buttons and menus.pdf | class 2 (input and sensors)]]. 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. see the [[Howto]]. The [[Main/libraries]] page explains how to use libraries in your sketches and how to make your own.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]] .adding links to todbot's class notes. (: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. Restore October 21.edu/physcomp/Labs/DigitalInOut | Digital Input and Output]] (from [[http://itp.content/uploads/2006/10/arduino_spooky_projects_class2.pdf | class 2 (input and sensors)]]. 2006.pdf | class 1 (getting started)]].nyu. 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. 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.pdf | class 1 (getting started)]].com/blog/spookyarduino/ | Spooky Projects]] course: [[http://todbot. 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.com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class3.nyu. see the [[Main/Howto]].com/blog/wpcontent/uploads/2006/10/arduino_spooky_projects_class2. 2006. illustrated tutorials from his [[http://todbot. [[http://todbot.pdf | class 2 (input and sensors)]]. For instructions on getting the board and IDE up and running.com/blog | todbot]] has some very detailed. 2006. Restore October 08. at 05:45 PM by David A. Mellis . Restore October 08. illustrated tutorials from his [[http://todbot. 2006. [[http://todbot.pdf | class 3 (communication. For instructions on getting the board and IDE up and running. at 04:25 PM by David A.

flr4.nyu.arduino.cc/cgi-bin/yabb2/YaBB.arduino.arduino.org/arduino/index.nyu.sbk.cc/playground/Interfacing/VVVV | Arduino + VVVV]] * [[http://www.cc/cgi-bin/yabb2/YaBB.nyu.pl?num=1138310274 | L297 motor driver]] * [[http://www. Thanks to Pollie Barden for the great videos.cc/playground/Code/EEPROM-Flash | Non-volatile memory (EEPROM)]] * [[http://www.pl?num=1135701338 | Hex inverter]] * [[http://www. !!!Video Lectures by Tom Igoe [[http://www. * [[ 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.arduino.arduino.nyu.cc/playground/Code/OSXISPMKII | AVRISP mkII on the Mac]] * [[http://www.arduino.arduino.edu/physcomp/Labs/Labs | ITP physcomp labs]]) * [[http://www.cc/playground/Interfacing/Flash | Arduino + Flash]] * [[http://www.cc/cgi-bin/yabb2/YaBB.cc/playground/ | playground]]) * [[http://www.edu/physcomp/Labs/Labs | ITP physcomp labs]]).* [[ 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.pl?num=1139161553 | The components on the Arduino board]] * [[http://www.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.arduino.edu/physcomp/Labs/DCMotorControl | Driving a DC Motor with an L293]] (from [[http://itp.nyu.pl?num=1147888882 | Software serial]] (serial on pins besides 0 and 1) * [[http://www.arduino.nyu.edu/physcomp/Labs/MIDIOutput | MIDI Output]] (from [[http://itp. !!!Interfacing with Other Software * [[http://itp.arduino.arduino.pl?num=1138892708 | Power supplies]] * [[http://www.pl?num=1138666403 | Analog multiplexer]] * [[http://www.cc/cgi-bin/yabb2/YaBB.cc/cgi-bin/yabb2/YaBB.cc/playground/Interfacing/Director | Arduino + Director]] !!!Tech Notes (from the [[http://www.arduino. The [[libraries]] page explains how to use libraries in your sketches and how to make your own.arduino.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/Learning/Tutorial01 | Bluetooth]] .cc/playground/Learning/BuildProcess | Arduino build process]] * [[http://www.arduino.cc/cgi-bin/yabb2/YaBB.cc/playground/Interfacing/PD | Arduino + PD]] * [[http://www. !!!The Arduino environment 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]]) !!!! 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.cc/playground/Interfacing/Processing | Arduino + Processing]] * [[http://www.edu/physcomp/Labs/Serial | Introduction to Serial Communication]] (from [[http://itp.html | Watch Tom]] introduce Arduino.arduino.cc/cgi-bin/yabb2/YaBB.arduino.arduino.pl | forums]] or [[http://www.nyu.

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

X1 (pink) Toggles External Power and USB Power (place jumper on two pins closest to desired supply) . 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) .S1 (dark blue) In-circuit Serial Programmer (blue-green) Analog In Pins 0-5 (light blue) Power and Ground Pins (power: orange. Linux. Arduino Mini.SV1 (purple) USB (used for uploading sketches to the board and for serial communication between the board and the computer. The maximum current per pin is 40 mA. digitalRead(). LilyPad Arduino. . Arduino Nano. grounds: light orange) External Power Supply In (9-12VDC) . and digitalWrite() commands.g. Arduino BT.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ (redirected from Tutorial. Mac OS X. can be used to power the board) (yellow) Digital Pins In addition to the specific functions listed below. Reset Button .These pins cannot be used for digital i/o (digitalRead and digitalWrite) if you are also using serial communication (e. respectively) when the pin is configured as an input. the digital pins on an Arduino board can be used for general purpose input and output via the pinMode(). 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 .ArduinoBoard) Guide Contents | Introduction | How To: Windows.begin). 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.

Typically used to add a reset button to shields which block the one on the board. a rising or falling edge. 10. these pins are connected to the corresponding pins of the FTDI USB-to-TTL Serial chip. 3V3. I 2 C: 4 (SDA) and 5 (SCL). On the Arduino Diecimila. if supplying voltage via the power jack. Other Pins AREF. On the Diecimila and LilyPad. is not currently included in the Arduino language. when the pin is LOW. Support I 2 C (TWI) communication using the Wire library (documentation on the Wiring website). the Mini-USB Adapter). PWM output is available only on pins 9. LED: 13. 6. the LED is on. Reference voltage for the analog inputs. 10. Analog inputs 6 and 7 (present on the Mini and BT) cannot be used as digital pins. SPI: 10 (SS). The text of the Arduino getting started guide is licensed under a Creative Commons Attribution-ShareAlike 3. 13 (SCK). 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. access it through this pin. Reset. Used to receive (RX) and transmit (TX) TTL serial data. they are intended for use with an external TTL serial module (e. the analog input pins support 10-bit analog-to-digital conversion (ADC) using the analogRead() function. This can come either from VIN via an on-board regulator. You can supply voltage through this pin. 11 (MOSI). Ground pins. Edit Page | Page History | Printable View | All Recent Site Changes . 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. there is a built-in LED connected to digital pin 13. PWM: 3. (Arduino BT-only) Connected to the reset line of the bluetooth module. and 11. See the attachInterrupt() function for details. please see the documentation for your board. Provide 8-bit PWM output with the analogWrite() function. or be supplied by USB or another regulated 5V supply. 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). 12 (MISO). which. Power Pins VIN (sometimes labelled "9V").3 volt supply generated by the on-board FTDI chip. and 11. 9. Analog Pins In addition to the specific functions listed below. Not currently supported by the Arduino software. (Diecimila-only) Bring this line LOW to reset the microcontroller. Also note that the LilyPad has no VIN pin and accepts only a regulated input. although provided by the underlying hardware.0 License. These pins can be configured to trigger an interrupt on a low value. External Interrupts: 2 and 3. These pins support SPI communication. Code samples in the guide are released into the public domain. or. On the Arduino BT. On boards with an ATmega8. 5. it's off. Note that different boards accept different input voltages ranges. or a change in value. (Diecimila-only) A 3. 5V. When the pin is HIGH value. GND.Serial: 0 (RX) and 1 (TX). On the Arduino Mini and LilyPad Arduino. BT Reset: 7.g.

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 .

Sign up to vote on this title
UsefulNot useful