Top Banner
Getting Started with Arduino
21

Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Aug 21, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Getting Started with Arduino

Page 2: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

What is Arduino?

Page 3: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Arduino is…

• Small, programmable microcontroller.

• Software that runs on Mac, PC, and Linux. (IDE)

• Learning platform (for electronics & programming).

• Community of people sharing code & ideas.

Page 4: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Arduino Hardware: UNO

Reset Button

USB / Power

DC PowerPower & Analog Inputs

ATmega 328

Digital Inputs & Outputs

Page 5: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

The Arduino Family

UNO Leonardo

MEGADUE

Page 6: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

More Family…

Esplora

Arduino Ethernet

Lilypad

Micro

Nano

Pro

Pro Mini

Fio

Page 7: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Arduino Software

Upload Serial Monitor

Arduino Sketch Code

Errors

Page 8: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Anatomy of a Sketch/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */

// the setup function runs once when you press reset or power the boardvoid setup() // initialize digital pin 13 as an output. pinMode(13, OUTPUT);

// the loop function runs over and over again forevervoid loop() digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second

Start Comment

End Comment Descriptive Comment

Line Comments

Start Comment

Page 9: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Anatomy of a Sketch/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */

// the setup function runs once when you press reset or power the boardvoid setup() // initialize digital pin 13 as an output. pinMode(13, OUTPUT);

// the loop function runs over and over again forevervoid loop() digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second

Page 10: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Anatomy of a Sketch/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */

// the setup function runs once when you press reset or power the boardvoid setup() // initialize digital pin 13 as an output. pinMode(13, OUTPUT);

// the loop function runs over and over again forevervoid loop() digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second

Hey Arduino, here’s how you setup

Code block for setup

Page 11: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Anatomy of a Sketch/* Blink Turns on an LED on for one second, then off for one second, repeatedly. This example code is in the public domain. */

// the setup function runs once when you press reset or power the boardvoid setup() // initialize digital pin 13 as an output. pinMode(13, OUTPUT);

// the loop function runs over and over again forevervoid loop() digitalWrite(13, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(13, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second

Hey Arduino, here’s how you loop

Code block for loop

Page 12: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Electronics is… Moving Charge

Highly energetic charge particle+

+ Exhausted charge particle

+ Less energetic charge particle

Page 13: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Pin 13

GND

LED

Simple Circuit

+

++

++

++

++

+

+

++

+

++

++

+

+

+

+

++++

+ +

+

+

+

+

+ +

+

+

+ +

+

+

+

Page 14: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

A Happier LED

+

+

+ +

+

+

++

+

+

++

+

++

++

330 Ω

330 Ω

5V

GND

LED

Page 15: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

The BreadboardAbove the board

Inside the board

Making a connection

+ Runs power along column − Runs ground along column

Each numbered row has 5 connected sockets

Inside the board »

Page 16: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

A Blinking LED

+

+

+ +

+

+

++

+

+

++

+

++

++

330 Ω

Pin 13

GND

330 Ω

LED

Page 17: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Control the Blinking

330 Ω

Pin 13

GND

10k Ω

5V

A0

GND

+

+

+ +

+

+

++

+

+

++

+

++

++

++

++

++

++

+

+

++

+

+

++

+

330 Ω

LED

Page 18: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Control the Blinking, Code/* Analog Input[...]

This example code is in the public domain. */

int sensorPin = A0; // select the input pin for the potentiometerint ledPin = 13; // select the pin for the LEDint 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 <sensorValue> milliseconds: delay(sensorValue); // turn the ledPin off: digitalWrite(ledPin, LOW); // stop the program for for <sensorValue> milliseconds: delay(sensorValue);

Page 19: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Debug the Blinking/* Analog Input [...] This example code is in the public domain. */

int sensorPin = A0; // select the input pin for the potentiometerint ledPin = 13; // select the pin for the LEDint sensorValue = 0; // variable to store the value coming from the sensor

void setup() // declare the ledPin as an OUTPUT: pinMode(ledPin, OUTPUT); // open a 9600-baud serial connection: Serial.begin(9600);

void loop() // read the value from the sensor: sensorValue = analogRead(sensorPin); // write the sensor value to the serial interface: Serial.println(sensorValue); // turn the ledPin on digitalWrite(ledPin, HIGH); // stop the program for <sensorValue> milliseconds: delay(sensorValue); // turn the ledPin off: digitalWrite(ledPin, LOW); // stop the program for for <sensorValue> milliseconds: delay(sensorValue);

Page 20: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Examples!• Make the potentiometer control brightness instead of blink

rate. Hint: try flashing the LED really quickly! The analogWrite function might help!

• Wire up 8 LEDs to 8 digital output pins. Use the potentiometer to control how many of the LEDs are on — a level meter!

• Control the red, green, and blue components of an RGB LED using three potentiometers.

• Challenge: Blink two LEDs, controlling the rate of each independently with its own potentiometer. Hint: You can’t use delay() anymore! Look at millis() instead.

Page 21: Getting Started with Arduino - Workshop Weekendworkshopweekend.net/img/arduino-projects/intro.pdf · Anatomy of a Sketch /* Blink Turns on an LED on for one second, then off for one

Arduino is…

Small, programmable microcontroller.

Software that runs on Mac, PC, and Linux. (IDE)

• Learning platform (for electronics & programming).

• Community of people sharing code & ideas.