Learn Arduino with Olympia Circuits
Learn Arduino
  • Home
    • Get Started
    • How to Use This Site
  • Electronics
    • The Basics
    • Electricity Flows like Water
    • Electronic Components
    • The Arno Board
  • Programming
    • The Basics
    • setup and loop Blocks
    • Variables and Arrays
    • Connecting with the Pins
    • Flow Control >
      • if Statement
      • Loops
      • Delays
    • Functions
    • Serial Communication
    • USB
    • Some Thoughts
  • Projects
    • Projects 1 >
      • 1.01: Blink
      • 1.02 Blink x2
      • 1.03 Blink Faster
      • 1.04 LED Chase!
      • 1.05 Wait To Blink
      • 1.06 Blink a Little Faster Now
      • 1.07 LED Fade
      • 1.08 RGB Blink
      • 1.09 Change RGB Color with SW1
      • 1.10 Fade RGB Colors
      • 1.11 Reaction Time Game
    • Projects 2 >
      • 2.01 Hello World
      • 2.02 Talk Back
      • 2.03 ASCII Values
      • 2.04 Ski Game
      • 2.05 Demonstration of the String Object
    • Projects 3 >
      • 3.01 Read the Potentiometer
      • 3.02 ASCIIbet Soup
      • 3.03 Potentiometer sets LED Brightness
      • 3.04 Potentiometer Sets Blink Rate
      • 3.05 LED Chase, Part II
    • Projects 4 >
      • 4.01 Bringing the Piezo to Life
      • 4.02 Controlling the Piezo with a Function
      • 4.03 Piezo C Major
      • 4.04 Piezo Greensleaves
      • 4.05 Piezo Metronome
      • 4.06 Piezo as an Input
      • 4.07 Piezo as an Input 2
      • 4.08 Metronome II
      • 4.09 Piezo Playback
      • 4.10 Piezo Fireworks
      • 4.11 Piezo Mosquito
    • Projects 5 >
      • 5.01 The Phototransistor
      • 5.02 Light and Sound
      • 5.03 Light and Sound II
    • Projects 6 >
      • 6.01 EEPROM
      • 6.02 I2C Address Scan
      • 6.03 Read the I2C Temperature Sensor
      • 6.04 High Temperature Alarm
    • Projects 7 >
      • 7.01 Arno Phone Home
      • 7.02 Keyboard Alphabet
      • 7.03 Move Mouse
      • 7.04 Draw Squares
    • Special Projects >
      • Bike Light Demo
  • References
    • Arno Pin Key
    • Arno Schematic
    • Project Index

Project 1.01: Blink

Nearly everyone starts out by learning how to blink an LED.  This project demonstrates all of the elements that we need to go on to bigger and better things: we set the pinMode in the setup() block and then blink LED1 by turning it on for one second and then off for one second.  Upload this sketch to the Arno, wait a moment, and then watch LED1 blink!

Concepts: setup(), loop(), declare variables, set pin modes, digitalWrite, delay.

Circuits:
  • Circuit 1

  • Select Sketch

    ///////////////////////////////////////////////////
    //Blink: our first project for the Arno
    int LED1 = 13;
    void setup(){
    pinMode(LED1,OUTPUT);
    }
    void loop(){
    digitalWrite(LED1,HIGH);
    delay(1000);
    digitalWrite(LED1,LOW);
    delay(1000);
    }
    ///////////////////////////////////////////////////

    Let’s take a closer look at how this sketch works.  We declare one int type variable at the top of the sketch.  It is a global variable since it is declared outside of the setup() block, loop() block, or any other function. This means we can use it anywhere else in the sketch.

    int LED1 = 13;

    Every sketch needs a setup() and loop() block.  The setup() block runs only once.  That’s all we need to set the pinMode of the LED to an output so that we can switch it on and off:

    void setup(){

      pinMode(LED1,OUTPUT);

    }

    Now comes the loop() block.  This block will run over and over again.  At the top of the block comes the digitalWrite statement.  This powers the pin attached to LED1 with 5 V, causing current to run from the pin, through the LED and resistor (we need that resistor to limit the current that will flow through the circuit), and finally to ground.  This causes LED1 to light up.

    void loop(){   

      digitalWrite(LED1,HIGH);

    LED1 will remain in a HIGH state until we tell it otherwise or we disconnect the Arno from its power source.  We want it to stay on for only a second so we wait a 1000 milliseconds:

      delay(1000);

    And then switch the pin to LOW.  Now the pin is at the same voltage as ground.  There’s no difference in electrical potential, so no current flows and the LED switches off:

      digitalWrite(LED1,LOW);

    We keep it off for another second and then finish the loop() block:

      delay(1000);

    }

    The closing bracket tells the Arno to go back to the top of the loop() block and do it all over again.

    Back to Projects 1

    Copyright Olympia Circuits LLC 2014. All Rights Reserved.