Arduino Lesson 1. Blink. Created by Simon Monk

Similar documents
For this exercise, you will need a partner, an Arduino kit (in the plastic tub), and a laptop with the Arduino programming environment.

MAE106 Laboratory Exercises Lab # 1 - Laboratory tools

Lesson 3: Arduino. Goals

EE-110 Introduction to Engineering & Laboratory Experience Saeid Rahimi, Ph.D. Labs Introduction to Arduino

J. La Favre Using Arduino with Raspberry Pi February 7, 2018

smraza Getting Start Guide Contents Arduino IDE (Integrated Development Environment)... 1 Introduction... 1 Install the Arduino Software (IDE)...

LESSONS Lesson 1. Microcontrollers and SBCs. The Big Idea: Lesson 1: Microcontrollers and SBCs. Background: What, precisely, is computer science?

Objectives: Learn what an Arduino is and what it can do Learn what an LED is and how to use it Be able to wire and program an LED to blink

Objective of the lesson

Lab 2: Blinkie Lab. Objectives. Materials. Theory

Lab 5: Arduino Uno Microcontroller Innovation Fellows Program Bootcamp Prof. Steven S. Saliterman

Welcome to Arduino Day 2016

CPSC 226 Lab Four Spring 2018

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

Programming 2 Servos. Learn to connect and write code to control two servos.

MICROCONTROLLERS BASIC INPUTS and OUTPUTS (I/O)

CURIE Academy, Summer 2014 Lab 2: Computer Engineering Software Perspective Sign-Off Sheet

Montgomery Village Arduino Meetup Dec 10, 2016

Arduino STEAM Academy Arduino STEM Academy Art without Engineering is dreaming. Engineering without Art is calculating. - Steven K.

INTRODUCTION to MICRO-CONTROLLERS

INTRODUCTION to MICRO-CONTROLLERS

EGG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

The wiring is relatively simple. You should put the module on one of the compatible Arduinos. The following are compatible:

FABO ACADEMY X ELECTRONIC DESIGN

ISSN: [Singh* et al., 6(6): June, 2017] Impact Factor: 4.116

HC-SR501 Passive Infrared (PIR) Motion Sensor

TWEAK THE ARDUINO LOGO

Practical Assignment 1: Arduino interface with Simulink

Adafruit 16-Channel Servo Driver with Arduino

INTRODUCTION to MICRO-CONTROLLERS

APDS-9960 RGB and Gesture Sensor Hookup Guide

Coding with Arduino to operate the prosthetic arm

Adafruit's Raspberry Pi Lesson 8. Using a Servo Motor

Capacitive Touch with Conductive Fabric & Flora

Pulse Width Modulation and

