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

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

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

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

OUTPUT). delay(val). HIGH). delay(val). LOW). } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin). digitalWrite(ledPin. // variable to store the value coming from the sensor void setup() { pinMode(ledPin.int val = 0. 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 Edit Page | Page History | Printable View | All Recent Site Changes .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The job of the 10K series resistor. it will overwhelm the external 200K resistor and the pin will report HIGH. One downside of the scheme (there always has to be a downside doesn't there?) is that one can't tell if both buttons are pushed at the same time. * * 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 * _ * */ . 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. but when the pullup resistor is turned on. They are accessible from software by using the digitalWrite() function. 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 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 . incidentally. * it will overwhelm the 200K resistor and the pin will report HIGH. /* * Read_Two_Switches_On_One_Pin * Read two pushbutton switches or one center-off toggle switch with one Arduino pin * Paul Badger 2008 * From an idea in EDN (Electronic Design News) * * Exploits the pullup resistors available on each I/O and analog pin * The idea is that the 200K resistor to ground will cause the input pin to report LOW when the * (20K) pullup resistor is turned off. is to prevent a short circuit if a pesky user pushes both buttons at once. When the internal pullup resistor is turned on however. In this case the scheme just reports that sw2 is pushed. when the pin is set to an input.+5 volts in the Arduino's case) built into the Atmega chip upon which Freeduino's are based. This sketch exploits the pullup resistors under software control.

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

by Anders Gran Code Use the Digital > Button example to read the tilt-sensor. Edit Page | Page History | Printable View | All Recent Site Changes . The code example is exactly as the one we would use for a pushbutton but substituting this one with the tilt sensor. However it is only the equivalent to a pushbutton activated through a different physical mechanism. but you'll need to make sure that the inputPin variable in the code matches the digital pin you're using on the Arduino board. The hardware was mounted and photographed by Anders Gran. 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. Circuit Picture of a protoboard supporting the tilt sensor. We use a pull-up resistor (thus use active-low to activate the pins) and connect the sensor to a digital input pin that we will read when needed. the software comes from the basic Arduino examples. This type of sensor is the environmental-friendly version of a mercuryswitch. 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.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. 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 .

the program always lights up the LED corresponding to the pie in which the joystick is. the joystick gives a coordinate (x.y) back to arduino. As you can see looking to the joystick is that the space in which he moves is a circle. This circle will be from now on our 'Pie' (see bottom right of the first image). This way. Then. when the joystick gives us a coordinate. (See figure below). it will necesarilly belong to one of the pies. To each piece will correspond an LED. . 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.

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

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

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

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

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

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

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

which is read by an analog input on the Arduino. zpin = 1. if you're using just the accelerometer: ADXL3xx Pin Self-Test Arduino Pin ZOut YOut XOut Ground VDD 5V None (unconnected) Analog Input 1 Analog Input 2 Analog Input 3 GND Code int int int int int groundpin = 18. Circuit An ADXL322 on a Sparkfun breakout board inserted into the analog input pins of an 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. ypin = 2. ADXL321. 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) . powerpin = 19. 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.g. ADXL320. The pins used are designed to be easily compatible with the breakout boards from Sparkfun. xpin = 3. ADXL322.

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

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

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

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

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

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

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

pinMode(qt401_clk.potemkin. void qt401_init() { // define pin directions pinMode(qt401_drd. INPUT). // = 7. // = 4. pinMode(qt401_di. INPUT). // data ready data in (from sensor) slave select clock data out (to sensor) detect proximity byte result. digitalWrite(qt401_ss. OUTPUT). pinMode(qt401_det. OUTPUT). // = 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.HIGH). INPUT). // = 8. pinMode(qt401_ss. pinMode(qt401_prx. INPUT). // initialise pins digitalWrite(qt401_clk. OUTPUT).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. // = 5.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » qt401 sensor full tutorial coming soon /* qt401 demo * -----------* * the qt401 from qprox http://www. pinMode(qt401_do.qprox. HIGH). // = 6. } // .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

. and the contrast adjustment pin on your LCD. Look at the datasheet for your LCD board to figure out which pins are where.Connect wires from the breadboard to the arduino input sockets. so keep them as short and tidy as possible. It is a lot of wires. Ground. 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. Make sure to take note of whether the pin view is from the front or back side of the LCD board.

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

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

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

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

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

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

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

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 » DMX Master Device Please see this updated tutorial on the playground.

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

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

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

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

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

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. HyperTerminal or RealTerm on the PC.11 to 5V. Materials needed: Computer with a terminal program installed (ie. If you are using an LED connect it between pin 13 and ground. A general purpose software serial tutorial can be found here. 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. .optional.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.

GND wires are black Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting. +5v wires are red. and the last between pin 6 and ground. Connect your TX pin (7) to MAX3323 pin 10 (T1IN). 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). Connect your RX pin (6) to MAX3323 pin 9 (R1OUT). another between pin 1 and ground.+5v wires are red. GND wires are black Connect a 1uF capacitor across pins 1 and 3.

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

Heatshrink the wire connections to avoid accidental shorts. Enclose the connector in a backshell to further protect the signal and enable easy unplugging from your serial port.Connect pins 1 and 6 to pin 4 and pin 7 to pin 8. 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). .

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

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

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

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

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

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

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

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

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

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

Materials Needed: AD5206 Digital Potentiometer Arduino Microcontroller Module 6 Light Emitting Diodes (LEDs) Hookup Wire Introduction to the AD5206 Digital Potentiometer . For an explanation of SPI see the SPI EEPROM tutorial. The steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. 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. Example applications include LED dimming. In this example we will use a six channel digital potentiometer to control the brightness of six LEDs.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).

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

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

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

//2 byte opcode spi_transfer(address).LOW). } if (pot==6) { pot=0. This causes the LEDs to sequentially flash on brightly and then fade out slowly: void loop() { write_pot(pot. //release chip.i++) { write_pot(i.delay(10). int value) { digitalWrite(SLAVESELECT. 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 . It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. Finally. We conclude the setup function by setting all the potentiometers to full on resistance states thereby turning the LEDs off: for (i=0. We set the SLAVESELECT line low to enable the device. Then we transfer the address byte followed by the resistance value byte. byte write_pot(int address. We pause for 10 milliseconds each iteration to make the steps visible. but part of builtin SPI SPICLOCK 13//sck SLAVESELECT 10//ss . resistance++. digitalWrite(SLAVESELECT.resistance). An explanation of bit masks can be found here.not used. delay(10). // return the received byte } The write_pot function allows us to control the individual potentiometers.255). if (resistance==255) { pot++. } } The spi_transfer function loads the output data into the data transmission register. thus starting the SPI transmission. return SPDR. we set the SLAVSELECT line high again to release the chip and signal the end of our data transfer.HIGH). SPIF.i<6. } } In our main loop we iterate through each resistance value (0-255) for each potentiometer address (0-5). // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. 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++. // Start the transmission while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission { }. INPUT). tutorial and photos by Heather Dewey-Hagborg Edit Page | Page History | Printable View | All Recent Site Changes .master.msb 1st. for (i=0.spi enabled. } } code. pinMode(DATAIN. resistance++.HIGH). signal end transfer } void loop() { write_pot(pot.HIGH).i++) { write_pot(i. //2 byte opcode spi_transfer(address).clk low when idle. pinMode(DATAOUT. return SPDR.i<6.LOW). } } byte write_pot(int address. //sample on leading edge of clk. char spi_transfer(volatile char data) { SPDR = data. digitalWrite(SLAVESELECT. pinMode(SLAVESELECT.OUTPUT).system clock/4 (fastest) SPCR = (1<<SPE)|(1<<MSTR). } if (pot==6) { pot=0.resistance). byte resistance=0. //disable device // SPCR = 01010000 //interrupt disabled. int value) { digitalWrite(SLAVESELECT. byte clr. delay(10). clr=SPSR. OUTPUT).byte pot=0. //release chip.255). clr=SPDR. delay(10). spi_transfer(value). // return the received byte } void setup() { byte i. pinMode(SPICLOCK. digitalWrite(SLAVESELECT.OUTPUT).

.

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

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 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. 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. 2. You can get around this by controlling the MR and OE pins from your Arduino board too. 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. Turning it on Make the following connections: GND (pin 8) to ground.The Circuit 1.1µf capacitor on the latchPin.

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

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

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

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

Circuit Diagram .

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

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

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

please contact me at tom. see this technote If anyone's interested in helping to develop this library further.igoe at gmail.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.com Edit Page | Page History | Printable View | All Recent Site Changes .

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

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

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

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

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

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

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

at 07:20 PM by David A. 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:23 PM by David A. 2008. 2008. Mellis . at 08:22 PM by David A. to: See the foundations page for explanations of the concepts involved in the Arduino hardware and software. 2008. 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.(:if false:) Changed line 41 from: to: (:ifend:) Restore April 22. Changed lines 18-19 from: TwoSwitchesOnePin: Read two switches with one I/O pin to: Added line 43: * TwoSwitchesOnePin: Read two switches with one I/O pin Restore April 08. 2008. at 09:26 PM by Paul Badger Changed lines 73-75 from: to: . 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. 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. Restore March 07. at 05:56 PM by Paul Badger Added lines 40-41: TimeSinceStart: Restore April 18.moving TwoSwitchesOnePin to "other examples" since it's not (yet) in the distribution.

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

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

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

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

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

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

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

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

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

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

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

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. . 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. (: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 libraries? page explains how to use libraries in your sketches and how to make your own. see the Howto?.

or is there something you would like to see published in this site? Refer to the forum for further help. 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. Make magazine has some great links in its electronics archive. Thanks to Pollie Barden for the great videos. Do you need extra help? Is there a sensor you would like to see characterized for Arduino.Video Lectures by Tom Igoe Watch Tom introduce Arduino. (:tableend:) Restore Edit Page | Page History | Printable View | All Recent Site Changes . External Resources Instant Soup is an introduction to electronics through a series of beautifully-documented fun projects. 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 processing.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. 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 . The code is included on the page. Graph: sending data to the computer and graphing it 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. to open them. Physical Pixel: turning on and off an LED by sending data from Processing. check the Arduino 0007 tutorials page. Button: use a pushbutton to control an LED. Dimmer: move the mouse to change the brightness of an LED. Blink Without Delay: blinking an LED without using the delay() function. Reading Knock: detect knocks with a piezo element. Loop: controlling multiple LEDs with a loop and an array. the hacking page for information on extending and modifying the Arduino hardware and software. ASCII Table: demonstrates Arduino's advanced serial output functions. Examples Simple programs that demonstrate the use of the Arduino board. For more information or to download Processing. (If you're looking for an older example. Virtual Color Mixer: sending multiple variables from Arduino to the computer and reading them in Processing. These are included with the Arduino environment. click the Open button on the toolbar and look in the examples folder. Read an Fading: uses an analog output (PWM pin) to fade sensor) an LED. and the links page for other documentation. 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. Communication These examples include code that allows the Arduino to talk to Processing sketches running on the computer. filtering noise. Debounce: read a pushbutton. Play Melodies with a Piezo Speaker Play Tones from the Serial Connection MIDI Output (from ITP physcomp labs) and from Spooky Arduino Interfacing w/ Hardware Multiply the Amount of Outputs with an LED Driver Interfacing an LCD display with 8 bits LCD interface library Driving a DC Motor with an L293 (from ITP physcomp labs).org.) Other Examples These are more complex examples for using particular electronic components or accomplishing specific tasks. Smoothing: smooth multiple readings of an analog Sound input.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Programming Technique Variables: How to define and use variables. Microcontrollers Digital Pins: How the pins work and what it means for them to be configured as inputs or outputs. Arduino Firmware Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. 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. Page Discussion Basics Sketch: The various components of a sketch and how they work. Port Manipulation: Manipulating ports directly for faster manipulation of multiple pins (Printable View of http://www.arduino.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.cc/en/Tutorial/Foundations) .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

The car had been augmented with plenty of LEDs in all possible sizes performing flashy effects. Malmo University * @author: David Cuartielles * @hardware: David Cuartielles.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.) construction to perform the very same thing. Aaron Hallborg */ . one by one using only digitalWrite(pinNum. The first code example will make the LEDs blink in a sequence.HIGH/LOW) and delay(time). Example for Hasselhoff's fans Knight Rider 1 /* Knight Rider 1 * -------------* * Basically an extension of Blink_LED. 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. it would be interesting to use the Knight Rider as a metaphor.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 . The second example shows how to use a for(.. * * * (cleft) 2005 K3.

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

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

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

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

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

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

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

