Outline

  1. Microcontroller. Analog. Digital. Input. Output.
  2. Analog/Digital converter.
  3. Serial communication.
  4. Voltage. Current. Ground.
  5. Parts, Pins, and Jacks
  6. Watch the 123d Circuit Video
  7. The IDE. Processing. AVRdude.
  8. LED.
  9. Experiments
    1. Experiment 1: blinking an LED on the board
      1. Experiment 1a: blinking discrete LED
    2. Experiment 2: getting input from the world (simple switch)
    3. Experiment 3: getting input from a sensor (photodiode) to serial monitor
    4. Experiment 4: simple 4 bit counter
    5. Experiment 5: analog sensor (Getting Started with Arduino chapter 5)

Parts

Arduino Uno or other

  1. LEDs (4)
  2. 220 ohm R (4) RRBr
  3. 1k ohm R (1) BrBkR
  4. 10k ohm R (1) BrBkY
  5. Switch
  6. Photoresistor

The Arduino is a prototyping platform. It consists of some inexpensive hardware and a relatively easy to use software environment. The hardware part looks like this:

arduino_transparent.pngarduino_topview.png

The hardware can be connected to all kinds of sensors (switches, light and motion detectors, etc.) for inputs and it can control things like motors, lights, bells, etc. We write simple programs that tell the Arduino how to vary the outputs based on what the inputs are.

Example

One might create a burglar alarm like this:

alarmcircuit.png

There is a sensor mounted on the window - as long as the window is closed the sensor sends the signal "closed" to the Arduino board. A bell is connected to the output "pins" of the Arduino. We write a simple "sketch" (this is what a program in the Processing language is called) that (1) tells the Arduino what pins are inputs and what pins are outputs, and then (2) simply waits over and over again doing nothing as long as (while) the window is closed, but (3) stops waiting if the window opens and sends a signal to ring the bell.

Getting Started

The beauty of Arduino is that you can get hands-on prototyping experience really easily. But it turns out you don't even need to have access to an Arduino board to start experimenting. We will illustrate our initial exercises using Autodesk's 123d Circuits software.

// Pin 13 has an LED connected to it.

#define LED 13  // Define the name "LED" as 13

// setup routine runs once when board is reset

void setup() {

  pinMode(LED, OUTPUT);   // Tell Arduino pin 13 is an output.

}

// loop routine runs forever:

void loop() {
  digitalWrite(LED, HIGH);   // turn the LED on (HIGH is digital "1")
  delay (1000);              // wait 1 second
  digitalWrite(LED, LOW);    // turn the LED off (LOW is digital "0")
  delay (1000);              // wait 1 second
}

Next, let's connect a discrete (meaning separate) LED to the circuit, putting its cathode (short leg) into the GND socket and its anode (long leg) into the pin 13 socket

A Short Aside on LEDs

A diode is a component that lets electricity flow in only one direction. If the voltage on its anode is higher than the cathode by enough, it will permit current to flow. If the voltage is the other way round it blocks the flow. If it is a Light Emitting diode then it glows when current flows.

In a circuit we put a resistor in series with the LED so that the voltage drop across the LED is appropriate.

battery.jpgLED.png
LED2.png
arduino-blink01-with-LED.png

The same code should blink this circuit.

Adding a Switch for Interaction

We now add a switch to the circuit. When the switch is pressed a circuit is closed and a positive voltage appears at one end of the switch. We attach an input pin to this point and change our code so that it turns the LED on or off depending on what is detected at the input pin.

#define LED 13   // Define the name "LED" as 13
#define BUTTON 7 // Pin 7 will detect button push
int val = 0;     // Used to store button state

// setup routine runs once when board is reset

void setup() {

  pinMode(LED, OUTPUT);   // Tell Arduino pin 13 is an output
  pinMode(BUTTON, INPUT); // and pin 7 is an input

}

// loop routine runs forever:

void loop() {
  val = digitalRead(BUTTON);  // Read and store button state

  if (val == HIGH) {          // If button is pushed
    digitalWrite(LED, HIGH);  // turn the LED on (HIGH is digital "1")
  } else {
    digitalWrite(LED, LOW);  // turn the LED off (LOW is digital "0")
  }
}

// Name the LED pins
int led0 = 13;
int led1 = 12;
int led2 = 11;
int led3 = 10;
int count = 0;

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pins as an output.
  pinMode(led3, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led1, OUTPUT);
  pinMode(led0, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  int i = 0;
  count = (count + 1) % 16;
  i = count;
  if (i > 7) {                     // is the fourth bit on?   
    digitalWrite(led3, HIGH);      // if so, LED on and 
    i = i - 8;}                    // take away 8 = 2**3
  else {digitalWrite(led3, LOW);}; // else turn LED off
  if (i > 3) {                     // is the third bit on?
    digitalWrite(led2, HIGH);
    i = i - 4;}
  else {digitalWrite(led2, LOW);};
  if (i > 1) {                     // is the second bit on?
    digitalWrite(led1, HIGH);
    i = i - 2;}
  else {digitalWrite(led1, LOW);};
  if (i > 0) {                     // is the first bit on?
    digitalWrite(led0, HIGH);
    }
  else {digitalWrite(led0, LOW);};

  delay(1000);                       // wait for a second

}

arduino-bb-4bit-counter.png

Communicating between Processing and Arduino Processing

And then we send this code to the Arduino

Using a Circuit to Control Screen Graphics

arduino-004.png

The Arduino Sketch

The Processing Sketch

Suggested

https://processing.org/tutorials/electronics/
http://www.talkingelectronics.com/ChipDataEbook-1d/html/SM-LEDs.html

File nameFile typeSize
arduino-1.6.0-macosx.zipZip archive data134.97 MBInfo
Getting_Started_with_Arduino-1.pdfPDF document1.87 MBInfo