Topic outline

  • General

    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

    Sparkfun inventors' guide(PDF)

  • Topic 1

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

    resistor code Resistors explained
    • Topic 2

      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.
      • Download and install the Arduino SDK.
      • Install any drivers needed for your machine to communicate via USB.
      • Identify which Arduino you have.
      • identify which COM port it is connected to.

       

      uno
      Now download the Sparkfun inventors guide.

      Sparkfun inventors' guide(PDF)

      • Topic 3

        using a breadboard

        the man from instructables

        • Topic 4

          circuit #01 : blinking lights

          Outcomes

          • Be able to explain what is meant by a diode.
          • Be able to explain what is meant by a LED.
          • Be able to explain why a protection resistor is used.
          • Be able to find the data sheet for a component.
          • Be able to explain how the value of the protection resistor is calculated.
          • Be able to find the example code in the Arduino SDK.
          • Be able to load and edit a sketch in  the Arduino SDK.



          What to do

          Follow circuit #1 from Sparkfun SIK guide.

          Search on Arduino site for further information.

          What We're Doing

          LEDs (light emitting diodes) are used in all sorts of clever things which is why we have included them in this kit. We will start off with something very simple, turning one on and off, repeatedly, producing a pleasant blinking effect. Once the circuit is assembled you'll need to upload the program.

          To do this

          1. plug the Arduino board into your USB port.
          2. select the proper port in Tools > Serial Port > (the comm port of your Arduino).
          3. upload the program by going to File > Upload to I/O Board (ctrl+U).

          Finally, bask in the glory and possibility that controlling lights offers.

          If you are having trouble uploading, a full trouble shooting guide can be found here: http://ardx.org/TRBL Hints and tips

          the led only allows current to flow across it in one direction.

          the code must be typed exactly as written - it is case sensitive.

          blink

          Sketch 

            *Blink
            *Turns on an LED on for one second, then off for one second, repeatedly.
            *The circuit:
            * LED connected from digital pin 13 to ground.
            * Note: On most Arduino boards, there is already an LED on the board
            * connected to pin 13, so you don't need any extra components for this example.
            
            *Created 1 June 2005
            *By David Cuartielles
            *http://arduino.cc/en/Tutorial/Blink
            *based on an orginal by H. Barragan for the Wiring i/o board
          */
           
          int ledPin =  13;    // LED connected to digital pin 13
           
          // The setup() method runs once, when the sketch starts
           
          void setup()   {                
            // initialize the digital pin as an output:
            pinMode(ledPin, OUTPUT);     
          }
           
          // the loop() method runs over and over again,
          // as long as the Arduino has power
           
          void loop()                     
          {
            digitalWrite(ledPin, HIGH);   // set the LED on
            delay(1000);                  // wait for a second
            digitalWrite(ledPin, LOW);    // set the LED off
            delay(1000);                  // wait for a second
          }


          • Topic 5

            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.

            potentiometer

            /*
              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 potentiometer
            int ledPin = 13;      // select the pin for the LED
            int sensorValue = 0;  // variable to store the value coming from the sensor

            void 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);                  
            }
            potentiometer

            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.

            • Topic 6

              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 potentiometer
              int 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
              }

              potentiometer
              • Topic 7

                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.
                 
                • Topic 8

                  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 weber
                  250498

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

                  • Topic 9

                    circuit #05 : pushbuttons

                    • Topic 10

                      circuit #07 : temperature sensor

                      • Topic 11

                        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 <http://barraganstudio.com>
                        // This example code is in the public domain.


                        #include <Servo.h>

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

                        servo
                        • Topic 12

                          circuit #09 : flex sensor

                          • Topic 13

                            ircuit #10 : soft sensorc

                            • Topic 14

                              circuit #11 : peizo element

                              • Topic 15

                                circuit #13 : relays

                                • Topic 16

                                  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);
                                  }

                                  • Topic 17

                                    circuit #12 : spin motor spin

                                    npn
                                    p2n2222ag is an npn transistor. This form of transistor can be used as an amplifier.



                                    note npn transistors operate from the switch, pnp stay on.

                                    pnp Vocab

                                    multimeter, ohms, diode, pnp, npn,
                                    • Topic 18

                                      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 variables
                                      int ledPin1 = 4; // choose the pin for the motor
                                      int ledPin2 = 5; // choose the pin for the motor
                                      int 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, 

                                      • Topic 19

                                        circ-12 : colorful light

                                        • Topic 20

                                          circ-13 : measuring bends

                                          • Topic 21

                                            circ-14 : fancy sensing

                                            • Topic 22

                                              Simple stepper motor

                                              • Topic 23

                                                nn

                                                • Topic 24

                                                  nn

                                                  • Topic 25

                                                    nn

                                                    • Topic 26

                                                      nn

                                                      • Topic 27

                                                        nn

                                                        • Topic 28

                                                          nn

                                                          • Topic 29

                                                            nn

                                                            • Topic 30

                                                              nn