// if (val == HIGH) { // digitalWrite(ledPin.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). HIGH). } else { digitalWrite(ledPin. LOW). OUTPUT). pinMode(inPin. INPUT).

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

OUTPUT).time > debounce) { if (state == HIGH) state = LOW. } digitalWrite(outPin. INPUT). toggle the output pin and remember the time (reading == HIGH && previous == LOW && millis() . increase if the output flickers void setup() { pinMode(inPin.// 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. long time = 0. else state = HIGH. time = millis(). previous = reading. // the last time the output pin was toggled long debounce = 200. pinMode(outPin. // the debounce time. } void loop() { reading = digitalRead(inPin). } Edit Page | Page History | Printable View | All Recent Site Changes . state).

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

// select the input pin for the potentiometer // select the pin for the LED // variable to store the value coming from the sensor void setup() { pinMode(ledPin. delay(val).int potPin = 2. OUTPUT). HIGH). int ledPin = 13. int val = 0. delay(val). 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 Edit Page | Page History | Printable View | All Recent Site Changes . } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin). digitalWrite(ledPin. LOW).

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

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

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

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

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

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

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

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

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

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

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

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

Add a second shift register. The Circuit 1. doubling the number of input pins while still using the same number of pins on the Arduino.Code Sample 1.4 – Is it pressed? (sub-function) Example 2: Daisy Chained In this example you’ll add a second shift register. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires). . 2. Connect the 2 registers. 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.

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

Diagram .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

digitalWrite(ledPin. int val = 0. 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 Restore Edit Page | Page History | Printable View | All Recent Site Changes . HIGH). int ledPin = 13. LOW). } // declare the ledPin as an OUTPUT void loop() { val = analogRead(potPin). delay(val).* a potentiometer to analog pin 2. OUTPUT). // select the input pin for the potentiometer // select the pin for the LED // variable to store the value coming from the sensor void setup() { pinMode(ledPin. delay(val).

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

} // // // // // 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.cc/en/Tutorial/AnalogInput) .arduino. digitalWrite(ledPin.void loop() { val = analogRead(potPin). 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 .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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 .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

