Arduino Lesson 1. Blink



Similar documents
Arduino Lesson 14. Servo Motors

Arduino Lesson 5. The Serial Monitor

Arduino Lesson 13. DC Motors. Created by Simon Monk

Arduino Lesson 9. Sensing Light

Arduino Lesson 4. Eight LEDs and a Shift Register

Arduino Lesson 16. Stepper Motors

Arduino Lesson 0. Getting Started

Arduino Lesson 17. Sending Movement Detector

SSH to BeagleBone Black over USB

Workshop Intel Galileo Board

Bluetooth + USB 16 Servo Controller [RKI-1005 & RKI-1205]

USB Driver Installation for Windows XP

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

#include <Gamer.h> Gamer gamer; void setup() { gamer.begin(); } void loop() {

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable. Created by Simon Monk

INDEX. Trademarks All name and product s trademarks mentioned below are the property of their respective companies.

CM HOST CM CardTransporter Fuel Communication and Management Software Software version up to 3.1

Set up and Blink - Simulink with Arduino

Adafruit's Raspberry Pi Lesson 5. Using a Console Cable

3.1 Backup and Recovery System

Waspmote. Quickstart Guide

How To Set Up A Smart Card Programmer With Titan (Titan) And Titan 2.3 (Tok) (Tonga) (Powerbook) (Smart Card) (Programmer) (S

Lesson 8: Simon - Arrays

Animated Lighting Software Overview

Using the Communication Ports on the DG-700 and DG-500 Digital Pressure Gauges

HomeSeer Technologies. HomeSeer Technologies LLC 35 Constitution Dr, Suite C Bedford NH,

ISP Engineering Kit Model 300

MS830 / MS833 Barcode Reader v1.0 9-December-2014

Board also Supports MicroBridge

TUTORIAL 3 :: ETHERNET SHIELD AND TWITTER.COM

Programming the VEX Robot

Digital Photo Bank / Portable HDD Pan Ocean E350 User Manual

TUTORIAL FOR INITIALIZING BLUETOOTH COMMUNICATION BETWEEN ANDROID AND ARDUINO

Arduino Wifi shield And reciever. 5V adapter. Connecting wifi module on shield: Make sure the wifi unit is connected the following way on the shield:

Yun Shield Quick Start Guide VERSION: 1.0 Version Description Date 1.0 Release 2014-Jul-08 Yun Shield Quick Start Guide 1 / 14

Your Multimeter. The Arduino Uno 10/1/2012. Using Your Arduino, Breadboard and Multimeter. EAS 199A Fall Work in teams of two!

Work with Arduino Hardware

Basic Pulse Width Modulation

Waspmote IDE. User Guide

An Introduction To Simple Scheduling (Primarily targeted at Arduino Platform)

Sending an SMS with Temboo

Speedlink software will run on Windows NT, Windows 7, and Windows 8; it will run on both 32 byte and 64 byte versions of Windows.

Arduino DUE + DAC MCP4922 (SPI)

Eric Mitchell April 2, 2012 Application Note: Control of a 180 Servo Motor with Arduino UNO Development Board

Installation Instructions

TPG MOBILE BROADBAND QUICK SETUP GUIDE

LOK-IT ENCRYPTED USB Administrator User Instructions

PHYS 2P32 Project: MIDI for Arduino/ 8 Note Keyboard

Sending Data from a computer to a microcontroller using a UART (Universal Asynchronous Receiver/Transmitter)

EARTH PEOPLE TECHNOLOGY SERIAL GRAPH TOOL FOR THE ARDUINO UNO USER MANUAL

Using the Parani SD1000U/SD1000 with Carlson SurvCE

DS1307 Real Time Clock Breakout Board Kit

How to setup a serial Bluetooth adapter Master Guide

Ethernet Radio Configuration Guide

Lab 6 Introduction to Serial and Wireless Communication

Table of Contents Getting Started... 3 The Motors... 4 The Control Board... 5 Setting up the Computer with Mach Starting up the Equipment...

Adafruit's Raspberry Pi Lesson 1. Preparing an SD Card for your Raspberry Pi

Caplio Utility for Windows

2.2" TFT Display. Created by Ladyada. Last updated on :15:09 PM EDT

Troubleshooting Tips Lifestyle SA-2 & SA-3 Amplifier. Troubleshooting Tips

iloq P10S.10/20 Programming device User's Guide

MeshBee Open Source ZigBee RF Module CookBook

Using and Installing: HCS12C32 Board, HCS12C128 Board, USB-to-Serial port driver, and HyperTerminal

Bidirectional wireless communication using EmbedRF

Installation of the USB to RS 485 Converter

Scan2CRM for ACT! User Guide

Application & Quick-Start Guide

Software Toolbox License Transfer Guide. TOP Server OPC Server

Bluetooth Installation

Using USB Flash Drives

Tiny Arduino Music Visualizer

cs281: Introduction to Computer Systems Lab08 Interrupt Handling and Stepper Motor Controller

Business Plus Accounting Hardware Setup Guide For Windows XP

BIODEX. ATOMLAB 500/WIPE TEST COUNTER DATA MANAGER SOFTWARE Version 1.10 (and higher). OPERATION MANUAL

Programming Arduino. Getting Started with Sketches. Simon Monk.

Sabrent USB DSC5 USB 2.0 to SATA/IDE Hard Drive Adapter. 2.5 Notebook IDE Hard Drive

TCP/IP MODULE CA-ETHR-A INSTALLATION MANUAL

SainSmart UNO R3 Starter Kit

Designing VM2 Application Boards

Windows XP.. ELITE Firmware Update procedures.. v1.41

PRODUCTIVITY THROUGH INNOVATION 600 CONTROL DIRECT DRIVE TECHNICAL/OPERATION MANUAL

Intro to Intel Galileo - IoT Apps GERARDO CARMONA

Greetings Keyboard Mastery Keyboarding Students! Teacher: Mrs. Wright

DMX USB PRO. User Manual.

Warnings: This manual is intended to guide a technicians or customers who would like to repair DBL's

DKVM-2KU KVM Switch with USB 2.0 Sharing with Built-In Cables. Quick Installation Guide

Programming PIC Microcontrollers in PicBasic Pro Lesson 1 Cornerstone Electronics Technology and Robotics II

Getting started with the O Watch

Adafruit's Raspberry Pi Lesson 3. Network Setup

SOFTWARE USER GUIDE. Aleratec. Part No , EU. 1:10 USB 3.0 Copy Cruiser Mini

Watch GPS Instruction Manual. If you have any other questions or concerns, please call or go to

SMART BOARD USER GUIDE FOR PC TABLE OF CONTENTS I. BEFORE YOU USE THE SMART BOARD. What is it?

Running the R4 Software on a USB Port

LP 2844 Thermal Printer

Chapter 1 Installing the Gateway

N750 WiFi DSL Modem Router Premium Edition

Zebra Ethernet. Frequently Asked Questions

Quick Start Guide Vodafone Mobile Connect USB Stick. Designed for Vodafone

This document will show you how to set up the Hotwire 6205 ADSL Modem, and how to customize its configuration to get the most out of this product.

Transcription:

Arduino Lesson 1. Blink Created by Simon Monk Last updated on 2015-01-15 09:45:38 PM EST

Guide Contents Guide Contents Overview Parts Part Qty The 'L' LED Loading the 'Blink' Example Saving a Copy of 'Blink' Uploading Blink to the Board How 'Blink' Works Blinking Faster Other Things to Do 2 3 4 4 4 6 8 11 13 15 17 18 Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 2 of 18

Overview In this lesson, you will learn how program your Arduino to make the Arduino's built-in LED blink. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 3 of 18

Parts Part Qty Arduino Uno R3 1 Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 4 of 18

USB Lead - type A to B 1 Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 5 of 18

The 'L' LED The Arduino has rows of connectors along both sides that are used to connect to electronic devices and plug-in 'shields' that allow the Arduino to do more. However, the Arduino also has a single LED that you can control from your sketches. This LED is built onto the Arduino board and is often referred to as the 'L' LED as this is how it is labelled on the board. The position of this LED is circled in red on the pictures of the Arduino Uno and Leonardo below. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 6 of 18

Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 7 of 18

Loading the 'Blink' Example You may find that your Arduino board's 'L' LED already blinks when you connect it to a USB plug. This is because Arduino boards are generally shipped with the 'Blink' sketch preinstalled. In this lesson, we will reprogram the Arduino with our own Blink sketch and then change the rate at which it blinks. In Lesson 0, you setup your Arduino IDE and made sure that you could find the right serial port for it to connect to your Arduino board. The time has now come to put that connection to the test and program your Arduino board. The Arduino IDE includes a large collection of example sketches that you can load up and use. This includes an example sketch for making the 'L' LED blink. Load the 'Blink' sketch that you will find in the IDE's menu system under File Examples 01.Basics Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 8 of 18

When the sketch window opens, enlarge it so that you can see the whole of the sketch in the window. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 9 of 18

Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 10 of 18

Saving a Copy of 'Blink' The example sketches included with the Arduino IDE are 'read-only'. That is, you can upload them to an Arduino board, but if you change them, you cannot save them as the same file. We are going to change this sketch, so, the first thing you need to do is save your own copy that you can change however you like. From the File menu on the Arduino IDE select the option 'Save As..' and then save the sketch with the name 'MyBlink'. You have saved your copy of 'Blink' in your sketchbook. This means that if you ever want to find it again, you can just open it using the File Sketchbook menu option. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 11 of 18

Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 12 of 18

Uploading Blink to the Board Attach your Arduino board to your computer with the USB cable and check that the 'Board Type' and 'Serial Port' are set correctly. You may need to refer back to Lesson 0. The Arduino IDE will show you the current settings for board at the bottom of the window. Click on the 'Upload' button. The second button from the left on the toolbar. If you watch the status area of the IDE, you will see a progress bar and a series of messages. At first it will say 'Compiling Sketch..'. This converts the sketch into a format suitable for uploading to the board. Next, the status will change to 'Uploading'. At this point, the LEDs on the Arduino should start to flicker as the sketch is transferred. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 13 of 18

Finally, the staus will change to 'Done'. The other message tells us that the sketch is using 1,084 bytes of the 32,256 bytes available.after the 'Compiling Sketch..' stage you could get the following error message: The clue is at the top here, it probably means that your board is not connected at all, or the drivers have not been installed (if necessary) or that the wrong serial port is selected. If you get this, go back to Lesson 0 and check your installation. Once the upload has completed, the board should restart and start blinking. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 14 of 18

How 'Blink' Works Here is the code for the Blink sketch. /* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */ // Pin 13 has an LED connected on most Arduino boards. // give it a name: int led = 13; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinmode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { digitalwrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalwrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } The first thing to note is that quite a lot of this sketch is what is called 'comments'. Comments are not actual program instructions, they are just comments about how the program works. They are there for out benefit, so that there is some explanation to accompany the sketch. Everything between /* and */ at the top of the sketch is a block comment, that explains what the sketch is for. There are also single line comments that start with // and everything up intil the end of the line counts as being a comment. The first actual line of code is: int led = 13; Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 15 of 18

As the comment above explains, this is giving a name to the pin that the LED is attached to. This is 13 on most Arduinos, including the Uno and Leonardo. Next, we have the 'setup' function. Again, as the comment says, this is run when the reset button is pressed. It is also run whenever the board resets for any reason, such as power first being applied to it, or after a sketch has been uploaded. void setup() { // initialize the digital pin as an output. pinmode(led, OUTPUT); } Every Arduino sketch must have a 'setup' function, and the part of it where you might want to add instructions of your own is between the { and the }. In this case, there is just one command there, which, as the comment states tells the Arduino board that we are going to use the LED pin as an output. It is also mandatory for a sketch to have a 'loop' function. Unlike the 'setup' functio n that only runs once, after a reset, the 'loop' function will, after it has finished running its co mmands, immediately start again. void loop() { digitalwrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalwrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second } Inside the loop function, the commands first of all turn the LED pin on (HIGH), then 'delay' for 1000 milliseconds (1 second), then turn the LED pin off and pause for another second. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 16 of 18

Blinking Faster You are now going to make your LED blink faster.as you might have guessed, the key to this lies in changing the parameter in () for the 'delay' command. This delay period is in milliseconds, and so if you want the LED to blink twice as fast, change the value of 1000 to 500. This would then pause for half a second each delay rather than a whole second. Upload the sketch again and you should see the LED start to flash more quickly. Adafruit Industries https://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 17 of 18

Other Things to Do Try changing the delay again to make the blinking even faster using 100 as the parameter to 'delay'. Click Here for the Next Lesson http://adafru.it/au9 About the Author. Simon Monk is author of a number of books relating to Open Source Hardware. The following books written by Simon are available from Adafruit: Programming Arduino (http://adafru.it/1019), 30 Arduino Projects for the Evil Genius (http://adafru.it/868) and Programming the Raspberry Pi (http://adafru.it/am5). Adafruit Industries Last Updated: 2015-01-15 09:45:39 PM EST Page 18 of 18