To realize this goal, you’ll learn how a computer converts the changes in energy given off by our bodies (in the form of sound, light, motion, and other forms) into changing electronic signals that it can read interpret. You’ll learn about the sensors that do this, and about very simple computers called microcontrollers that read sensors and convert their output into data. Finally, you’ll learn how microcontrollers communicate with other computers.
This workshop is based off the Physical Computing course at New York University’s Interactive Telecommunications Program. It is intended for beginners with little to no experience with electronics and programing. However, any experience you have will be very helpful when working with these tools.
Day 1: Control of Input & Output
Today, you’ll learn the basics of input from the physical world to a microcontroller, and output from the microcontroller to the physical world. We will also talk about the basic principals of electricity.
- Intro to tools
- What is a Microcontroller?
- Analog vs. Digital
- Understanding Electricity
- Digital Input/Output
- Intro to Arduino and first program.
- Analog Input Explained
Day 2 : Communication
- high current loads and motors
- Servos
- analog output
- pulsewidth modulation
- serial communication
- multiple sensors
- Interpreting bytes: ASCII vs. binary
- handshaking/call-and-response
Day 3: Advanced topics and multiple outputs
- Synchronous Serial Communication
- Shift Registers
- Multiplexers
- The TLC5940 and multiple LEDs
Tools :
7805 5V power regulator
ceramic capcitors
electrolytic capacitors
servo motor
Arduino Duemilanove ATmega328 – the latest Arduino USB board
6′ USB A to B cable – USB provides power for up to 500mA
Miniature breadboard – Excellent for making circuits and connections
jumper wire
Force Sensitive Resistor 0.5″ – A sensor that will vary its resistance depending on the amount of pressure (range of 100g to 10kg) being applied to its circular sensing area.
Photocell – A sensor to detect ambient light.
Tri-Color LED – Because everyone loves a blinky.
Basic LEDs – Light emitting diodes make great general indicators.
Linear potentiometer – Also known as a variable resistor
TIP120 transistor
Speaker
Momentary Switches
330 Ohm Resistors – 5 current limiting resistors for LEDs
10kOhm Resistor – These make excellent pull-ups, pull-downs, and current limiters.
soldering iron
computer with the latest version of the Arduino software
Breadboard
Links :
Online resistance calculator
Resitulator iPhone App and Dashboard widget
ITP’s Sensor Reports
What is the Arduino
ITP’s Physical Computing site
Other software we used on day 2 :
PureData
Max/MSP
Processing
vvvv
Live
Firmata
OpenFrameworks
Resources
LED array Wizard
Hack a Day
Make Zine
Evil Mad Scientist
adafruit
Instructables
ITP Sensor Wiki
LED ON/OFF
//first, let's name the pins, so we can refer to them later by name
#define LEDPin 7
//setup is where we initialize things
void setup(){
//here we are declaring LEDPin as outputs
pinMode(LEDPin, OUTPUT);
}
//loop is your main program, it does this over and over and over again
void loop(){
//Turn one led on, and turn the other off
digitalWrite(LEDPin, HIGH);
//wait a moment, or 250 milliseconds (1/4 of a second)
delay(250);
//Turn one led off, and turn the other on
digitalWrite(LEDPin, LOW);
//wait again before repeating
delay(250);
}
DIGITAL INPUT & OUTPUT
//first, let's name the pins, so we can refer to them later by name
#define LEDPin 5
#define SwitchPin 2
//setup is where we initialize things
void setup(){
//here we are declaring the LEDPin as an output (it will light up)
pinMode(LEDPin, OUTPUT);
//here we declare the SwitchPin as an input (it listens for a digital on/off)
pinMode(SwitchPin, INPUT);
}
//loop is your main program, it does this over and over and over again
void loop(){
//an if statement is a conditional, saying "if this thing is
//[true, greater than, not equal to...], then do this other thing"
//in English, we would say "read the value on the SwitchPin. If the value is equal to 1...
if(digitalRead(SwitchPin)==1) {
//turn the LEDPin on
digitalWrite(LEDPin, HIGH);
}
else{ //if there is a different condition (ex. the SwitchPin == 0), do this instead
//turn the LED off
digitalWrite(LEDPin, LOW);
}
}
ANALOG INPUT
///////////////////
//some constants for the pin that will never change
#define VarResistor 2
//make a variable to hold the values from the analog sensor (pot, photocell, thermisitor, etc)
//no need to initialize this particular one, but I do out of habit
int AnalogValue =0;
void setup(){
//start serial communication, this way we can see the values coming from the sensor
Serial.begin(9600);
}
void loop(){
//read the value of the sensor or variable resistor
//and place it in our variable named AnalogValue
AnalogValue=analogRead(VarResistor);
//print the value of the resistor to the serial monitor
Serial.println(AnalogValue);
//take a moment to let the ADC "breathe"
delay(10);
}
ANALOG INPUT :: DIGITAL OUTPUT
//some constants for the pin that will never change
#define VarResistor 2
#define ledPin 7
//make a variable to hold the values from the analog sensor (pot, photocell, thermisitor, etc)
//no need to initialize this particular one, but I do out of habit
int AnalogValue =0;
void setup(){
//start serial communication, this way we can see the values coming from the sensor
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
void loop(){
//read the value of the sensor or variable resistor
//and place it in our variable named AnalogValue
AnalogValue=analogRead(VarResistor);
if(AnalogValue<=6){
digitalWrite(ledPin, HIGH);
}else{
digitalWrite(ledPin, LOW);
}
//print the value of the resistor to the serial monitor
Serial.println(AnalogValue);
//take a moment to let the ADC "breathe"
delay(10);
}
SERVOS THE HARD WAY
int servoPin = 2; // Control pin for servo motor
int minPulse = 750; // Minimum servo position
int maxPulse = 2500; // Maximum servo position
int pulse = 0; // Amount to pulse the servo
long lastPulse = 0; // the time in milliseconds of the last pulse
int refreshTime = 20; // the time needed in between pulses
int analogValue = 0; // the value returned from the analog sensor
int analogPin = 0; // the analog pin that the sensor's on
void setup() {
pinMode(servoPin, OUTPUT); // Set servo pin as an output pin
pulse = minPulse; // Set the motor position value to the minimum
Serial.begin(9600);
}
void loop() {
analogValue = analogRead(analogPin); // read the analog input
pulse = map(analogValue,0,1023,minPulse,maxPulse); // convert the analog value
// to a range between minPulse
// and maxPulse.
// pulse the servo again if rhe refresh time (20 ms) have passed:
if (millis() - lastPulse >= refreshTime) {
digitalWrite(servoPin, HIGH); // Turn the motor on
delayMicroseconds(pulse); // Length of the pulse sets the motor position
digitalWrite(servoPin, LOW); // Turn the motor off
lastPulse = millis(); // save the time of the last pulse
}
Serial.println(analogValue);
}
/*
This code was written for a pot
it assumes you're going to get values from 0 to 1023
if you don't, the servo won't move through its whole range.
Determine the range of numbers the sensor is giving you and adjust the servo formula to fit.
Here's a scaling formula that will make the adjustment:
(pulseWidth - minPulse) / pulseRange = (sensorValue - minSensorValue) /sensorRange
Multiply both sides by pulseRange, and you get:
(pulseWidth - minPulse) = (sensorValue - minsensorValue * pulseRange /sensorRange
Add the minimum pulse to both sides and you get:
pulseWidth = ((sensorValue - minSensorValue) * pulseRange / sensorRange) + minPulse
That's the full ranging formula.
*/
TRI-COLOR FADES
//Adapted from Clay Shirky's example at //http://www.arduino.cc/en/Tutorial/DimmingLEDs
// Output
int redPin = 9; // Red LED, connected to digital pin 9
int greenPin = 10; // Green LED, connected to digital pin 10
int bluePin = 11; // Blue LED, connected to digital pin 11
// Program variables
int redVal = 255; // Variables to store the values to send to the pins
int greenVal = 1; // Initial values are Red full, Green and Blue off
int blueVal = 1;
int i = 0; // Loop counter
int wait = 50; // 50ms (.05 second) delay; shorten for faster fades
void setup()
{
pinMode(redPin, OUTPUT); // sets the pins as output
pinMode(greenPin, OUTPUT);
pinMode(bluePin, OUTPUT);
}
void loop()
{
i += 1; // Increment counter
if (i < 255) // First phase of fades
{
redVal -= 1; // Red down
greenVal += 1; // Green up
blueVal = 1; // Blue low
}
else if (i < 509) // Second phase of fades
{
redVal = 1; // Red low
greenVal -= 1; // Green down
blueVal += 1; // Blue up
}
else if (i < 763) // Third phase of fades
{
redVal += 1; // Red up
greenVal = 1; // Green low
blueVal -= 1; // Blue down
}
else // Re-set the counter, and start the fades again
{
i = 1;
}
analogWrite(redPin, redVal); // Write current values to LED pins
analogWrite(greenPin, greenVal);
analogWrite(bluePin, blueVal);
delay(wait); // Pause for 'wait' milliseconds before resuming the loop
}