(edit sidebar)
Intro to Physical Computing Syllabus

Research & Learning

Other Class pages

Shop Admin

ITP Help Pages
Tom's pcomp site
DanO's pcomp site


Digital Input and Output with an Arduino

Labs.DigitalInOut History

Hide minor edits - Show changes to output

Changed lines 121-122 from:
''This is a suggestion for a possible project.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction.''
to:
''This is just a suggestion for a short project.  It's not a requirement for the class homework.''
Changed lines 64-65 from:
Connect the microcontroller to your computer via USB. When you plug teh Arduino into your computer, you'll find a new serial port in the Tools-->Serial Port menu (for details on installing the software, and USB-to-serial drivers for older Arduino models, see the [[http://arduino.cc/en/Guide/HomePage|Arduino Getting Started Guide]]). In OSX, the name will begin with /dev/tty.usbmodem- if it's an Arduino Uno later, and /dev/tty.usbserial- if it's a Duemilanove or earlier. In Windows it will start with COM like all the other serial ports.
to:
Connect the microcontroller to your computer via USB. When you plug the Arduino into your computer, you'll find a new serial port in the Tools-->Serial Port menu (for details on installing the software, and USB-to-serial drivers for older Arduino models, see the [[http://arduino.cc/en/Guide/HomePage|Arduino Getting Started Guide]]). In OSX, the name will begin with /dev/tty.usbmodem- if it's an Arduino Uno later, and /dev/tty.usbserial- if it's a Duemilanove or earlier. In Windows it will start with COM like all the other serial ports.
Changed line 19 from:
%lframe width=100px% [[Attach:resistors.jpg|Attach:resistors.jpg"220-ohm and 10kilohm resistors"]] | [-220-ohm and 10kilohm resistors-]
to:
%lframe width=100px% [[Attach:resistors.jpg|Attach:resistors.jpg"220-ohm and 10kilohm resistors"]] | [-560-ohm and 10kilohm resistors-]
Changed lines 1-2 from:
(:title Analog In with an Arduino:)
to:
(:title Digital Input and Output with an Arduino:)
Changed lines 5-6 from:
In this lab, you'll learn how to connect a variable resistor to a microcontroller and read it as an analog input.  You'll be able to read changing conditions from the physical world and convert them to changing variables in a program.
to:
In this lab, you'll connect a digital input circuit and a digital output circuit to a microcontroller. Though this is written for the Arduino microcontroller module, the principles apply to any microcontroller.
Changed lines 9-16 from:
!!! Parts

For this lab you will need to have the following parts:

%lframe width=100px% [[Attach:breadboard.jpg | Attach:breadboard.jpg"Solderless breadboard"]] | [-Solderless breadboard-]
%lframe width=100px% [[Attach:hookup_wire.jpg | Attach:hookup_wire.jpg"hookup wire"]] | [-22-AWG hookup wire-]
%lframe width=100px% [[Attach:arduino.jpg | Attach:arduino.jpg"Arduino module"]] | [-Arduino Microcontroller \\
module-]
to:
!!!Parts

For this lab you will need the following parts:

