## Sparkfun Introduction

Physical computing is a term coined by Massimo Banzi, co-developer of the Arduino microcontroller. He defines his term as the design of interactive objects that can communicate with humans using sensors and actuators controlled by behaviour implemented as software running inside a micro-controller (small computer on a chip). The philosophy of this movement is to involve the concepts of open source, collaboration, tinkering and a desire to teach especially children that computers have operating systems and can be programmed by just about anyone.

It involves
• planning
• electronics
• programming
• projects
• collaboration

and as the founder of Logo, Seymour Papert put it "hard fun".

Here are a set of exercises

## Getting started with circuits

 Outcomes Before you get going be able to Explain how electricity flows from high potential to low potential in a circuit. Explain the difference between the flow of current (Amps) and the ability of electricity to do work (Volts). Explain that resistance measures the ability of a charge to flow in a circuit. Be able to construct a simple circuit on a breadboard. Be able to find the value of a resistor from the codes on its body. You will find you will be able to identify various components on the way through. Wikipedia : Electricity Useful things to have handy an know how to use soldering iron multi meter hand lens or magnifying glass access to the Internet Reading the value of a resistor is useful. It is based on ROY G BIV the colours of the rainbow. Resistors explained

## Getting started with Arduino

We are following the outline from the Sparkfun inventors' guide. We have purchased out kits for around \$(aus)45.00 and they come complete with all the necessary components to complete these activities.

I sourced some of my components from eBay as well.

Bofore you actually get to do any programming, make sure you can do the following.

• Describe what is meant by a microcontroller like and Arduino or Picaxe.
• Install any drivers needed for your machine to communicate via USB.
• Identify which Arduino you have.
• identify which COM port it is connected to.

## circuit #2 : potentiometer

 Outcomes Describe how to use a potentiometer as a variable resistor Describe how to use a potentiometer as a voltage divider Be able to calculate the voltage in both parts of a 2 resisitor system Sparkfun voltage divider Voltage divider calculator What to do Follow circuit #2 from Sparkfun SIK guide. Search on Arduino site for further information. What We're Doing Along with the digital pins, the Arduino also has 6 pins which can be used for analog input. These inputs take a voltage (from 0 to 5 volts) and convert it to a digital number between 0 (0 volts) and 1023 (5 volts) (10 bits of resolution). A very useful device that exploits these inputs is a potentiometer (also called a variable resistor). When it is connected with 5 volts across its outer pins the middle pin will read some value between 0 and 5 volts dependent on the angle to which it is turned (ie. 2.5 volts in the middle). We can then use the returned values as a variable in our program. /*  Analog Input Demonstrates analog input by reading an analog sensor on analog pin 0 and turning on and off a light emitting diode(LED)  connected to digital pin 13.  The amount of time the LED will be on and off depends on the value obtained by analogRead().   The circuit: * Potentiometer attached to analog input 0 * center pin of the potentiometer to the analog pin * one side pin (either one) to ground * the other side pin to +5V * LED anode (long leg) attached to digital output 13 * LED cathode (short leg) attached to ground  * Note: because most Arduinos have a built-in LED attached  to pin 13 on the board, the LED is optional.   Created by David Cuartielles Modified 16 Jun 2009 By Tom Igoe  http://arduino.cc/en/Tutorial/AnalogInput  */int sensorPin = 0;    // select the input pin for the potentiometerint ledPin = 13;      // select the pin for the LEDint sensorValue = 0;  // variable to store the value coming from the sensorvoid setup() {  // declare the ledPin as an OUTPUT:  pinMode(ledPin, OUTPUT);  }void loop() {  // read the value from the sensor:  sensorValue = analogRead(sensorPin);      // turn the ledPin on  digitalWrite(ledPin, HIGH);    // stop the program for  milliseconds:  delay(sensorValue);            // turn the ledPin off:          digitalWrite(ledPin, LOW);     // stop the program for for  milliseconds:  delay(sensorValue);                  } Hint Christmas, department stores have strings of cheap LEDS for half price. These can be substituted for a single LED. Some people sew these into clothes for effects.

## Serial window

 Outcomes Be able to code to begin a serial window at the correct baud rate. Be able to code to read a value from a periferal and report it in the serial window. Be able to explain why you would do that. Code /* Analog Read * ----------- * * A potentiometer is a simple knob that provides a variable resistance, which we can read into * the Arduino board as an analog value. * * When read through an arduino board, it will deliver a value of between 0 - 1024 * using the tools => serial monitor screen * * look here for more information * * http://www.arduino.cc/en/tutorial/potentiometer * */ int potPin = 0; // select the input pin for the potentiometerint val = 0;int readx = 0; void setup() { Serial.begin(9600);} void loop() { val = analogRead(potPin); // read the value from the sensor readx = val; Serial.println(val); if ( val > 512) { Serial.println ("yippee i amm high!"); } else { Serial.println("I am pretty low"); } delay(500); // stop the program for some time}

