introduction to arduino

15
Introduction to Arduino/Genuino Uno By: Yeo Kheng Meng (yeokm1@gmai https://github.com/SustainableLivingLab/intro-to- artathon (20 Feb 2016) 1

Upload: yeokm1

Post on 17-Jan-2017

952 views

Category:

Technology


2 download

TRANSCRIPT

Page 1: Introduction to Arduino

1

Introduction toArduino/Genuino Uno

By: Yeo Kheng Meng ([email protected]) https://github.com/SustainableLivingLab/intro-to-arduinoStartathon (20 Feb 2016)

Page 2: Introduction to Arduino

Components/Software check• Laptop loaded with Arduino IDE • Whole Hackpack or at least• Arduino Uno• Breadboard• USB cable• LED• Button• 220 ohm resistor• 10k ohm resistor• At least a few jumper wires

Page 3: Introduction to Arduino

Why the 2 names?• Different branding• Arduino (sold in USA)• Genuino (sold everywhere else)

• Some disagreements between the founders

• Uno boards from both brands are otherwise identical

Page 4: Introduction to Arduino

First some electronic basics

Page 5: Introduction to Arduino

Digital Logic Levels• Logic HIGH = True = ON = +5V / +3.3V• Logic LOW = False = OFF = 0V

• +5V for Arduino Uno

• +3.3V may be used by other devices

Page 6: Introduction to Arduino

Analog signal

• Analog signals are smooth and continuous• Can be positive and/or negative or both• Signals will be converted by analog-to-digital converter (ADC)

in Arduino before use • Arduino’s resolution is 10bits: 210 = 1024• Range: 0 – 5V >>>> 0 – 1024

Page 7: Introduction to Arduino

Breadboard• Your main prototyping component• Continuous lines indicate those holes are connected together

• Horizontal usually for power • Convention: Red for +, Black/Blue for -

• Vertical for your components

Page 8: Introduction to Arduino

Now we come to the Arduino

• Programmable board• Use program code to:

• Receive signal inputs from pins• Control signal outputs of pins

Page 9: Introduction to Arduino

Ex 1: Blink onboard LED• Sanity check, verifies if working

• Arduino hardware• Arduino IDE settings

• Arduino IDE settings• Arduino board: Arduino/Gemuino Uno• Port: Depends on your machine

• Click “Upload” button (2nd from left)• Understand source code

• Onboard LED blinks at 1 second intervals

Exercise objectives:1. Use an example2. Understand Arduino

code format3. Concept of pins4. Output to pin5. Upload code

Page 10: Introduction to Arduino

Create new Arduino file1. Create folder on desktop2. File -> New3. Name program filename same as folder name• Example: myblinker.ino

Page 11: Introduction to Arduino

Ex 2: Blink external LED

• 220ohm resistor is to prevent too much current from flowing -> Damage LED

• Arduino IDE instructions1. Copy-paste Blink example to your

new file2. Change Pin number 13 > 12

Exercise objectives:1. Basic wiring up of breadboard2. Creating your own Arduino sketch

Page 12: Introduction to Arduino

Ex 3: Button adjusts LED state

• We will now try to toggle the LED whenever button is pressed

• 10k ohm pull-down resistor • Ensures button pin is LOW when button is not

pressed -> Not floating• Prevents short circuit when button is pressed

• Execute the code in Ex3• Does the LED toggle as expected?• Why?

Exercise objectives:1. Retrieving input2. Prevent floating pin3. If-else branching

Page 13: Introduction to Arduino

Ex 4: Debouncing• Now lets try some code to solve this problem

Exercise objectives:1. Long datatype2. Debouncing3. millis() function4. Use of &&

• Debouncing: • Accept only one input within

certain time period

Page 14: Introduction to Arduino

Ex 5: Blink LED 3x on button press• Blink LED 3x with blink separation of 100ms

Exercise objectives:1. For - loop

Page 15: Introduction to Arduino

Ex 6: Serial Port Debugging

• Useful debugging tool

• Let’s print out something when button is pressed• Print the steps. • Good practice to print “Arduino Ready” at end of setup()

• Tools -> Serial Monitor• Ensure baud rate eg. 9600 match what you place in code

Exercise objectives:1. Print Data over Serial