Milli Developer Kit Reference Application Published on Silver Spring Networks STAGE (

Rodni What will yours be?

INA169 Breakout Board Hookup Guide

Application Note. Communication between arduino and IMU Software capturing the data

Arduino An Introduction

LED + Servo 2 devices, 1 Arduino

CONSTRUCTION GUIDE IR Alarm. Robobox. Level I

Electronic Prototyping

EARTH PEOPLE TECHNOLOGY. EPT-200TMP-TS-U2 Temperature Sensor Docking Board User Manual

EGG 101L INTRODUCTION TO ENGINEERING EXPERIENCE

Internet of Things Student STEM Project Jackson High School. Lesson 2: Arduino and LED

ZX Distance and Gesture Sensor Hookup Guide

Application Note AN 157: Arduino UART Interface to TelAire T6613 CO2 Sensor

Servo Sweep. Learn to make a regular Servo move in a sweeping motion.

AS726X NIR/VIS Spectral Sensor Hookup Guide

VBRC 5. Radio Communicator. Installer Manual

WEEK. Learning Objective. Materials to Prepare LESSON

Module: Arduino as Signal Generator

1Getting Started SIK BINDER //3

Application Note AN 102: Arduino I2C Interface to K 30 Sensor

PLAN DE FORMACIÓN EN LENGUAS EXTRANJERAS IN-57 Technology for ESO: Contents and Strategies

Programming a Servo. Servo. Red Wire. Black Wire. White Wire

Arduino

The DesignaKnit Serial E6000 Link 1

Grove - Infrared Receiver

Preface. If you have any TECHNICAL questions, add a topic under FORUM section on our website and we'll reply as soon as possible.

Using the S5U13781R01C100 Shield Graphics Library with Atmel Studio

Veyron Servo Driver (24 Channel) (SKU:DRI0029)

On the front of the board there are a number of components that are pretty visible right off the bat!

Lesson 2 Bluetooth Car

A servo is an electric motor that takes in a pulse width modulated signal that controls direction and speed. A servo has three leads:

Controlling Your Robot

Light Emitting Diode IV Characterization

PSoC and Arduino Calculator

WEEK. Learning Objective. Materials to Prepare. Summary of Class LESSON

Community College of Allegheny County Unit 4 Page #1. Timers and PWM Motor Control

You'll create a lamp that turns a light on and off when you touch a piece of conductive material

BeeLine TX User s Guide V1.1c 4/25/2005

Quick Start. DTA Self-Install Guide

Getting Started with the micro:bit

Adafruit 16-channel PWM/Servo Shield

Tarocco Closed Loop Motor Controller

Inspiring Creative Fun Ysbrydoledig Creadigol Hwyl. S4A - Scratch for Arduino Workbook

Arduino Workshop 01. AD32600 Physical Computing Prof. Fabian Winkler Fall 2014

The DesignaKnit USB E6000 Link 1 & 2

The DesignaKnit Serial Brotherlink 3

Intelligent Systems Design in a Non Engineering Curriculum. Embedded Systems Without Major Hardware Engineering

VBRC 4. Radio Communicator. Installer Manual

In this project, you will create a memory game where you have to memorise and repeat a sequence of random colours!

Adafruit 16-Channel PWM/Servo HAT & Bonnet for Raspberry Pi

Adafruit 16-Channel Servo Driver with Arduino

Grove - Collision Sensor

the Multifunctional DCC decoder for servo s and accessory s with Arduino for everybody (with a DCC central station)

Adafruit 16-Channel PWM/Servo HAT for Raspberry Pi

Circuit Playground Quick Draw

Adafruit 16-channel PWM/Servo Shield

1. ASSEMBLING THE PCB 2. FLASH THE ZIP LEDs 3. BUILDING THE WHEELS

Megamark Arduino Library Documentation

Setting up Volumio to get great audio

CONSTRUCTION GUIDE Robotic Arm. Robobox. Level II

Experiment 1 Identification of Components and Breadboard Realization

TLE5014 Programmer. About this document. Application Note

Lesson 13. The Big Idea: Lesson 13: Infrared Transmitters

Adafruit 16 Channel Servo Driver with Raspberry Pi

Computer Science/Computer Engineering. Wheeler HS Fall 2018 Foundations of Engineering

Transcription:

Arduino Lesson 1. Blink Created by Simon Monk

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 5 6 8 9 11 13 14 Adafruit Industries http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 2 of 14

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

Parts Part Qty Arduino Uno R3 1 USB Lead - type A to B 1 Adafruit Industries http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 4 of 14

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 http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 5 of 14

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 pre-installed. 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 When the sketch window opens, enlarge it so that you can see the whole of the sketch in the window. Adafruit Industries http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 6 of 14

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

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 http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 8 of 14

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. Finally, the staus will change to 'Done'. Adafruit Industries http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 9 of 14

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 http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 10 of 14

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; 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. Adafruit Industries http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 11 of 14

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' function that only runs once, after a reset, the 'loop' function will, after it has finished running its commands, 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 http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 12 of 14

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 http://learn.adafruit.com/adafruit-arduino-lesson-1-blink Page 13 of 14

Other Things to Do Try changing the delay again to make the blinking even faster using 100 as the parameter to 'delay'. 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: 2012-12-28 01:42:02 PM EST Page 14 of 14