## circuit #03 : rgb led

 Outcomes Code /*Adafruit Arduino - Lesson 3. RGB LED*/ int redPin = 11;int greenPin = 10;int bluePin = 9; //uncomment this line if using a Common Anode LED//#define COMMON_ANODE void setup(){ pinMode(redPin, OUTPUT); pinMode(greenPin, OUTPUT); pinMode(bluePin, OUTPUT); } void loop(){ setColor(255, 0, 0); // red delay(1000); setColor(0, 255, 0); // green delay(1000); setColor(0, 0, 255); // blue delay(1000); setColor(255, 255, 0); // yellow delay(1000); setColor(80, 0, 80); // purple delay(1000); setColor(0, 255, 255); // aqua delay(1000);} void setColor(int red, int green, int blue){ #ifdef COMMON_ANODE red = 255 - red; green = 255 - green; blue = 255 - blue; #endif analogWrite(redPin, red); analogWrite(greenPin, green); analogWrite(bluePin, blue); } Check to see if the anode or cathode are common.

## circuit #04 : multiple leds

 This is the introduction to a whole world of projects, from a simple chaser like this prac or 16x16 matrices to all sorts of applications. Look elsewhere on the sight for ideas. /* old logo project here is an oldie but a goodie set up an array of LEDs and turn them on and off. smarty pantses will have by now investigated loops, random numbers, arrays etc. go knock yourselves out author m weber250498 */int ledPin1 = 13;int ledPin2 = 12;int ledPin3 = 11;int ledPin4 = 10;int ledPin5 = 9;int ledPin6 = 8;int ledPin7 = 7;int ledPin8 = 6;int ledPin9 = 5;int ledPin10 = 4; void setup(){ pinMode(ledPin1,OUTPUT); pinMode(ledPin2,OUTPUT); pinMode(ledPin3,OUTPUT); pinMode(ledPin4,OUTPUT); pinMode(ledPin5,OUTPUT); pinMode(ledPin6,OUTPUT); pinMode(ledPin7,OUTPUT); pinMode(ledPin8,OUTPUT); pinMode(ledPin9,OUTPUT); pinMode(ledPin10,OUTPUT); } void loop(){ digitalWrite(ledPin1, HIGH); delay (134);digitalWrite(ledPin1,LOW);delay(145); digitalWrite(ledPin2, HIGH); delay (134);digitalWrite(ledPin2,LOW);delay(145); digitalWrite(ledPin3, HIGH); delay (134);digitalWrite(ledPin3,LOW);delay(145); digitalWrite(ledPin4, HIGH); delay (134);digitalWrite(ledPin4,LOW);delay(145); digitalWrite(ledPin5, HIGH); delay (134);digitalWrite(ledPin5,LOW);delay(145); digitalWrite(ledPin6, HIGH); delay (134);digitalWrite(ledPin6,LOW);delay(145); digitalWrite(ledPin7, HIGH); delay (134);digitalWrite(ledPin7,LOW);delay(145); digitalWrite(ledPin8, HIGH); delay (134);digitalWrite(ledPin8,LOW);delay(145); digitalWrite(ledPin9, HIGH); delay (134);digitalWrite(ledPin9,LOW);delay(145); digitalWrite(ledPin10, HIGH); delay (134);digitalWrite(ledPin10,LOW);delay(145); } Some students like to use an Arduino called a lilypad to make clothes that sparkle.

## circuit #08 : single servo motor

 Objectives Be able to describe how a servo is used explain what is meant by a library Look // Sweep// by BARRAGAN // This example code is in the public domain. #include Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object Serial.begin(9600);} void loop() { for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(100); // waits 15ms for the servo to reach the position } for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(100); // waits 15ms for the servo to reach the position } }

## Simple motor control

 // simple motor control// from book beginning arduino int potPin = 0;int transistorPin = 9;int potValue = 0; void setup(){ pinMode(transistorPin, OUTPUT);} // read value of potentiometer, convert to 0 - 255 potValue = anlogRead(potPin)/4;analogueWrite(transistorPin, potValue);}

## circuit #12 : spin motor spin

 p2n2222ag is an npn transistor. This form of transistor can be used as an amplifier. Making a circuit for transistorsnote npn transistors operate from the switch, pnp stay on.Identifying npn and pnp Vocabmultimeter, ohms, diode, pnp, npn,

## Controlling a motor with a transistor

 detecting input and making decisions /** Button * Mark Weber* adapted from* http://www.arduino.cc/en/Tutorial/Button** The trick is to have the 5v input controlled by pull down resistor* I used a 3K resistor, tute says 2.2K*/// Declare data types and variablesint ledPin1 = 4; // choose the pin for the motorint ledPin2 = 5; // choose the pin for the motorint inputPin = 2; // choose the input pin (for a pushbutton)int val = 0; // declare variable for reading the pin status void setup() {  pinMode(ledPin1, OUTPUT); // declare as output  pinMode(ledPin2, OUTPUT); // declare as output  pinMode(inputPin, INPUT); // declare pushbutton as input  Serial.begin(9600); // you can read the value of the pushbutton // in Tools ==> serial window}void loop(){if (val == HIGH) { // check if the input is HIGH// first one way  digitalWrite(ledPin1, LOW);   digitalWrite(ledPin2, HIGH);  delay(200);  val = digitalRead(inputPin);  Serial.print("val = HIGH, "); // read the value in serial monitor  Serial.println(val); } else {// then the other  digitalWrite(ledPin1, HIGH); //   digitalWrite(ledPin2, LOW); //  delay(200);  val = digitalRead(inputPin);   Serial.print("val = low, "); // read the value in serial monitor  Serial.println(val); }} Can you find the serial window in the ADE? Vocabulary analogue, serial, clock, data types, variables, loops,