However it is only the equivalent to a pushbutton activated through a different physical mechanism. 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. 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.arduino. 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. The code example is exactly as the one we would use for a pushbutton but substituting this one with the tilt sensor.cc/en/Tutorial/TiltSensor) . which datasheet can be found here. the software comes from the basic Arduino examples. Circuit Picture of a protoboard supporting the tilt sensor. by Anders Gran Code Use the Digital > Button example to read the tilt-sensor. This type of sensor is the environmental-friendly version of a mercury-switch. The hardware was mounted and photographed by Anders Gran.Arduino : Tutorial / Tilt Sensor Learning Examples | Foundations | Hacking | Links Tilt Sensor The tilt sensor is a component that can detect the tilting of an object.

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

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

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

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

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

the joystick gives a coordinate (x. . As you can see looking to the joystick is that the space in which he moves is a circle. when the joystick gives us a coordinate. it will necesarilly belong to one of the pies. This circle will be from now on our 'Pie' (see bottom right of the first image).y) back to arduino. 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. Then. To each piece will correspond an LED. This way. the program always lights up the LED corresponding to the pie in which the joystick is. (See figure below).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

value). } else{ lastButtonState = buttonState. } } } (Printable View of http://www. lastButtonState. that is. fractional = (int)(elapsedTime % 1000L). seconds .then cast to an int to print Serial."). digitalWrite(ledPin. else value = LOW.arduino. fractional part of time Serial. } else{ digitalWrite(ledPin.previousMillis > interval) ) { if (blinking == true){ previousMillis = millis().Serial. is the difference between the current time and last time we blinked the LED bigger than the interval at which we want to blink the LED.println(fractional). if ( (millis() .print( (int)(elapsedTime / 1000L) ). the LED // 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. if (value == LOW) value = HIGH.cc/en/Tutorial/Stopwatch) // remember the last time we blinked // turn off LED when not blinking . LOW).print(". 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 .

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

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

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

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

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

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

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

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

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

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

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

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

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

arduino.cc/en/Tutorial/AccelerometerMemsic2125) . (Printable View of http://www. 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. by M. Marcos Yarza added two 220Ohm resistors to the pins coming out of the accelerometer. Here the code is exactly the same as before (changing the input pins to be 2 and 3). 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 .

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

with volume control set using analogWrite() /* * * * * * * * * * * * * * * * * * Play Melody ----------Program to play melodies stored in an array. Light fuse and get away. Serial.cc/en/Tutorial/PlayMelody * ADD code to make the tempo settable by pot or other input device * ADD code to take tempo or volume settable by serial communication * (Requires 0005 or higher. tone. pause.print(":"). a tone of 'duration' plays much more slowly than a rest * of 'duration. Your mileage may vary. // Set up timing playTone()..} } // LET THE WILD RUMPUS BEGIN ============================= void loop() { // Set up a counter to pull from melody[] and beats[] for (int i=0.. Serial.println(duration). * Lies lies lies! It holds for at least 'duration' microseconds.print(i). as with the second program at * http://www. _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. Serial. using analogWrite. report loop. beat. * * 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. // A pause between notes. i<MAX_COUNT. Past behavior is no guarantee of future * performance. i++) { tone = melody[i]. as well as * overhead from any program mods. * * rest_count will be affected by chip architecture and speed. Serial. and rest_count to #define statements * RE-WRITE to include volume.print(" ").print(tone). and duration Serial.print(" "). if (DEBUG) { // If debugging. it requires to know about timing issues and about how to play tones.print(beat). Serial. The calculation of the tones is made following the mathematical operation: timeHigh = 1/(2 * toneFrequency) = period / 2 where the different tones are described as in the table: note c d e f frequency 261 Hz 294 Hz 329 Hz 349 Hz period 3830 3400 3038 2864 PW (timeHigh) 1915 1700 1519 1432 . beat = beats[i]. duration = beat * tempo.' rest_count creates a loop variable to bring 'rest' beats * in line with 'tone' beats of the same length.arduino. Serial.) * 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. } } } /* * NOTES * The program purports to hold a tone for 'duration' microseconds. delayMicroseconds(pause).

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Look at the datasheet for your LCD board to figure out which pins are where. and the contrast adjustment pin on your LCD.Connect wires from the breadboard to the arduino input sockets. so keep them as short and tidy as possible. . Make sure to take note of whether the pin view is from the front or back side of the LCD board. Ground. 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

count++){ shiftDmxOut(3. //set all adresses/channels to 60% for (count = 1. pinMode(sigI. LOW). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). theByte>>=1. delay(10). } delayMicroseconds(theDelay). // reenable interrupts. } delayMicroseconds(theDelay). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). } void setup() { pinMode(sig. _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber).0). // 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).2. } delayMicroseconds(theDelay). OUTPUT). _SFR_BYTE(_SFR_IO8(iPortNumber)) &= ~_BV(iPinNumber). digitalWrite(sigI. if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). sei(). } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber). HIGH). //sending the start byte shiftDmxOut(3. _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). } } to: . } else { _SFR_BYTE(_SFR_IO8(portNumber)) &= ~_BV(pinNumber).155). } void loop() { digitalWrite(sig. count<=512._SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber).2. if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). if (theByte & 01) { _SFR_BYTE(_SFR_IO8(portNumber)) |= _BV(pinNumber). theByte>>=1. theByte>>=1. theByte>>=1. } delayMicroseconds(theDelay). _SFR_BYTE(_SFR_IO8(iPortNumber)) |= _BV(iPinNumber). OUTPUT).

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

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

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

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

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

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. 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.else{ //if bitwise and resolves to false digitalWrite(transmit. Edit Page | Page History | Printable View | All Recent Site Changes .LOW). //delay } } Here we use a FOR loop to iterate through a bit mask value. // send 0 } delayMicroseconds(bitDelay). We then perform a bitwise AND operation on the value and the bitmask. so our operation looks like: 00000010 & 10101010 ________ 00000010 And our output pin gets set to 1. 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. shifting the value one position left each time through the loop. Then all 8 bits have been sent and our loop exits. This way as the bitmask shifts left through each position in the byte it will be compared against each bit in the byte we are sending sequentially and can then be used to set our output pin either high or low accordingly. So in this example.

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

Mellis Added lines 3-4: Note: If you just want to use a software serial interface.Show changes to markup February 26. Restore September 05. at 10:40 AM by David A. 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.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 2006. 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.SoftwareSerial History Hide minor edits . 2006. 2007.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Connect your RX pin (6) to MAX3323 pin 9 (R1OUT). . 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. GND wires are black Connect a 1uF capacitor across pins 1 and 3. GND wires are black Determine which Arduino pins you want to use for your transmit (TX) and recieve (RX) lines. and the last between pin 6 and ground. another across pins 4 and 5. Connect your TX pin (7) to MAX3323 pin 10 (T1IN). +5v wires are red. another between pin 1 and ground. In this tutorial we will be using Arduino pin 6 for receiving and pin 7 for transmitting.

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

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

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

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

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

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

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

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

followed by the 16-bit address we wish to read from. 2006. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. followed by the 16-bit address we wish to read from. First we set the SLAVESELECT line low to enable the device. If we wanted to read multiple bytes at a time we could hold the SLAVESELECT line low while we repeated the data = spi_transfer(0xFF). Finally we pull the SLAVESELECT line high again to release the device after reading one byte. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. It polls a bit to the SPI Status register (SPSR) to detect when the transmission is complete using a bit mask. and return the data. 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). 2006. thus starting the SPI transmission. First we set the SLAVESELECT line low to enable the device.127 for each index in the array. 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. 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. Most Significant Bit first. at 11:05 AM by Heather Dewey-Hagborg Changed lines 180-182 from: This function simply fills our data array with numbers 0 .Restore August 30. 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. up to 128 times for a full page of data: Restore . SPIF. Next we send a dummy byte to the EEPROM for the purpose of shifting the data out. 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.127 for each index in the array. Most Significant Bit first. Finally we pull the SLAVESELECT line high again to release the device after reading one byte. An explanation of bit masks can be found here. and return the data. SPIF. Then we transmit a READ instruction. 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. thus starting the SPI transmission. 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 .

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

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

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

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

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

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

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

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

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

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

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

to: [@ Serial. 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. Each time through the loop we increment the eeprom address to read. define DATAOUT 11//MOSI Restore August 29. Changed lines 139-140 from: [@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.print('h'. to: Finally we get to our main loop. the simplest function in the program! Here we just read one byte at a time from the EEPROM and print it out the serial port. Changed lines 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. to: [@ delay(10).BYTE).to: [@ // SPCR = 01010000 Changed lines 111-112 from: [@//fill buffer with data to: [@ //fill buffer with data Changed lines 121-122 from: [@delay(10).print('h'. 2006.BYTE). Each time through the loop we increment the eeprom address to read. at 02:43 PM by Heather Dewey-Hagborg Changed lines 162-164 from: Finally we get to our main loop. 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 .

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

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

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

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

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

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

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

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

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

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

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

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

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

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ 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 September 06. 2006. at 03:55 PM by Heather Dewey-Hagborg Changed lines 204-206 from: @] to: @] code. 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.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ search Blog » | Forum » | Playground » Tutorial. 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.SPIDigitalPot History Hide minor edits .

2006. 2006. at 10:03 AM by Heather Dewey-Hagborg Restore September 06.Changed lines 36-37 from: PICTURE leds to: Restore September 06. 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: . 2006.

.

at 03:03 PM by Heather Dewey-Hagborg Changed lines 117-118 from: The write_pot function allows us to control the individual potentiometers. 2006. This makes room to add the resistance value which occupies the least significant eight bits of the data byte. at 03:07 PM by Heather Dewey-Hagborg Restore September 05. 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.Restore September 05. When we sum the two together we get our 11 bit opcode to . 2006. at 03:11 PM by Heather Dewey-Hagborg Added lines 130-131: VIDEO ? LEDs Restore September 05. 2006.

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

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

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

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

or flat side of the LED connects to ground. This program will sequentially pulse each LED on and then fade it out gradually. so we don't need to worry about pre-scaling to slow down the transmission. and they can be interfaced with just as you would use a mechanical potentiometer. and the interface runs much faster than the Arduino. 2006. and they can be interfaced with just as you would use a mechanical potentiometer.to: The AD5206 is digitally controlled using SPI. SPICLOCK and SLAVESELECT. The data clock is idle when low. The device is enabled by pulling the Chip Select (CS) pin low. DATAIN. ie. We will walk through the code in small sections. This means it has six variable resistors built in for individual electronic control. to: The AD5206 is digitally controlled using SPI. 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 . and the interface runs much faster than the Arduino. Data is shifted in Most Significant Bit (MSB) first on the rising edge of the data clock. DATAOUT. to: The AD5206 is a 6 channel digital potentiometer. Added lines 26-52: Finally. Restore September 05. at 01:59 PM by Heather Dewey-Hagborg Changed lines 11-12 from: The AD5206 is a 6 channel digital potentiometer. Changed lines 15-25 from: The AD5206 is digitally controlled using standard SPI. 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. PICTURE leds Program the Arduino Now we will write the code to enable SPI control of the AD5206. The data clock is idle when low. The device is enabled by pulling the Chip Select (CS) pin low. and the interface runs much faster than the Arduino. A1. There are three pins on the chip for each of the six internal variable resistors. 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. 20 and 23) and ground so that the long pin of the LED connects to the wiper and the short pin. There are three pins on the chip for each of the six internal variable resistors. Prepare the Breadboard . Bx and Wx. 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. so we don't need to worry about pre-scaling to slow down the transmission. 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. 14. 11. 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. 17. Although we are not reading any data back out of the AD5206 in this program.not used. connect an LED between each Wiper pin (AD5206 pins 2. The device is enabled by pulling the Chip Select (CS) pin low. B1 and W1. 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 data clock is idle when low. byte resistance=0. We define the pins we will be using for our SPI connection. The individual variable resistor pins are labeled Ax.

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

.

For an explanation of SPI see the SPI EEPROM tutorial. Materials Needed: AD5206 Digital Potentiometer Arduino Microcontroller Module 6 Light Emitting Diodes (LEDs) Hookup Wire Introduction to the AD5206 Digital Potentiometer .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). The steps we will cover for implementing SPI communication can be modified for use with most other SPI devices. audio signal conditioning and tone generation. Digital potentiometers are useful when you need to vary the resistance in a ciruit electronically rather than by hand. In this example we will use a six channel digital potentiometer to control the brightness of six LEDs. Example applications include LED dimming.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Tom Igoe // // Date : 25 Oct. } void loop() { //function that blinks all the LEDs //gets passed the number of blinks and the pause time blinkAll_2Bytes(1. 0). . //return the latch pin high to signal chip that it //no longer needs to listen for information digitalWrite(latchPin. delay(1000). // 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. //holder for infromation you're going to pass to shifting function byte data = 0. 0). j < 8. j < 8. j++) { //ground latchPin and hold low for as long as you are transmitting digitalWrite(latchPin.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ Learning Examples | Foundations | Hacking | Links search Blog » | Forum » | Playground » Back to ShiftOut Tutorial //**************************************************************// // Name : shiftOutCode. ////Pin connected to DS of 74HC595 int dataPin = 11. //green LEDs lightShiftPinA(j). 1). //Pin connected to SH_CP of 74HC595 int clockPin = 12. //red LEDs lightShiftPinA(7-j). OUTPUT).500). 2006 // // Version : 1. // 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.

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

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

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

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

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

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

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 .

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

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

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

595 Logic Table 595 Logic Table .

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

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

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

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

(: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. 2006. at 02:19 PM by Carlyn Maw Added lines 55-56: .Restore November 09. at 02:22 PM by Carlyn Maw Changed lines 77-78 from: Attach:Exmp1_.gif Δ to: Restore November 09.

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

Added lines 104-105: .

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

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

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

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

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

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

2006. Code Sample 1.1µf capacitor on the latchPin. at 06:19 PM by Carlyn Maw Changed lines 3-4 from: by Carlyn Maw to: Carlyn Maw.1µf capacitor on the latchPin.the first byte sent through to the second register. if you notice some flicker every time the latch pin pulses you can use a capacitor to even it out. The second byte will then show up on the red LEDs. lighting the green LEDs.1 – Hello World Code Sample 1. The third cycles through an array. Circuit Diagram Restore November 01. 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. at 06:27 PM by Carlyn Maw Added lines 43-50: The Code Here are three code examples. Notice the 0. the clockPin and the latchPin respectively. The second program lights one LED at a time.2 – One by One to: Code Sample 1.1 – Hello World Code Sample 1. to: From now on those will be refered to as the dataPin.3 – from Defined Array\\ Restore November 01. 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.2 – One by One Code Sample 1. and the anode (long pin) of each to its respective shift register output pin. The first is just some “hello world” code that simply outputs a byte value from 0 to 255. at 06:25 PM by Carlyn Maw Changed lines 36-42 from: From now on those will be refered to as the dataPin. to: .2 – One by One Restore November 01. at 06:34 PM by Carlyn Maw Changed lines 50-51 from: Code Sample 1. When the latchPin goes from low to high the sent data gets moved from the aforementioned memory register into the output pins. lighting the LEDs.1 – Hello World Restore November 01. Notice the 0. Tom Igoe Changed line 36 from: I’m going to refer to them from now on as the dataPin. at 06:32 PM by Carlyn Maw Added line 51: Code Sample 1. 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. As the data gets shifted in it is saved in an internal memory register on the shift register. 2006.1µf capacitor on the latchPin. 2006. Restore November 01. Add 8 LEDs. they will only ground. 2006. The code is based on two pieces of information in the datasheet: the timing diagram and the logic table. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. Notice the 0. I was getting some flicker every time the latch pin pulsed so I used the capacitor to even it out. the clockPin and the latchPin respectively. the clockPin and the latchPin respectively. the shift register reads the state of the data pin.

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

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

The 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. that you delineate between bits. you can pulse one pin up and down thereby communicating a data byte to the register bit by bit.Make the following connections: GND (pin 8) to ground. the shift register isn’t actively set to either a high or low voltage. the clock pin. This is the “parallel output” part. 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. Turning it on Make the following connections: GND (pin 8) to ground. 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. a second register attached in parallel to the original circuit you could do so without competition. Restore Edit Page | Page History | Printable View | All Recent Site Changes . You’d do this by setting the Output-Enable (pin 13) HIGH and the Master-Reclear (pin) LOW. >>>>>>> Restore November 01. serial or parallel-out shift register with output latches. you can only set the whole chip together. you can use it to control 8 outputs at a time while only taking up a few pins on your microcontroller. Its by pulsing second pin. Unlike the HIGH and LOW states. 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.” In other words. 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. low or “high impedance. 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. 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). Once the whole byte gets to the register the HIGH or LOW messages held in each bit get parceled out to each of the individual output pins. When a pin is in a high impedance state. 3-state. This example is based on the 74HC595.” When you set a pin set high by sending a 1 bit to that address. Restore November 01. 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. 2006. How this all works is through something called “synchronous serial communication. 2006. it will output whatever voltage you have connected to the Vcc pin. 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.begin() function which relies on the sender and the receiver to be independently set to an agreed upon specified data rate. you can’t set pins to their high impedance state individually. The datasheet refers to the 74HC595 as an “8-bit serial-in. so you don’t need to spend a lot of time on it now.e.” i. 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 learn to do that from the second example. Neither example takes advantage of this feature. The one flaw of this set up is that you might end up with the lights turning on to their last state or something arbitrary every time you first power up the circuit before the program starts to run. This is in contrast using the “asynchronous serial communication” of the Serial. 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. for example. The Circuit 1.

.

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

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

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

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

2. 3. you should put a second shift register on the board. 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 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. Two of these connections simply extend the same clock and latch signal from the Arduino to the second shift register (yellow and green wires). Add a second set of LEDs. It should have the same leads to power and ground.Starting from the previous example. Connect the 2 registers.

Circuit Diagram .

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

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

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

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

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

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

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

see this technote If anyone's interested in helping to develop this library further.A through F: house code values.com (Printable View of http://www.igoe at gmail.arduino.cc/en/Tutorial/X10) . please contact me at tom. 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

2008. Mellis Added lines 80-81: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. to: Serial Communication?: How to send serial data from an Arduino board to a computer or other device (including via the USB connection). at 09:36 PM by David A. 2008. (:ifend:) Restore February 13. Mellis Added lines 80-81: (:if false:) Added lines 84-89: Communication?: An overview of the various ways in which an Arduino board can communicate with other devices (serial. at 09:22 PM by David A. 2008. Pointers?: Functions?: How to write and call functions. Mellis Added lines 90-99: Numbers?: The various types of numbers available and how to use them. Restore February 13. at 09:38 PM by David A. Restore February 13. Midi. at 09:12 PM by David A. Restore February 13. 2008. Mellis Added lines 80-81: Bootloader: A small program pre-loaded on the Arduino board to allow uploading sketches. I2C. at 09:30 PM by David A. 2008.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.) Serial Communication?: How to send serial data from an Arduino board to a computer or other device. to: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. 2008. SPI. 2008. Variables: How to define and use variables. Restore February 13. at 09:41 PM by David A. Interrupts?: Code that interrupts other code under certain conditions. etc. at 09:58 PM by David A. Debugging?: Figuring out what's wrong with your hardware or software and how to fix it. Restore February 13. Mellis Changed lines 80-81 from: PWM (Pulse-Width Modulation): The method used by analogWrite() to simulate an analog output with digital pins. 2008. at 09:31 PM by David A. Restore February 13. Arrays?: How to store multiple values of the same type. Mellis - . Mellis Added lines 100-103: 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. to: Other Examples These are more complex examples for using particular electronic components or accomplishing specific tasks. at 11:54 PM by David A. Curricula. Code Library and Tutorials: Arduino functions for performing specific tasks and other programming tutorials. The code is included in the tutorial. 2008. The code is included in the tutorial. Electronics Techniques: tutorials on soldering and other electronics resources. communication. Changed lines 36-42 from: (:cell width=50%:) Tutorials These are more complex tutorials for using particular electronic components or accomplishing specific tasks. ladyada's tutorials.adding links to other pages: the tutorial parts of the playground. Interfacing With Hardware: Code. Flash. input / output.linking to board setup and configuration on the playground. More Tutorials Restore January 11. Mellis . Analog Input Pins: Details about the analog-to-digital conversion and other uses of the pins. Mellis . Restore December 19. Max/MSP). and Other Resources Arduino Booklet (pdf): an illustrated guide to the philosophy and practice of Arduino. 2007.Added lines 74-81: Memory: The various types of memory available on the Arduino board. Learn electronics using Arduino: an introduction to programming. Added lines 76-77: Board Setup and Configuration: Information about the components and usage of Arduino hardware. Processing. at 11:31 AM by David A. Output Input Interaction Storage Communication Interfacing with Software: how to get an Arduino board talking to software running on the computer (e. etc. todbot. 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. and instructions for using various electronic components with an Arduino board. PD. By .g. Manuals. using Arduino. etc. Hosted on the publicly-editable playground wiki. circuits.

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

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

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. at 06:06 AM by Paul Badger Changed lines 17-18 from: to: . 2007.

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

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

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

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

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

Interfacing with Other Software Introduction to Serial Communication (from ITP physcomp labs) Arduino + Flash Arduino + Processing . The libraries? page explains how to use libraries in your sketches and how to make your own. 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 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.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ 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 .

These pins cannot be used for digital i/o (digitalRead and digitalWrite) if you are also using serial communication (e.X1 (pink) Toggles External Power and USB Power (place jumper on two pins closest to desired supply) . this is an outline of what you will see (parts of the board you might interact with in the course of normal use are highlighted): Starting clockwise from the top center: Analog Reference pin (orange) Digital Ground (light green) Digital Pins 2-13 (green) Digital Pins 0-1/Serial In/Out .S1 (dark blue) In-circuit Serial Programmer (blue-green) Analog In Pins 0-5 (light blue) Power and Ground Pins (power: orange.Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ (redirected from Tutorial. LilyPad Arduino.ArduinoBoard) Guide Contents | Introduction | How To: Windows. Mac OS X. the digital pins on an Arduino board can be used for general purpose input and output via the pinMode(). digitalRead(). can be used to power the board) (yellow) Digital Pins In addition to the specific functions listed below. Linux. . Reset Button . Each pin has an internal pull-up resistor which can be turned on and off using digitalWrite() (w/ a value of HIGH or LOW. and digitalWrite() commands. Arduino Nano. Xbee shield | Troubleshooting | Environment (:redirect Reference/Board:) search Blog » | Forum » | Playground » Introduction to the Arduino Board Looking at the board from the top down. Arduino BT. The maximum current per pin is 40 mA.SV1 (purple) USB (used for uploading sketches to the board and for serial communication between the board and the computer.TX/RX (dark green) . Arduino Mini.begin). Serial.g. respectively) when the pin is configured as an input. grounds: light orange) External Power Supply In (9-12VDC) .

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

Arduino Buy | Download | Getting Started | Learning | Reference | Hardware | FAQ 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