%lframe width=100px valign=center%[[Attach:breadboard.jpg|Attach:breadboard.jpg"solderless breadboard"]] | [-Solderless breadboard-]
%lframe width=100px% [[Attach:hookup_wire.jpg|Attach:hookup_wire.jpg"Hookup wire"]] | [-22-AWG hookup wire-]
%lframe width=100px% [[Attach:arduino.jpg|Attach:arduino.jpg"Arduino microcontroller module"]] | [-Arduino microcontroller module-]
Changed lines 18-24 from:
%lframe width=100px valign=center% [[Attach:leds.jpg | Attach:leds.jpg"Light Emiting Diodes"]] | [-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% [[Attach:resistors_220.jpg | Attach:resistors_220.jpg"resistors"]] | [-560-ohm (anything from 220 to 1K) and 10Kohm resistors-]
%lframe width=90px valign=center% [[Attach:potentiometer.jpg | Attach:potentiometer.jpg"potentiometer"]] | [-10Kohm potentiometer-]
Variable resistors
%lframe width=90px valign=center% [[Attach:flex_sensors.jpg | Attach:flex_sensors.jpg"potentiometer"]] | [-Flex sensors\\
(or a different\\
 form of variable resistor)-]
to:
%lframe width=100px% [[Attach:leds.jpg|Attach:leds.jpg"LEDs"]] | [-Light Emitting Diodes, LEDs-]
%lframe width=100px% [[Attach:resistors.jpg|Attach:resistors.jpg"220-ohm and 10kilohm resistors"]] | [-220-ohm and 10kilohm resistors-]
%lframe width=100px% [[Attach:switch.jpg|Attach:switch.jpg"switch"]] | [-switch or pushbutton
-]
Added lines 24-25:
Click on any image for a larger view
Changed lines 27-28 from:
Conect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:
to:
Connect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:
Added lines 31-39:
[--(Diagram made with [[http://fritzing.org | Fritzing]] --]

!!! Add a Digital Input (a switch)

Connect a switch to digital input 2 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.

%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Arduino with switch on digital pin 2
%lframe height=300  hspace=10 alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Schematic view
[[<<]]
Changed lines 41-47 from:


!!! Add a potentiometer and LED

Connect
a potentiometer to analog in pin 0 of the module, and an LED to digital pin 9:

%lframe alt='Arduino with potentiometer and LED'
hspace=10 height=300%[[Attach:analog_in_lab_pot_and_led_bb.png|Attach:analog_in_lab_pot_and_led_bb.png]]
to:
!!! Add Digital Outputs (LEDs)

Connect
a 560-ohm resistor and an LED in series to digital pin 3 and another to digital pin 4 of the Arduino.

%lframe height=300
hspace=10 %[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]  | Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 %[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]]  | Schematic view

Changed lines 50-60 from:
%lframe alt='Arduino with potentiometer and LED schematic' hspace=10 height=300%[[Attach:arduino_analog_input_schem.png|Attach:arduino_analog_input_schem.png]]
[[<<]]


!!! Program the Module

Program your Arduino as follows:

First, establish some global variables: One to hold the value returned by the potentiometer, and another to hold the brightness value. Make a global constant to give the LED's pin number a name.

(:toggle question1 init=hide show='I give up, how do I do that
?' hide='Let me figure it out':)
to:

What happens if you don't include the resistor connecting the switch to ground?

(:toggle question1 init
=hide show='I give up, what should happen?' hide='Let me figure it out':)
Changed lines 55-59 from:
(:source lang=arduino tabwidth=4 :)
const int ledPin = 9 // pin that
the LED is attached to
int analogValue = 0;        // value read from the pot
int brightness = 0;        // PWM pin that the LED is on
.
(:sourceend:)
to:
The resistor connecting the switch is a '''pulldown resistor'''. It provides the digital input pin with a reference to ground. Without it, the input will behave unreliably.
Changed lines 58-59 from:
In the setup() method, initialize serial communications at 9600 bits per second, and set the LED's pin to be an output.
to:

'''A note on resistor values:''' if you don't have a 10-kilohm resistor for
the switch, you can use any reasonably high value. 4.7K, 22K, and even 1 Megohm resistors have been tested with this circuit and they work fine.  As for the resistor on the LED, the higher the resistor value, the dimmer your LED will be.  So 220-ohm resistors give you a nice bright LED, 1-kilohm will make it dimmer, and 10K or higher will likely make it too dim to see.

----
!!! Program the Arduino

Connect the microcontroller to your computer via USB. When you plug teh Arduino into your computer, you'll find a new serial port in the Tools-->Serial Port menu (for details on installing the software, and USB-to-serial drivers for older Arduino models, see the [[http://arduino.cc/en/Guide/HomePage|Arduino Getting Started Guide]]). In OSX, the name will begin with /dev/tty.usbmodem- if it's an Arduino Uno later, and /dev/tty.usbserial- if it's a Duemilanove or earlier. In Windows it will start with COM like all the other serial ports.

%alt='arduino serial port menu'%http://itp.nyu.edu/physcomp/images/labs/arduino_tools_menu.png


Write a program that reads the digital input on pin 2. When the switch is pressed, turn the yellow LED on and the red one off.  When the  switch is released, turn the red LED on and the yellow LED off.

In your setup() method, you need to set the three pins you're using as inputs or outputs, appropriately.


Changed lines 77-82 from:
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin
(9600);
// declare the led pin as an output:
pinMode(led,
OUTPUT);
}
to:
 
 void setup() {
  pinMode
(2, INPUT);     // set the switch pin to be an input
  pinMode(3,
OUTPUT);   // set the yellow LED pin to be an output
  pinMode(4, OUTPUT);  // set the red LED pin to be an output
 
}
Changed lines 86-87 from:
In the main loop, read the analog value using analogRead() and put the result into the variable that holds the analog value.  Then divide the analog value by 4 to get it into a range from 0 to 255.  Then use the analogWrite() command to face the LED.  Then print out the brightness value.
to:
In the main loop, first you need an if-then-else statement to read the switch.
Changed lines 91-96 from:
void loop() {
analogValue = analogRead
(A0); // read the pot value
brightness = analogValue /4; //divide by 4 to fit in a byte
analogWrite(led, brightness
); // PWM the LED with the brightness value
Serial.println(brightness); // print the brightness value back to the serial monitor
}
to:
 
 void loop() {
  // read the switch input:
  if (digitalRead(2) == HIGH
) {
    // if the switch is closed:
    digitalWrite(3, HIGH);    // turn on the yellow LED
    digitalWrite(4, LOW);    // turn off the red LED
 
} 
  else {
    // if the switch is open:
    digitalWrite(3, LOW);    // turn off the yellow LED
    digitalWrite(4, HIGH);    // turn on the red LED
  }
 }

Changed lines 109-120 from:
When you run this code, the LED should dim up and down as you turn the pot, and the brightness value should show up in the serial monitor.

!!! Other variable resistors

You can use many different types of variable resistors for analog input.  For example,
the pink monkey in the photo below has his arms wired with flex sensors. These sensors change their resistance as they are flexed.  When the monkey's arms move up and down, the values of the flex sensors change the brightness of two LEDs.  The same values could be used to control servo motors, change the frequency on a speaker, or move servo motors. 

%alt='Monski with analog sensors'% [[Attach:monski_analog.JPG|Attach:monski_analog.JPG]]

(
Here's an example circuit much like the pink monkey circuit above, but with force
-sensing resistors instead of flex sensors.

%lframe alt='Arduino with variable resistors and LED' hspace=10 width=300%[[Attach:arduino_fsrs_bb.png|Attach:arduino_fsrs_bb.png]]
to:

Once
you're done with that, you're ready to compile your sketch and upload it. Click the Verify button to compile your code. Then click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.

[@
Binary sketch size: 5522 bytes (of a 7168 byte maximum)

@]
Press the switch and watch the LEDs change until you get bored. That's all there is to basic digital input and output!
----
Changed lines 119-120 from:
[--(Diagram made with [[http://fritzing.org | Fritzing]])--]
%lframe alt='Arduino with variable resistors and LED schematic' hspace=10 width=300%[[Attach:arduino_fsrs_schem
.png|Attach:arduino_fsrs_schem.png]]
to:
!!! Get Creative

''This is a suggestion for a possible project.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction
.''

Many projects can be made with just digital input and output
. For example, a combination lock is just a series of switches that have been switched in a particular sequence. Consider the cymbal-playing monkey below:

http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey.jpg

His cymbals can be turned into a switch by lining them with tin foil and screwing wires to them:

%lfloat%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail1.jpg
%rfloat%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail2.jpg
Changed lines 132-182 from:

The circuit above works for any variable resistor. It's called a '''voltage divider'''. There are two voltage dividers, one on analog in 0 and one on analog in 1. The fixed resistor in each circuit should have the same order of magnitude as the variable resistor's range.  For example, if you're using a flex sensor with a range of 50 - 100 kilohms, you might use a 47Kohm or a 100Kohm fixed resistor. If you're using a force sensing resistor that goes from inifinity ohms to 10 ohms, but most of its range is between 10Kohms and 10 ohms, you might use a 10Kohm fixed resistor.

The code above assumed you were using a potentiometer, which always gives the full range of analog input, which is 0 to 1023.  Dividing by 4 gives you a range of 0 to 255, which is the full output range of the @@analogWrite()@@ command. The voltage divider circuit, on the other hand, can't give you the full range. The fixed resistor in the circuit limits the range.  You'll need to modify the code. 

To find out your range, open the serial monitor and watch the printout as you press the FSR or flex the flex sensor.  Note the maximum value and the minimum value. Then you can map the range that the sensor actually gives as input to the range that the LED needs as output. For example, if your photocell gives a range from 400 to 900, you'd do this:

(:div class=code :)
 %color=#7e7e7e%// map the sensor vaue from the input range (400 - 900, for example) to the output range (0-255):
 %color=#cc6600%int%% brightness = %color=#cc6600%map%%(sensorValue, 400, 900, 0, 255);
 %color=#cc6600%analogWrite%%(led, brightness);
(:divend:)

Here's an alternate version of the program above for this circuit:

(:div class=code :)
 
 %color=#cc6600%int%% potPin = 0;    %color=#7e7e7e%// Analog input pin that the potentiometer is attached to
 %color=#cc6600%int%% sensorValue = 0;  %color=#7e7e7e%// value read from the analog sensor
 %color=#cc6600%int%% led = 9;    %color=#7e7e7e%// PWM pin that the LED is on.  n.b. PWM 0 is on digital pin 9
 
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// initialize serial communications at 9600 bps:
  %color=#cc6600%Serial%%.%color=#cc6600%begin%%(9600);
  %color=#7e7e7e%// declare the led pin as an output:
  %color=#cc6600%pinMode%%(led, %color=#006699%OUTPUT%%);
 }
 
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  sensorValue = %color=#cc6600%analogRead%%(potPin); %color=#7e7e7e%// read the pot value
 
  %color=#7e7e7e%// map the sensor vaue from the input range (400 - 900, for example)
  %color=#7e7e7e%// to the output range (0-255). Change the values 400 and 900 below
  %color=#7e7e7e%// to match the range your analog input gives:
  %color=#cc6600%int%% brightness = %color=#cc6600%map%%(sensorValue, 400, 900, 0, 255);
 
  %color=#cc6600%analogWrite%%(led, brightness);  %color=#7e7e7e%// set the LED brightness with the result
  %color=#cc6600%Serial%%.%color=#cc6600%println%%(sensorValue);  %color=#7e7e7e%// print the pot value back to the debugger pane
  %color=#cc6600%delay%%(10);                    %color=#7e7e7e%// wait 10 milliseconds before the next loop
 }
 
(:divend:)


!!! Get creative


''This is a suggestion for the Stupid Pet Trick assignment.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction. This is just one suggestion.''

Make a luv-o-meter with analog inputs.  A luv-o-meter is a device that measures a person's potential to be a lover, and displays it on a graph of lights.  In gaming arcades, the luv-o-meter is usually a handle that a person grips, and his or her grip is measured either for its strength or its sweatiness. But your luv-o-meter can measure any analog physical quantity that you want, providing you have a sensor for it. Make sure the display is clear, so the participant knows what it means, and make sure it is responsive.

to:
Those wires can be run to a breadboard and used as a switch.  Then the microcontroller could be programmed to listen for pattern of cymbal crashes, and if it sees that pattern, to open a lock by switching on a digital output.

Come up with your own physical interface for a combination lock.
Changed lines 1-2 from:
(:title Digital Input and Output with an Arduino:)
to:
(:title Analog In with an Arduino:)
Changed lines 5-6 from:
In this lab, you'll connect a digital input circuit and a digital output circuit to a microcontroller. Though this is written for the Arduino microcontroller module, the principles apply to any microcontroller.
to:
In this lab, you'll learn how to connect a variable resistor to a microcontroller and read it as an analog input.  You'll be able to read changing conditions from the physical world and convert them to changing variables in a program.
Changed lines 9-16 from:
!!!Parts

For this lab you will need the following parts:

%lframe width=100px valign=center%[[Attach:breadboard.jpg|Attach:breadboard.jpg"solderless breadboard"]] | [-Solderless breadboard-]
%lframe width=100px% [[Attach:hookup_wire.jpg|Attach:hookup_wire.jpg"Hookup wire"]] | [-22-AWG hookup wire-]
%lframe width=100px% [[Attach:arduino.jpg|Attach:arduino.jpg"Arduino microcontroller module"]] | [-Arduino microcontroller module-]
to:
!!! Parts

For this lab you will need to have the following parts:

%lframe width=100px% [[Attach:breadboard.jpg | Attach:breadboard.jpg"Solderless breadboard"]] | [-Solderless breadboard-]
%lframe width=100px% [[Attach:hookup_wire.jpg | Attach:hookup_wire.jpg"hookup wire"]] | [-22-AWG hookup wire-]
%lframe width=100px% [[Attach:arduino.jpg | Attach:arduino.jpg"Arduino module"]] | [-Arduino Microcontroller \\
module-]
Changed lines 18-21 from:
%lframe width=100px% [[Attach:leds.jpg|Attach:leds.jpg"LEDs"]] | [-Light Emitting Diodes, LEDs-]
%lframe width=100px% [[Attach:resistors.jpg|Attach:resistors.jpg"220-ohm and 10kilohm resistors"]] | [-220-ohm and 10kilohm resistors-]
%lframe width=100px% [[Attach:switch.jpg|Attach:switch.jpg"switch"]] | [-switch or pushbutton
-]
to:
%lframe width=100px valign=center% [[Attach:leds.jpg | Attach:leds.jpg"Light Emiting Diodes"]] | [-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% [[Attach:resistors_220.jpg | Attach:resistors_220.jpg"resistors"]] | [-560-ohm (anything from 220 to 1K) and 10Kohm resistors-]
%lframe width=90px valign=center% [[Attach:potentiometer.jpg | Attach:potentiometer.jpg"potentiometer"]] | [-10Kohm potentiometer-]
Variable resistors
%lframe width=90px valign=center% [[Attach:flex_sensors.jpg | Attach:flex_sensors.jpg"potentiometer"]] | [-Flex sensors\\
(or a different\\
 form of variable resistor)-]
Deleted lines 26-27:
Click on any image for a larger view
Changed lines 28-29 from:
Connect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:
to:
Conect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:
Deleted lines 31-39:
[--(Diagram made with [[http://fritzing.org | Fritzing]] --]

!!! Add a Digital Input (a switch)

Connect a switch to digital input 2 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.

%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Arduino with switch on digital pin 2
%lframe height=300  hspace=10 alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Schematic view
[[<<]]
Changed lines 33-39 from:
!!! Add Digital Outputs (LEDs)

Connect
a 560-ohm resistor and an LED in series to digital pin 3 and another to digital pin 4 of the Arduino.

%lframe height=300
hspace=10 %[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]  | Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 %[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]]  | Schematic view

to:


!!! Add a potentiometer and LED

Connect
a potentiometer to analog in pin 0 of the module, and an LED to digital pin 9:

%lframe alt='Arduino with potentiometer and LED'
hspace=10 height=300%[[Attach:analog_in_lab_pot_and_led_bb.png|Attach:analog_in_lab_pot_and_led_bb.png]]
Changed lines 42-45 from:

What happens if you don't include the resistor connecting the switch to ground?

(:toggle question1 init
=hide show='I give up, what should happen?' hide='Let me figure it out':)
to:
%lframe alt='Arduino with potentiometer and LED schematic' hspace=10 height=300%[[Attach:arduino_analog_input_schem.png|Attach:arduino_analog_input_schem.png]]
[[<<]]


!!! Program the Module

Program your Arduino as follows:

First, establish some global variables: One to hold the value returned by the potentiometer, and another to hold the brightness value. Make a global constant to give the LED's pin number a name.

(:toggle question1 init=hide show='I give up, how do I do that
?' hide='Let me figure it out':)
Changed lines 54-58 from:
The resistor connecting the switch is a '''pulldown resistor'''. It provides the digital input pin with a reference to ground. Without it, the input will behave unreliably.
to:
(:source lang=arduino tabwidth=4 :)
const int ledPin = 9 // pin that
the LED is attached to
int analogValue = 0;        // value read from the pot
int brightness = 0;        // PWM pin that the LED is on
.
(:sourceend:)
Changed lines 61-76 from:

'''A note on resistor values:''' if you don't have a 10-kilohm resistor for
the switch, you can use any reasonably high value. 4.7K, 22K, and even 1 Megohm resistors have been tested with this circuit and they work fine.  As for the resistor on the LED, the higher the resistor value, the dimmer your LED will be.  So 220-ohm resistors give you a nice bright LED, 1-kilohm will make it dimmer, and 10K or higher will likely make it too dim to see.

----
!!! Program the Arduino

Connect the microcontroller to your computer via USB. When you plug teh Arduino into your computer, you'll find a new serial port in the Tools-->Serial Port menu (for details on installing the software, and USB-to-serial drivers for older Arduino models, see the [[http://arduino.cc/en/Guide/HomePage|Arduino Getting Started Guide]]). In OSX, the name will begin with /dev/tty.usbmodem- if it's an Arduino Uno later, and /dev/tty.usbserial- if it's a Duemilanove or earlier. In Windows it will start with COM like all the other serial ports.

%alt='arduino serial port menu'%http://itp.nyu.edu/physcomp/images/labs/arduino_tools_menu.png


Write a program that reads the digital input on pin 2. When the switch is pressed, turn the yellow LED on and the red one off.  When the  switch is released, turn the red LED on and the yellow LED off.

In your setup() method, you need to set the three pins you're using as inputs or outputs, appropriately.


to:
In the setup() method, initialize serial communications at 9600 bits per second, and set the LED's pin to be an output.
Changed lines 66-71 from:
 
 void setup() {
  pinMode
(2, INPUT);     // set the switch pin to be an input
  pinMode(3,
OUTPUT);   // set the yellow LED pin to be an output
  pinMode(4, OUTPUT);  // set the red LED pin to be an output
 
}
to:
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin
(9600);
// declare the led pin as an output:
pinMode(led,
OUTPUT);
}
Changed lines 75-76 from:
In the main loop, first you need an if-then-else statement to read the switch.
to:
In the main loop, read the analog value using analogRead() and put the result into the variable that holds the analog value.  Then divide the analog value by 4 to get it into a range from 0 to 255.  Then use the analogWrite() command to face the LED.  Then print out the brightness value.
Changed lines 80-94 from:
 
 void loop() {
  // read the switch input:
  if (digitalRead(2) == HIGH
) {
    // if the switch is closed:
    digitalWrite(3, HIGH);    // turn on the yellow LED
    digitalWrite(4, LOW);    // turn off the red LED
 
} 
  else {
    // if the switch is open:
    digitalWrite(3, LOW);    // turn off the yellow LED
    digitalWrite(4, HIGH);    // turn on the red LED
  }
 }

to:
void loop() {
analogValue = analogRead
(A0); // read the pot value
brightness = analogValue /4; //divide by 4 to fit in a byte
analogWrite(led, brightness
); // PWM the LED with the brightness value
Serial.println(brightness); // print the brightness value back to the serial monitor
}
Changed lines 89-97 from:

Once
you're done with that, you're ready to compile your sketch and upload it. Click the Verify button to compile your code. Then click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.

[@
Binary sketch size: 5522 bytes (of a 7168 byte maximum)

@]
Press the switch and watch the LEDs change until you get bored. That's all there is to basic digital input and output!
----
to:
When you run this code, the LED should dim up and down as you turn the pot, and the brightness value should show up in the serial monitor.

!!! Other variable resistors

You can use many different types of variable resistors for analog input.  For example,
the pink monkey in the photo below has his arms wired with flex sensors. These sensors change their resistance as they are flexed.  When the monkey's arms move up and down, the values of the flex sensors change the brightness of two LEDs.  The same values could be used to control servo motors, change the frequency on a speaker, or move servo motors. 

%alt='Monski with analog sensors'% [[Attach:monski_analog.JPG|Attach:monski_analog.JPG]]

(
Here's an example circuit much like the pink monkey circuit above, but with force
-sensing resistors instead of flex sensors.

%lframe alt='Arduino with variable resistors and LED' hspace=10 width=300%[[Attach:arduino_fsrs_bb.png|Attach:arduino_fsrs_bb.png]]
Changed lines 102-113 from:
!!! Get Creative

''This is a suggestion for a possible project.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction
.''

Many projects can be made with just digital input and output
. For example, a combination lock is just a series of switches that have been switched in a particular sequence. Consider the cymbal-playing monkey below:

http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey.jpg

His cymbals can be turned into a switch by lining them with tin foil and screwing wires to them:

%lfloat%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail1.jpg
%rfloat%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail2.jpg
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]])--]
%lframe alt='Arduino with variable resistors and LED schematic' hspace=10 width=300%[[Attach:arduino_fsrs_schem
.png|Attach:arduino_fsrs_schem.png]]
Changed lines 105-107 from:
Those wires can be run to a breadboard and used as a switch.  Then the microcontroller could be programmed to listen for pattern of cymbal crashes, and if it sees that pattern, to open a lock by switching on a digital output.

Come up with your own physical interface for a combination lock.
to:

The circuit above works for any variable resistor. It's called a '''voltage divider'''. There are two voltage dividers, one on analog in 0 and one on analog in 1. The fixed resistor in each circuit should have the same order of magnitude as the variable resistor's range.  For example, if you're using a flex sensor with a range of 50 - 100 kilohms, you might use a 47Kohm or a 100Kohm fixed resistor. If you're using a force sensing resistor that goes from inifinity ohms to 10 ohms, but most of its range is between 10Kohms and 10 ohms, you might use a 10Kohm fixed resistor.

The code above assumed you were using a potentiometer, which always gives the full range of analog input, which is 0 to 1023.  Dividing by 4 gives you a range of 0 to 255, which is the full output range of the @@analogWrite()@@ command. The voltage divider circuit, on the other hand, can't give you the full range. The fixed resistor in the circuit limits the range.  You'll need to modify the code. 

To find out your range, open the serial monitor and watch the printout as you press the FSR or flex the flex sensor.  Note the maximum value and the minimum value. Then you can map the range that the sensor actually gives as input to the range that the LED needs as output. For example, if your photocell gives a range from 400 to 900, you'd do this:

(:div class=code :)
 %color=#7e7e7e%// map the sensor vaue from the input range (400 - 900, for example) to the output range (0-255):
 %color=#cc6600%int%% brightness = %color=#cc6600%map%%(sensorValue, 400, 900, 0, 255);
 %color=#cc6600%analogWrite%%(led, brightness);
(:divend:)

Here's an alternate version of the program above for this circuit:

(:div class=code :)
 
 %color=#cc6600%int%% potPin = 0;    %color=#7e7e7e%// Analog input pin that the potentiometer is attached to
 %color=#cc6600%int%% sensorValue = 0;  %color=#7e7e7e%// value read from the analog sensor
 %color=#cc6600%int%% led = 9;    %color=#7e7e7e%// PWM pin that the LED is on.  n.b. PWM 0 is on digital pin 9
 
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#7e7e7e%// initialize serial communications at 9600 bps:
  %color=#cc6600%Serial%%.%color=#cc6600%begin%%(9600);
  %color=#7e7e7e%// declare the led pin as an output:
  %color=#cc6600%pinMode%%(led, %color=#006699%OUTPUT%%);
 }
 
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  sensorValue = %color=#cc6600%analogRead%%(potPin); %color=#7e7e7e%// read the pot value
 
  %color=#7e7e7e%// map the sensor vaue from the input range (400 - 900, for example)
  %color=#7e7e7e%// to the output range (0-255). Change the values 400 and 900 below
  %color=#7e7e7e%// to match the range your analog input gives:
  %color=#cc6600%int%% brightness = %color=#cc6600%map%%(sensorValue, 400, 900, 0, 255);
 
  %color=#cc6600%analogWrite%%(led, brightness);  %color=#7e7e7e%// set the LED brightness with the result
  %color=#cc6600%Serial%%.%color=#cc6600%println%%(sensorValue);  %color=#7e7e7e%// print the pot value back to the debugger pane
  %color=#cc6600%delay%%(10);                    %color=#7e7e7e%// wait 10 milliseconds before the next loop
 }
 
(:divend:)


!!! Get creative


''This is a suggestion for the Stupid Pet Trick assignment.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction. This is just one suggestion.''

Make a luv-o-meter with analog inputs.  A luv-o-meter is a device that measures a person's potential to be a lover, and displays it on a graph of lights.  In gaming arcades, the luv-o-meter is usually a handle that a person grips, and his or her grip is measured either for its strength or its sweatiness. But your luv-o-meter can measure any analog physical quantity that you want, providing you have a sensor for it. Make sure the display is clear, so the participant knows what it means, and make sure it is responsive.

Changed lines 110-111 from:
 Once you're done with that, you're ready to compile your sketch and upload it. Click the Verify button to compile your code. Then click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.
to:
Once you're done with that, you're ready to compile your sketch and upload it. Click the Verify button to compile your code. Then click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.
Changed lines 88-89 from:
(:toggle question2 init=hide show='I give up, how do I do that?' hide='Let me figure it out':)
>>id=question2 border='1px solid #999' padding=5px bgcolor=#e1e7f1<<
to:
(:toggle question3 init=hide show='I give up, how do I do that?' hide='Let me figure it out':)
>>id=question3 border='1px solid #999' padding=5px bgcolor=#e1e7f1<<
Changed lines 68-75 from:
Here's a program that reads the digital input on pin 4. Then it turns on the LED on pin 2 if the input is high (i.e. the switch is on), or turns on the LED on pin 3 is the input is low (the switch is off):
to:

Write
a program that reads the digital input on pin 2. When the switch is pressed, turn the yellow LED on and the red one off.  When the  switch is released, turn the red LED on and the yellow LED off.

In your setup
() method, you need to set the three pins you're using as inputs or outputs, appropriately.


(
:toggle question2 init=hide show='I give up, how do I do that?' hide='Let me figure it out':)
>>id=question2 border='1px solid #999' padding=5px bgcolor=#e1e7f1<<
Changed lines 83-91 from:
 
to:
(:sourceend:)
>><<

In the main loop, first you need an if-then-else statement to read the switch.

(:toggle question2 init=hide show='I give up, how do I do that?' hide='Let me figure it out':)
>>id=question2 border='1px solid #999' padding=5px bgcolor=#e1e7f1<<
(:source lang=arduino tabwidth=4 :)
 
Changed line 97 from:
     digitalWrite(4, LOW);      // turn off the red LED
to:
     digitalWrite(4, LOW);    // turn off the red LED
Changed lines 101-102 from:
     digitalWrite(3, LOW);  // turn off the yellow LED
 
  digitalWrite(4, HIGH);     // turn on the red LED
to:
     digitalWrite(3, LOW);     // turn off the yellow LED
    digitalWrite(4, HIGH);    // turn on the red LED
Changed line 105 from:
 
to:
Changed lines 107-109 from:

Click the Verify button to compile this code. Then press the reset button on the Arduino module and click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.
to:
>><<


 Once you're done with that, you're ready to compile your sketch and upload it. Click the Verify button to compile your code. Then
click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.
Changed lines 64-65 from:
Connect the microcontroller to your computer via USB.  Assuming you've installed the Arduino software environment and the USB-to-serial drivers correctly, you'll find a new serial port in the Tools-->Serial Port menu. in OSX, the name will begin with /dev/tty.usbserial-.  In Windows it will start with COM like all the other serial ports.
to:
Connect the microcontroller to your computer via USB. When you plug teh Arduino into your computer, you'll find a new serial port in the Tools-->Serial Port menu (for details on installing the software, and USB-to-serial drivers for older Arduino models, see the [[http://arduino.cc/en/Guide/HomePage|Arduino Getting Started Guide]]). In OSX, the name will begin with /dev/tty.usbmodem- if it's an Arduino Uno later, and /dev/tty.usbserial- if it's a Duemilanove or earlier. In Windows it will start with COM like all the other serial ports.
Added line 30:
[[<<]]
Deleted line 32:
[[<<]]
Added line 32:
[[<<]]
Added line 31:
Changed lines 49-50 from:
Whaat happens if you don't include the resistor connecting the switch to ground?
to:
What happens if you don't include the resistor connecting the switch to ground?
Changed line 53 from:
The resistor connecting the switch is a '''pullwodn resistor'''. It provides the digital input pin with a reference to ground. Without it, the input will behave unreliably.
to:
The resistor connecting the switch is a '''pulldown resistor'''. It provides the digital input pin with a reference to ground. Without it, the input will behave unreliably.
Added lines 49-55:
Whaat happens if you don't include the resistor connecting the switch to ground?
(:toggle question1 init=hide show='I give up, what should happen?' hide='Let me figure it out':)
>>id=question1 border='1px solid #999' padding=5px bgcolor=#e1e7f1<<
The resistor connecting the switch is a '''pullwodn resistor'''. It provides the digital input pin with a reference to ground. Without it, the input will behave unreliably.
>><<

Changed lines 29-30 from:
%height=300 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:arduino_and_breadboard.zip | download]])--]
to:
%lframe height=300 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
[--(Diagram made with [[http://fritzing.org | Fritzing]] --]
Changed lines 43-45 from:
%lframe height=300 hspace=10 %[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 %[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
to:
%lframe height=300 hspace=10 %[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]  | Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 %[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]]  | Schematic view
Changed lines 43-45 from:
%lframe height=300 hspace=10 alt='add LEDs'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 alt='add LEDs'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
to:
%lframe height=300 hspace=10 %[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 %[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
Changed lines 43-45 from:
%lframe height=300 hspace=10 alt='add LEDS'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
to:
%lframe height=300 hspace=10 alt='add LEDs'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 alt='add LEDs'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
Changed line 43 from:
%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Add LEDs on pins 3 and 4
to:
%lframe height=300 hspace=10 alt='add LEDS'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Add LEDs on pins 3 and 4
Changed lines 43-45 from:
%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Arduino with switch on digital pin 2
%lframe
height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]] |Add LEDs on pins 3 and 4
to:
%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Add LEDs on pins 3 and 4
%lframe
height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
Changed line 38 from:
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]])--]
Added line 43:
%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Arduino with switch on digital pin 2
Changed lines 47-48 from:
[--(Diagram made with [[http://fritzing.org | Fritzing]]--]
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]])--]
Changed lines 38-39 from:
[--(Diagram made with [[http://fritzing.org | Fritzing]]--]
to:
Added line 41:
Changed lines 45-46 from:
%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] |Schematic view
to:
Changed lines 35-36 from:
%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%lframe height=300  hspace=10 alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
to:
%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]  | Arduino with switch on digital pin 2
%lframe height=300  hspace=10 alt=
'schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Schematic view
Changed lines 41-45 from:
Connect a 5600-ohm resistor and an LED in series to digital pin 3 and another to digital pin 4 of the Arduino.

%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] |Add LEDs on pins 3 and 4
to:
Connect a 560-ohm resistor and an LED in series to digital pin 3 and another to digital pin 4 of the Arduino.

%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]] |Add LEDs on pins 3 and 4
%lframe height=300 hspace=10 alt=
'add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] |Schematic view
Changed lines 43-44 from:
%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
%lframe height=300 hspace=10 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]]
to:
%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
%lframe height=300 hspace=10 alt='add LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] |Add LEDs on pins 3 and 4
Added line 37:
[[<<]]
Changed lines 39-40 from:
[[<<]]
to:
Changed lines 44-45 from:

%lframe height=300 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] | Arduino with switch on digital pin 2 and LEDs on pins 3 and 4
to:
%lframe height=300 hspace=10 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]]
[[<<]]
Changed lines 43-44 from:
%lframe height=300 alt='Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
to:
%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
Changed lines 35-36 from:
%height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%height=300  hspace=10 alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
to:
%lframe height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%lframe height=300  hspace=10 alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
Changed lines 43-45 from:
%lfloat height=300 alt='Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]

%rfloat height=300 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] | Arduino with switch on digital pin 2 and LEDs on pins 3 and 4
to:
%lframe height=300 alt='Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]

%lframe height=300 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] | Arduino with switch on digital pin 2 and LEDs on pins 3 and 4
Changed lines 35-36 from:
%lfloat height=300 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%rfloat height=300  alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
to:
%height=300 hspace=10 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%height=300  hspace=10 alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
Changed lines 38-39 from:

to:
[[<<]]
Changed lines 35-36 from:
%height=300 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%height=300  alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
to:
%lfloat height=300 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%rfloat height=300  alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
Added line 44:
Changed line 29 from:
%height=200 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
to:
%height=300 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
Changed lines 35-36 from:
%height=200 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%width=200  alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
to:
%height=300 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%height=300  alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
Changed lines 41-44 from:
Connect a 220-ohm resistor and an LED in series to digital pin 2 and another to digital pin 3 of the Arduino.

%height=200 alt='Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
%height=200 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] | Arduino with switch on digital pin 2 and LEDs on pins 3 and 4
to:
Connect a 5600-ohm resistor and an LED in series to digital pin 3 and another to digital pin 4 of the Arduino.

%lfloat height=300 alt='Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
%rfloat height=300 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] | Arduino with switch on digital pin 2 and LEDs on pins 3 and 4
Changed lines 36-37 from:
%width=200  alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]]
 "Arduino with switch on digital pin 2"
to:
%width=200  alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]] | Arduino with switch on digital pin 2
Changed line 44 from:
%height=200 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png"Arduino with switch on digital pin 2 and LEDs on pins 3 and 4"]]
to:
%height=200 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png]] | Arduino with switch on digital pin 2 and LEDs on pins 3 and 4
Changed lines 36-37 from:
%width=200 %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png "Arduino with switch on digital pin 2"]]
to:
%width=200  alt='schematic of Arduino with switch on digital pin 2' %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png]]
 
"Arduino with switch on digital pin 2"
Changed line 44 from:
%width=200 %[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png"Arduino with switch on digital pin 2 and LEDs on pins 3 and 4"]]
to:
%height=200 alt='schematic of Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png"Arduino with switch on digital pin 2 and LEDs on pins 3 and 4"]]
Deleted lines 58-63:
 // declare variables:
 int switchPin = 4;      //  digital input pin for a switch
 int yellowLedPin = 2;  //  digital output pin for an LED
 int redLedPin = 3;      //  digital output pin for an LED
 int switchState = 0;    // the state of the switch
 
Changed lines 60-62 from:
   pinMode(switchPin, INPUT);       // set the switch pin to be an input
  pinMode(yellowLedPin, OUTPUT);  // set the yellow LED pin to be an output
  pinMode(redLedPin, OUTPUT);     // set the red LED pin to be an output
to:
   pinMode(2, INPUT);      // set the switch pin to be an input
  pinMode(3, OUTPUT);  // set the yellow LED pin to be an output
  pinMode(4, OUTPUT);  // set the red LED pin to be an output
Changed lines 67-69 from:
   switchState = digitalRead(switchPin);

   if (switchState == 1) {
to:
   if (digitalRead(2) == HIGH) {
Changed lines 69-70 from:
     digitalWrite(yellowLedPin, HIGH);    // turn on the yellow LED
    digitalWrite(redLedPin, LOW);      // turn off the red LED
to:
     digitalWrite(3, HIGH);    // turn on the yellow LED
    digitalWrite(4, LOW);      // turn off the red LED
Changed lines 74-75 from:
     digitalWrite(yellowLedPin, LOW);  // turn off the yellow LED
    digitalWrite(redLedPin, HIGH);    // turn on the red LED
to:
     digitalWrite(3, LOW);  // turn off the yellow LED
    digitalWrite(4, HIGH);    // turn on the red LED
Changed line 29 from:
%width=600 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
to:
%height=200 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
Changed lines 33-34 from:
Connect a switch to digital input 4 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.
to:
Connect a switch to digital input 2 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.

%height=200 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_bb.png|Attach:arduino_switch_bb.png]]
%width=200 %[[Attach:arduino_switch_schem.png|Attach:arduino_switch_schem.png "Arduino with switch on digital pin 2"]]
[--(Diagram made with [[http://fritzing.org | Fritzing]]--]


Changed lines 43-45 from:
%width=600 alt='Arduino with switch on digital pin 4'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 4"]]
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:digital_io_lab.zip | download]])--]
to:
%height=200 alt='Arduino with switch on digital pin 2 and LEDs on pins 3 and 4'%[[Attach:digital_io_lab_bb.png|Attach:digital_io_lab_bb.png]]
%width=200 %[[Attach:digital_io_lab_schem.png|Attach:digital_io_lab_schem.png"Arduino with switch on digital pin 2 and LEDs on pins 3 and 4"]]
[--(Diagram made with [[http://fritzing.org | Fritzing]]--]
Changed lines 33-34 from:
Connect a switch to digital input 2 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.
to:
Connect a switch to digital input 4 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.
Changed lines 36-38 from:
Connect a 220-ohm resistor and an LED in series to digital pin 3 and another to digital pin 4 of the Arduino.

%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
Connect a 220-ohm resistor and an LED in series to digital pin 2 and another to digital pin 3 of the Arduino.

%width=600 alt='Arduino with switch on digital pin 4'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 4"]]
Changed line 50 from:
Here's a program that reads the digital input on pin 2. Then it turns on the LED on pin 3 if the input is high (i.e. the switch is on), or turns on the LED on pin 4 is the input is low (the switch is off):
to:
Here's a program that reads the digital input on pin 4. Then it turns on the LED on pin 2 if the input is high (i.e. the switch is on), or turns on the LED on pin 3 is the input is low (the switch is off):
Changed lines 54-56 from:
 int switchPin = 2;      //  digital input pin for a switch
 int yellowLedPin = 3;  //  digital output pin for an LED
 int redLedPin = 4;      //  digital output pin for an LED
to:
 int switchPin = 4;      //  digital input pin for a switch
 int yellowLedPin = 2;  //  digital output pin for an LED
 int redLedPin = 3;      //  digital output pin for an LED
Changed line 51 from:
(:div class=code :)
to:
(:source lang=arduino tabwidth=4 :)
Changed lines 53-57 from:
 %color=#7e7e7e%// declare variables:
 %color=#cc6600%int%% switchPin = 2;      %color=#7e7e7e%//  digital input pin for a switch
 %color=#cc6600%int%% yellowLedPin = 3;  %color=#7e7e7e%//  digital output pin for an LED
 %color=#cc6600%int%% redLedPin = 4;      %color=#7e7e7e%//  digital output pin for an LED
 %color=#cc6600%int%% switchState = 0;    %color=#7e7e7e%// the state of the switch
to:
 // declare variables:
 int switchPin = 2;      //  digital input pin for a switch
 int yellowLedPin = 3;  //  digital output pin for an LED
 int redLedPin = 4;      //  digital output pin for an LED
 int switchState = 0;    // the state of the switch
Changed lines 59-62 from:
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#cc6600%pinMode%%(switchPin, %color=#006699%INPUT%%);      %color=#7e7e7e%// set the switch pin to be an input
  %color=#cc6600%pinMode%%(yellowLedPin, %color=#006699%OUTPUT%%);  %color=#7e7e7e%// set the yellow LED pin to be an output
  %color=#cc6600%pinMode%%(redLedPin, %color=#006699%OUTPUT%%);      %color=#7e7e7e%// set the red LED pin to be an output
to:
 void setup() {
  pinMode(switchPin, INPUT);      // set the switch pin to be an input
  pinMode(yellowLedPin, OUTPUT);  // set the yellow LED pin to be an output
  pinMode(redLedPin, OUTPUT);      // set the red LED pin to be an output
Changed lines 65-67 from:
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#7e7e7e%// read the switch input:
  switchState = %color=#cc6600%digitalRead%%(switchPin);
to:
 void loop() {
  // read the switch input:
  switchState = digitalRead(switchPin);
Changed lines 69-72 from:
   %color=#cc6600%if%% (switchState == 1) {
    %color=#7e7e7e%// if the switch is closed:
    %color=#cc6600%digitalWrite%%(yellowLedPin, %color=#006699%HIGH%%);    %color=#7e7e7e%// turn on the yellow LED
    %color=#cc6600%digitalWrite%%(redLedPin, %color=#006699%LOW%%);      %color=#7e7e7e%// turn off the red LED
to:
   if (switchState == 1) {
    // if the switch is closed:
    digitalWrite(yellowLedPin, HIGH);    // turn on the yellow LED
    digitalWrite(redLedPin, LOW);      // turn off the red LED
Changed lines 74-77 from:
   %color=#cc6600%else%% {
    %color=#7e7e7e%// if the switch is open:
    %color=#cc6600%digitalWrite%%(yellowLedPin, %color=#006699%LOW%%);  %color=#7e7e7e%// turn off the yellow LED
    %color=#cc6600%digitalWrite%%(redLedPin, %color=#006699%HIGH%%);    %color=#7e7e7e%// turn on the red LED
to:
   else {
    // if the switch is open:
    digitalWrite(yellowLedPin, LOW);  // turn off the yellow LED
    digitalWrite(redLedPin, HIGH);    // turn on the red LED
Changed lines 81-82 from:
(:divend:)
to:
(:sourceend:)
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out.png|Attach:digital_in_out.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out.png|Attach:digital_in_out.png]]. %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out.png|Attach:digital_in_out.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out.png|Attach:digital_in_out.png]]. %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[(Attach:)digital_in_out.png]]. %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[(Attach:)digital_in_out.png]]. %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out.png|Attach:digital_in_out.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out.png|digital_in_out.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out.png|Attach:digital_in_out.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out|digital_in_out]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out.png|digital_in_out.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 38 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_in_out|digital_in_out]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed line 30 from:
to:
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:arduino_and_breadboard.zip | download]])--]
Changed lines 38-39 from:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
[--(Diagram made with [[http://fritzing.org | Fritzing]] - [[Attach:digital_io_lab.zip | download]])--]
Changed lines 38-39 from:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=600 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed lines 29-30 from:
%width=400 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
to:
%width=600 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
Changed lines 38-39 from:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_leds.jpg|Attach:arduino_switch_leds.jpg]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
to:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:digital_IO_lab_bb.png|Attach:digital_IO_lab_bb.png]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed lines 29-30 from:
%width=400 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_breadbrd.jpg|Attach:arduino_breadbrd.jpg]]
to:
%width=400 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_and_breadboard_bb.png|Attach:arduino_and_breadboard_bb.png]]
Changed lines 93-94 from:
''This is a suggestion for the Stupid Pet Trick assignment.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction. This is just one suggestion.''
to:
''This is a suggestion for a possible project.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction.''
Added lines 93-94:
''This is a suggestion for the Stupid Pet Trick assignment.  You can do any project you wish as long as it demonstrates your mastery of the lab exercises and good physical interaction. This is just one suggestion.''
Changed lines 50-83 from:
to:
(:div class=code :)
 
 %color=#7e7e7e%// declare variables:
 %color=#cc6600%int%% switchPin = 2;      %color=#7e7e7e%//  digital input pin for a switch
 %color=#cc6600%int%% yellowLedPin = 3;  %color=#7e7e7e%//  digital output pin for an LED
 %color=#cc6600%int%% redLedPin = 4;      %color=#7e7e7e%//  digital output pin for an LED
 %color=#cc6600%int%% switchState = 0;    %color=#7e7e7e%// the state of the switch
 
 %color=#cc6600%void%% %color=#cc6600%'''setup'''%%() {
  %color=#cc6600%pinMode%%(switchPin, %color=#006699%INPUT%%);      %color=#7e7e7e%// set the switch pin to be an input
  %color=#cc6600%pinMode%%(yellowLedPin, %color=#006699%OUTPUT%%);  %color=#7e7e7e%// set the yellow LED pin to be an output
  %color=#cc6600%pinMode%%(redLedPin, %color=#006699%OUTPUT%%);      %color=#7e7e7e%// set the red LED pin to be an output
 }
 
 %color=#cc6600%void%% %color=#cc6600%'''loop'''%%() {
  %color=#7e7e7e%// read the switch input:
  switchState = %color=#cc6600%digitalRead%%(switchPin);
 
  %color=#cc6600%if%% (switchState == 1) {
    %color=#7e7e7e%// if the switch is closed:
    %color=#cc6600%digitalWrite%%(yellowLedPin, %color=#006699%HIGH%%);    %color=#7e7e7e%// turn on the yellow LED
    %color=#cc6600%digitalWrite%%(redLedPin, %color=#006699%LOW%%);      %color=#7e7e7e%// turn off the red LED
  }
  %color=#cc6600%else%% {
    %color=#7e7e7e%// if the switch is open:
    %color=#cc6600%digitalWrite%%(yellowLedPin, %color=#006699%LOW%%);  %color=#7e7e7e%// turn off the yellow LED
    %color=#cc6600%digitalWrite%%(redLedPin, %color=#006699%HIGH%%);    %color=#7e7e7e%// turn on the red LED
  }
 }
 
(:divend:)

Click the Verify button to compile this code. Then press the reset button on the Arduino module and click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.

Changed lines 85-113 from:

// declare variables:
int switchPin = 2;      //  digital input pin for a switch
int yellowLedPin = 3;  //  digital output pin for an LED
int redLedPin = 4;      //  digital output pin for an LED
int switchState = 0;    // the state of the switch

void setup() {
  pinMode(switchPin, INPUT);      // set the switch pin to be an input
  pinMode(yellowLedPin, OUTPUT);  // set the yellow LED pin to be an output
  pinMode(redLedPin, OUTPUT);      // set the red LED pin to be an output
}

void loop() {
  // read the switch input:
  switchState = digitalRead(switchPin);

  if (switchState == 1) {
    // if the switch is closed:
    digitalWrite(yellowLedPin, HIGH);    // turn on the yellow LED
    digitalWrite(redLedPin, LOW);      // turn off the red LED
  }
  else {
    // if the switch is open:
    digitalWrite(yellowLedPin, LOW);  // turn off the yellow LED
    digitalWrite(redLedPin, HIGH);    // turn on the red LED
  }
}

to:
Binary sketch size: 5522 bytes (of a 7168 byte maximum)
Deleted lines 87-93:

Click the Verify button to compile this code. Then press the reset button on the Arduino module and click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.

[@
Binary sketch size: 5522 bytes (of a 7168 byte maximum)

@]
Changed lines 27-28 from:
Conect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:
to:
Connect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:
Added lines 3-4:
!!!Overview
Changed lines 9-10 from:
!!! Parts
to:
!!!Parts
Changed lines 92-93 from:
Many projects can be made with just digital input and output.  For example, a combination lock is jsut a series of switches that have been switched in a particular sequence.  Consider the cymbal-playing monkey below:
to:
Many projects can be made with just digital input and output. For example, a combination lock is just a series of switches that have been switched in a particular sequence. Consider the cymbal-playing monkey below:
Added lines 1-2:
(:title Digital Input and Output with an Arduino:)
Changed lines 5-6 from:
for this lab you'll need:
to:
(:toc Table of Contents:)

!!! Parts

For this lab you will
need the following parts:
Added lines 32-33:
'''A note on resistor values:''' if you don't have a 10-kilohm resistor for the switch, you can use any reasonably high value. 4.7K, 22K, and even 1 Megohm resistors have been tested with this circuit and they work fine.  As for the resistor on the LED, the higher the resistor value, the dimmer your LED will be.  So 220-ohm resistors give you a nice bright LED, 1-kilohm will make it dimmer, and 10K or higher will likely make it too dim to see.
Deleted lines 77-81:
Atmel AVR ATmega8 is found.
Uploading: flash
Firmware Version: 1.18
Firmware Version: 1.18

Changed lines 30-31 from:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_leds.jpg|Attach:arduino_switch_leds.jpg]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]] | [-the schematic for this circuit-]
to:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_leds.jpg|Attach:arduino_switch_leds.jpg]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]]
Changed lines 30-31 from:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_leds.jpg|Attach:arduino_switch_leds.jpg]] %width=300 alt='Arduino with switch on digital pin 2'%[[Attach:digital_io.png|Attach:digital_io.png]] | [-the schematic for this circuit-]
to:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_leds.jpg|Attach:arduino_switch_leds.jpg]] %width=300 %[[Attach:digital_io.png|Attach:digital_io.png"Arduino with switch on digital pin 2"]] | [-the schematic for this circuit-]
Changed lines 30-32 from:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_leds.jpg|Attach:arduino_switch_leds.jpg]]
%width=300 alt='Arduino with switch on digital pin 2'%[[Attach:digital_io.png|Attach:digital_io.png]] | [-the schematic for this circuit-]
to:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_leds.jpg|Attach:arduino_switch_leds.jpg]] %width=300 alt='Arduino with switch on digital pin 2'%[[Attach:digital_io.png|Attach:digital_io.png]] | [-the schematic for this circuit-]
Deleted line 30:
Changed lines 32-33 from:
to:
%width=300 alt='Arduino with switch on digital pin 2'%[[Attach:digital_io.png|Attach:digital_io.png]] | [-the schematic for this circuit-]
Changed lines 10-15 from:
%lframe width=100px valign=center% Attach:leds.jpg\\
[-[[
Attach:leds.jpg|Light Emiting Diodes, LED]] -]
%lframe
width=100px valign=center% Attach:resistors_220.jpg\\
[-[[
Attach:resistors_220.jpg|220-ohm and 10Kohm resistors]]-]
%lframe width=100px valign=center%Attach:switch.jpg\\
[-[[Attach:switch.jpg|switch]]-]
to:
%lframe width=100px% [[Attach:leds.jpg|Attach:leds.jpg"LEDs"]] | [-Light Emitting Diodes, LEDs-]
%lframe width=100px% [[Attach:resistors.jpg|Attach:resistors.jpg"220-ohm and 10kilohm resistors"]] | [-220-ohm and 10kilohm resistors-]
%lframe width=100px% [[Attach:switch.jpg|Attach:switch.jpg"switch"]] | [-switch or pushbutton-]

Changed lines 7-9 from:
%lframe width=100px% Attach:arduino.jpg\\
[-[[
Attach:arduino.jpg|Arduino Microcontroller\\
module]]-]
to:
%lframe width=100px% [[Attach:arduino.jpg|Attach:arduino.jpg"Arduino microcontroller module"]] | [-Arduino microcontroller module-]
Changed line 6 from:
%lframe width=100px% Attach:hookup_wire.jpg|Attach:hookup_wire.jpg"Hookup wire" | [-22-AWG hookup wire-]
to:
%lframe width=100px% [[Attach:hookup_wire.jpg|Attach:hookup_wire.jpg"Hookup wire"]] | [-22-AWG hookup wire-]
Deleted lines 4-6:
%lframe width=200px valign=center% [[Attach:kit.jpg | Attach:kit.jpg"physical computing parts kit"]] | [-physical computing parts kit-]

Changed lines 6-7 from:
%lframe width=100px% Attach:hookup_wire.jpg\\
[-[[
Attach:hookup_wire.jpg|22-AWG hookup wire]]-]
to:
%lframe width=100px% Attach:hookup_wire.jpg|Attach:hookup_wire.jpg"Hookup wire" | [-22-AWG hookup wire-]
Changed line 8 from:
%lframe width=100px% [[Attach:breadboard.jpg|Solderless breadboard"solderless breadboard"]] | [-Solderless breadboard-]
to:
%lframe width=100px valign=center%[[Attach:breadboard.jpg|Attach:breadboard.jpg"solderless breadboard"]] | [-Solderless breadboard-]
Changed lines 5-6 from:
%lframe width=100px% [[Attach:breadboard.jpg|Solderless breadboard]]\\
[-
Attach:breadboard.jpg|Solderless breadboard-]
to:
%lframe width=200px valign=center% [[Attach:kit.jpg | Attach:kit.jpg"physical computing parts kit"]] | [-physical computing parts kit-]


%lframe width=100px% [[Attach:breadboard.jpg|Solderless breadboard"solderless breadboard"]] | [-
Solderless breadboard-]
Changed line 6 from:
-Attach:breadboard.jpg|Solderless breadboard-
to:
[-Attach:breadboard.jpg|Solderless breadboard-]
Changed lines 5-6 from:
%lframe width=100px% [[Attach:breadboard.jpg|Solderless breadboard\\
-Attach:breadboard.jpg|Solderless breadboard]]-]
to:
%lframe width=100px% [[Attach:breadboard.jpg|Solderless breadboard]]\\
-Attach:breadboard.jpg|Solderless breadboard-
Changed line 6 from:
[-Attach:breadboard.jpg|Solderless breadboard]]-]
to:
-Attach:breadboard.jpg|Solderless breadboard]]-]
Changed lines 5-6 from:
%lframe width=100px% Attach:breadboard.jpg\\
[-[[Attach:breadboard.jpg|Solderless breadboard]]-]
to:
%lframe width=100px% [[Attach:breadboard.jpg|Solderless breadboard\\
[-Attach:breadboard.jpg|Solderless breadboard]]-]
Changed lines 35-37 from:
%width=400 alt='Arduino with switch on digital pin 2'%Attach:arduino_switch_leds.jpg

to:
%width=400 alt='Arduino with switch on digital pin 2'%[[Attach:arduino_switch_leds.jpg|Attach:arduino_switch_leds.jpg]]

Changed lines 26-27 from:
[[Attach:arduino_breadbrd.jpg|%width=400 alt='Arduino connected to a breadboard' align=top valign=center%Attach:arduino_breadbrd.jpg]]
to:
%width=400 alt='Arduino connected to a breadboard' align=top valign=center%[[Attach:arduino_breadbrd.jpg|Attach:arduino_breadbrd.jpg]]
Changed line 8 from:
[-22-AWG hookup wire-]
to:
[-[[Attach:hookup_wire.jpg|22-AWG hookup wire]]-]
Changed lines 10-11 from:
[-Arduino Microcontroller\\
module-]
to:
[-[[Attach:arduino.jpg|Arduino Microcontroller\\
module]]-]
Changed line 14 from:
[-Light Emiting Diodes, LED -]
to:
[-[[Attach:leds.jpg|Light Emiting Diodes, LED]] -]
Changed line 16 from:
[-220-ohm and 10Kohm resistors-]
to:
[-[[Attach:resistors_220.jpg|220-ohm and 10Kohm resistors]]-]
Changed line 18 from:
[-switch-]
to:
[-[[Attach:switch.jpg|switch]]-]
Changed lines 26-27 from:
%width=400 alt='Arduino connected to a breadboard' align=top valign=center%Attach:arduino_breadbrd.jpg
to:
[[Attach:arduino_breadbrd.jpg|%width=400 alt='Arduino connected to a breadboard' align=top valign=center%Attach:arduino_breadbrd.jpg]]
Changed lines 5-6 from:
%lframe width=100px% [[Attach:breadboard.jpg|Attach:breadboard.jpg\\
[-Solderless breadboard]]-]
to:
%lframe width=100px% Attach:breadboard.jpg\\
[-[[Attach:breadboard.jpg|Solderless breadboard]]-]
Changed lines 5-6 from:
%lframe width=100px% Attach:breadboard.jpg\\
[-[[Attach:breadboard.jpg|Solderless breadboard]]-]
to:
%lframe width=100px% [[Attach:breadboard.jpg|Attach:breadboard.jpg\\
[-Solderless breadboard]]-]
Changed line 6 from:
[-Solderless breadboard-]
to:
[-[[Attach:breadboard.jpg|Solderless breadboard]]-]
Changed lines 26-27 from:
%alt='Arduino connected to a breadboard' align=top valign=center%Attach:arduino_breadbrd.jpg
to:
%width=400 alt='Arduino connected to a breadboard' align=top valign=center%Attach:arduino_breadbrd.jpg
Changed lines 35-37 from:
%alt='Arduino with switch on digital pin 2'%Attach:arduino_switch_leds.jpg

to:
%width=400 alt='Arduino with switch on digital pin 2'%Attach:arduino_switch_leds.jpg

Changed lines 35-37 from:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch_leds.jpg

to:
%alt='Arduino with switch on digital pin 2'%Attach:arduino_switch_leds.jpg

Changed lines 26-27 from:
%alt='Arduino connected to a breadboard' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino_bboard_power.jpg
to:
%alt='Arduino connected to a breadboard' align=top valign=center%Attach:arduino_breadbrd.jpg
Deleted lines 31-34:

%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg

----
Changed line 5 from:
%lframe width=100px% Attach:breadboard.jpg\\ 
to:
%lframe width=100px% Attach:breadboard.jpg\\
Deleted lines 18-19:

Click on any image for a larger view
Added lines 21-22:
Click on any image for a larger view
Changed line 7 from:
%lframe width=100px% Attach:hookup_wire.jpg \\
to:
%lframe width=100px% Attach:hookup_wire.jpg\\
Changed lines 9-10 from:
%lframe width=100px% Attach:arduino.jpg \\
[-Arduino Microcontroller \\
to:
%lframe width=100px% Attach:arduino.jpg\\
[-Arduino Microcontroller\\
Changed lines 13-16 from:
%lframe width=100px valign=center% Attach:leds.jpg \\[-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% Attach:resistors_220.jpg \\[-220-ohm and 10Kohm resistors-]
%lframe width=100px valign=center%Attach:switch.jpg [-switch-]
to:
%lframe width=100px valign=center% Attach:leds.jpg\\
[-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% Attach:resistors_220.jpg\\
[-220-ohm and 10Kohm resistors-]
%lframe width=100px valign=center%Attach:switch.jpg\\
[-switch-]
Changed lines 5-7 from:
%lframe width=100px% Attach:breadboard.jpg \\[-Solderless breadboard-]
%lframe width=100px% Attach:hookup_wire.jpg \\[-22-AWG hookup wire-]
%lframe width=100px% Attach:arduino.jpg [-Arduino Microcontroller \\
to:
%lframe width=100px% Attach:breadboard.jpg\\ 
[-Solderless breadboard-]
%lframe width=100px% Attach:hookup_wire.jpg \\
[-22-AWG hookup wire-]
%lframe width=100px% Attach:arduino.jpg \\
[-Arduino Microcontroller \\
Changed lines 5-6 from:
%lframe width=100px% Attach:breadboard.jpg [-Solderless breadboard-]
%lframe width=100px% Attach:hookup_wire.jpg [-22-AWG hookup wire-]
to:
%lframe width=100px% Attach:breadboard.jpg \\[-Solderless breadboard-]
%lframe width=100px% Attach:hookup_wire.jpg \\[-22-AWG hookup wire-]
Changed lines 10-11 from:
%lframe width=100px valign=center% Attach:leds.jpg [-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% Attach:resistors_220.jpg [-220-ohm and 10Kohm resistors-]
to:
%lframe width=100px valign=center% Attach:leds.jpg \\[-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% Attach:resistors_220.jpg \\[-220-ohm and 10Kohm resistors-]
Changed lines 10-13 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/leds.jpg | http://itp.nyu.edu/physcomp/images/labs/leds.jpg"Light Emiting Diodes"]] | [-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/
resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm and 10Kohm resistors-]
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"switch"]] | [-switch-]

to:
%lframe width=100px valign=center% Attach:leds.jpg [-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% Attach:resistors_220.jpg [
-220-ohm and 10Kohm resistors-]
%lframe width=100px valign=center%Attach
:switch.jpg [-switch-]

Click on any image for a larger view
Changed lines 5-7 from:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/breadboard.jpg | http://itp.nyu.edu/physcomp/images/labs/breadboard.jpg"Solderless breadboard"]] | [-Solderless breadboard-]
%lframe width=100px% [[http
://itp.nyu.edu/physcomp/images/labs/hookup_wire.jpg | http://itp.nyu.edu/physcomp/images/labs/hookup_wire.jpg"hookup wire"]] | [-22-AWG hookup wire-]
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino module"]] |
[-Arduino Microcontroller \\
to:
%lframe width=100px% Attach:breadboard.jpg [-Solderless breadboard-]
%lframe width=100px% Attach
:hookup_wire.jpg [-22-AWG hookup wire-]
%lframe width=100px% Attach
:arduino.jpg [-Arduino Microcontroller \\
Changed lines 25-32 from:
(:table:)
(:cellnr colspan
=2:)
%alt=
'Arduino digital in schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
(:cellnr:)
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.
jpg\\
Breadboard version
(:tableend:)

to:

%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg
Changed lines 32-42 from:
(:table:)
(:cellnr colspan
=2:)
%alt=
'Arduino digital in and out schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_io_schem.png
(:cellnr:)
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch_leds.
jpg\\
Breadboard version
(:cell:)
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch_leds.jpg\\
Shield version
(:tableend:)

to:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch_leds.jpg

Deleted lines 20-23:
If you're using an Arduino breadboard shield, there is a row of sockets connected to 5V on the analog in side of the breadboard, and a row connected to ground on the digital in side of the board:

%alt='Arduino breadboard shield' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/breadboard_shield.jpg

Deleted lines 30-32:
(:cell:)
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch.jpg\\
Shield version
Changed lines 112-113 from:
Many projects can be mae with just digital input and output.  For example, a combination lock is jsut a series of switches that have been switched in a particular sequence.  Consider the cymbal-playing monkey below:
to:
Many projects can be made with just digital input and output.  For example, a combination lock is jsut a series of switches that have been switched in a particular sequence.  Consider the cymbal-playing monkey below:
Changed lines 42-43 from:
Connect a 220-ohm resistor and an LED in series to digital pin 2 and another to digital pin 3 of the Arduino.
to:
Connect a 220-ohm resistor and an LED in series to digital pin 3 and another to digital pin 4 of the Arduino.
Changed lines 12-13 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"resistors"]] | [-switch-]
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"switch"]] | [-switch-]
Changed lines 23-24 from:
%alt='Arduino breadboard shield' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino_shield_power.jpg
to:
%alt='Arduino breadboard shield' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/breadboard_shield.jpg
Added line 9:
[[<<]]
Changed lines 10-13 from:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm resistors-]

Switch
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm and 10Kohm resistors-]
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/switch.jpg | http://itp.nyu.edu/physcomp/images/labs/switch.jpg"resistors"]] | [-switch-]
Changed lines 121-123 from:
Those wires can be run to a breadboard and used as a switch.  Then the microcontroller could be programmed to listen for pattern of cymbal crashes, and if it sees that pattern, to open a lock by switching on a digital output.
to:
Those wires can be run to a breadboard and used as a switch.  Then the microcontroller could be programmed to listen for pattern of cymbal crashes, and if it sees that pattern, to open a lock by switching on a digital output.

Come up with your own physical interface for a combination lock.
Changed line 120 from:
to:
[[<<]]
Changed lines 118-120 from:
http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail1.jpg
http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail2.jpg
to:
%lfloat%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail1.jpg
%rfloat%http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail2.jpg
Changed lines 110-111 from:

to:
!!! Get Creative

Many projects can be mae with just digital input and output.  For example, a combination lock is jsut a series of switches that have been switched in a particular sequence.  Consider the cymbal-playing monkey below:

http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey.jpg

His cymbals can be turned into a switch by lining them with tin foil and screwing wires to them:

http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail1.jpg
http://itp.nyu.edu/physcomp/images/labs/cymbal_monkey_detail2.jpg

Those wires can be run to a breadboard and used as a switch.  Then the microcontroller could be programmed to listen for pattern of cymbal crashes, and if it sees that pattern, to open a lock by switching on a digital output.
Changed lines 7-8 from:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino module"]] | [-Arduino Microcontroller \\module-]
to:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino module"]] | [-Arduino Microcontroller \\
module-]
Changed lines 7-8 from:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino\\
module"]] | [-Arduino Microcontroller module-]
to:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino module"]] | [-Arduino Microcontroller \\module-]
Changed lines 7-8 from:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino\\ module"]] | [-Arduino Microcontroller module-]
to:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino\\
module"]] | [-Arduino Microcontroller module-]
Changed line 7 from:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino module"]] | [-Arduino Microcontroller module-]
to:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino\\ module"]] | [-Arduino Microcontroller module-]
Changed lines 41-42 from:
Connect a 220-ohm resistor an LED in series to digital pin 2 and another to digital pin 3 of the Arduino.
to:
Connect a 220-ohm resistor and an LED in series to digital pin 2 and another to digital pin 3 of the Arduino.
Changed line 106 from:
Press the switch and watch the LEDs change until you get bored. That's all there is to nasic digital input and output!
to:
Press the switch and watch the LEDs change until you get bored. That's all there is to basic digital input and output!
Changed lines 106-109 from:
Press the switch and watch the LEDs change until you get bored.


to:
Press the switch and watch the LEDs change until you get bored. That's all there is to nasic digital input and output!
----
[[<<]]


Added lines 65-92:
// declare variables:
int switchPin = 2;      //  digital input pin for a switch
int yellowLedPin = 3;  //  digital output pin for an LED
int redLedPin = 4;      //  digital output pin for an LED
int switchState = 0;    // the state of the switch

void setup() {
  pinMode(switchPin, INPUT);      // set the switch pin to be an input
  pinMode(yellowLedPin, OUTPUT);  // set the yellow LED pin to be an output
  pinMode(redLedPin, OUTPUT);      // set the red LED pin to be an output
}

void loop() {
  // read the switch input:
  switchState = digitalRead(switchPin);

  if (switchState == 1) {
    // if the switch is closed:
    digitalWrite(yellowLedPin, HIGH);    // turn on the yellow LED
    digitalWrite(redLedPin, LOW);      // turn off the red LED
  }
  else {
    // if the switch is open:
    digitalWrite(yellowLedPin, LOW);  // turn off the yellow LED
    digitalWrite(redLedPin, HIGH);    // turn on the red LED
  }
}

Changed lines 98-104 from:
to:
Binary sketch size: 5522 bytes (of a 7168 byte maximum)

Atmel AVR ATmega8 is found.
Uploading: flash
Firmware Version: 1.18
Firmware Version: 1.18

Changed lines 61-75 from:
to:
Here's a program that reads the digital input on pin 2. Then it turns on the LED on pin 3 if the input is high (i.e. the switch is on), or turns on the LED on pin 4 is the input is low (the switch is off):

[@

@]

Click the Verify button to compile this code. Then press the reset button on the Arduino module and click the Upload button to upload the program to the module. After a few seconds, the following message will appear in the message pane to tell you the program was uploaded successfully.

[@

@]
Press the switch and watch the LEDs change until you get bored.


Changed lines 59-61 from:
%alt='arduino serial port menu'http://itp.nyu.edu/physcomp/images/labs/arduino_tools_menu.png

to:
%alt='arduino serial port menu'%http://itp.nyu.edu/physcomp/images/labs/arduino_tools_menu.png

Changed lines 57-61 from:
Connect the microcontroller to your computer via USB.  Assuming you've installed the Arduino software environment and the USB-to-serial drivers correctly, you'll find a new serial port in the Tools-->Serial Port menu
to:
Connect the microcontroller to your computer via USB.  Assuming you've installed the Arduino software environment and the USB-to-serial drivers correctly, you'll find a new serial port in the Tools-->Serial Port menu. in OSX, the name will begin with /dev/tty.usbserial-.  In Windows it will start with COM like all the other serial ports.

%alt='arduino serial port menu'http://itp.nyu.edu/physcomp/images/labs/arduino_tools_menu.png

Changed line 39 from:
to:
----
Added lines 54-57:
----
!!! Program the Arduino

Connect the microcontroller to your computer via USB.  Assuming you've installed the Arduino software environment and the USB-to-serial drivers correctly, you'll find a new serial port in the Tools-->Serial Port menu
Changed lines 32-33 from:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg
to:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg\\
Breadboard version
Changed lines 35-36 from:
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch.jpg
to:
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch.jpg\\
Shield version
Changed lines 47-48 from:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch_leds.jpg
to:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch_leds.jpg\\
Breadboard version
Changed lines 50-51 from:
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch_leds.jpg
to:
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch_leds.jpg\\
Shield version
Changed line 47 from:
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_switch_leds.jpg
to:
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch_leds.jpg
Changed lines 39-49 from:
to:
Connect a 220-ohm resistor an LED in series to digital pin 2 and another to digital pin 3 of the Arduino.

(:table:)
(:cellnr colspan=2:)
%alt='Arduino digital in and out schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_io_schem.png
(:cellnr:)
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch_leds.jpg
(:cell:)
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_switch_leds.jpg
(:tableend:)

Changed lines 8-14 from:


(
:cellnr:)
LEDs
(:cell:)
220-ohm resistors
(
:cell:)
to:
%lframe width=100px valign=center% [[http://itp.nyu.edu/physcomp/images/labs/leds.jpg | http://itp.nyu.edu/physcomp/images/labs/leds.jpg"Light Emiting Diodes"]] | [-Light Emiting Diodes, LED -]
%lframe width=100px valign=center% [[http
://itp.nyu.edu/physcomp/images/labs/resistors.jpg | http://itp.nyu.edu/physcomp/images/labs/resistors.jpg"resistors"]] | [-220-ohm resistors-]
Deleted lines 12-19:
(:cellnr:)
%alt='leds' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/leds.jpg
(:cell:)
%alt='resistors' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/resistors.jpg
(:cell:)
Switch
(:tableend:)

Changed lines 5-7 from:


%%Solderless breadboard
to:
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/breadboard.jpg | http://itp.nyu.edu/physcomp/images/labs/breadboard.jpg"Solderless breadboard"]] | [-Solderless breadboard-]
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/hookup_wire.jpg | http://itp.nyu.edu/physcomp/images/labs/hookup_wire.jpg"hookup wire"]] | [-22-AWG hookup wire-]
%lframe width=100px% [[http://itp.nyu.edu/physcomp/images/labs/arduino.jpg | http://itp.nyu.edu/physcomp/images/labs/arduino.jpg"Arduino module"]] | [-Arduino Microcontroller module-]


(:cellnr:)
LEDs
Changed line 13 from:
22-AWG hookup wire
to:
220-ohm resistors
Changed lines 15-16 from:
Microcontroller module (Arduino)
to:
Switch
Changed line 18 from:
%alt='breadboard'  align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/breadboard.jpg
to:
%alt='leds' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/leds.jpg
Changed line 20 from:
%alt='hookup wire' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/hookup_wire.jpg
to:
%alt='resistors' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/resistors.jpg
Deleted lines 21-27:
%alt='Arduino module' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino.jpg

(:cellnr:)
LEDs
(:cell:)
220-ohm resistors
(:cell:)
Deleted lines 22-28:

(:cellnr:)
%alt='leds' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/leds.jpg
(:cell:)
%alt='resistors' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/resistors.jpg
(:cell:)
Switch
Changed lines 7-9 from:
(:table border=0:)
(:cellnr:)

Solderless breadboard
to:
%%Solderless breadboard
Changed lines 57-59 from:


to:
(:tableend:)

Changed lines 48-51 from:
!!! Add a digital input (a switch)

Connect a switch to digital input 2 on the Arduino:
to:
!!! Add a Digital Input (a switch)

Connect a switch to digital input 2 on the Arduino. The switch shown below is a store-bought momentary pushbutton, but you can use any switch.  Try making your own with a couple of pieces of metal.
Changed line 54 from:
%alt='Arduino digital in schematic' height=300 align=center%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
to:
%alt='Arduino digital in schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
Changed lines 62-63 from:
to:
!!! Add Digital Outputs (LEDs)
Changed line 54 from:
%alt='Arduino digital in schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
to:
%alt='Arduino digital in schematic' height=300 align=center%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
Added lines 53-54:
(:cellnr colspan=2:)
%alt='Arduino digital in schematic' height=300%http://itp.nyu.edu/physcomp/images/labs/arduino_dig_input_schem.png
Added line 56:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg
Deleted lines 57-58:
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg
(:cell:)
Added lines 36-61:

[[<<]]

!!! Prepare the breadboard
Conect power and ground on the breadboard to power and ground from the microcontroller. On the Arduino module, use the 5V and any of the ground connections:

%alt='Arduino connected to a breadboard' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino_bboard_power.jpg

If you're using an Arduino breadboard shield, there is a row of sockets connected to 5V on the analog in side of the breadboard, and a row connected to ground on the digital in side of the board:

%alt='Arduino breadboard shield' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino_shield_power.jpg

!!! Add a digital input (a switch)

Connect a switch to digital input 2 on the Arduino:

(:table:)
(:cellnr:)
(:cell:)
%alt='Arduino with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/arduino_switch.jpg
(:cell:)
%alt='Arduino shield with switch on digital pin 2'%http://itp.nyu.edu/physcomp/images/labs/bbrd_shield_switch.jpg



Changed line 7 from:
:table border=0:)
to:
(:table border=0:)
Deleted lines 25-28:


(:cellnr:)
%alt='leds' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/leds.jpg
Added lines 27-31:
Switch

(:cellnr:)
%alt='leds' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/leds.jpg
(:cell:)
Changed lines 33-34 from:
to:
(:cell:)
Switch
Changed lines 20-21 from:
to:
%alt='Arduino module' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/arduino.jpg
Changed lines 5-10 from:
Microcontroller module

Solderless Breadboard

Switch
(you can make your own or use a store-bought one)
to:


:table border=0:)
(:cellnr:)
Solderless breadboard
(:cell:)
22-AWG hookup wire
(:cell:)
Microcontroller module (Arduino
)

(:cellnr:)
%alt='breadboard'  align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/breadboard.jpg
(:cell:)
%alt='hookup wire' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/hookup_wire.jpg
(:cell:)

(:cellnr:)
Changed lines 23-32 from:
to:
(:cell:)
220-ohm resistors


(:cellnr:)
%alt='leds' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/leds.jpg
(:cell:)
%alt='resistors' align=top valign=center%http://itp.nyu.edu/physcomp/images/labs/resistors.jpg

(:tableend:)
Added lines 1-12:
In this lab, you'll connect a digital input circuit and a digital output circuit to a microcontroller. Though this is written for the Arduino microcontroller module, the principles apply to any microcontroller.

for this lab you'll need:

Microcontroller module

Solderless Breadboard

Switch (you can make your own or use a store-bought one)

LEDs

  Edit | View | History | Print | Recent Changes | Search Page last modified on September 01, 2013, at 03:21 PM