+ All Categories
Home > Documents > Introduction to · These devices need more current than the Arduino can supply. They might need...

Introduction to · These devices need more current than the Arduino can supply. They might need...

Date post: 11-Jul-2020
Category:
Upload: others
View: 0 times
Download: 0 times
Share this document with a friend
33
Guest wifi: HSNOTTS-guest Password: hackspacebiscuits Presentation: http://wiki.nottinghack.co.uk/wiki/Arduino101 Software: http://arduino.cc/en/Main/Software Introduction to How to use electronics to make your projects better!
Transcript
Page 1: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

Guest wifi: HSNOTTS-guest Password: hackspacebiscuitsPresentation: http://wiki.nottinghack.co.uk/wiki/Arduino101Software: http://arduino.cc/en/Main/Software

Introduction to

How to use electronics to make your projects better!

Page 2: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 2

Welcome!

● Let's get programming!

● What did we just do? What is an “Arduino”

anyway?

● Serial communications (making your Arduino talk

to your laptop)

● Electrical Basics: Voltage, current, resistance

● More blinking LEDs

● Using switches

Page 3: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 3

Welcome!

● Lunch?● Structure and Decisions: Order out of chaos● Your Arduino is a wimp: giving it some muscle!● Life isn't digital: reading real-world values● Putting it all together

Page 4: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 4

Dive in: Blink an LED

Code Along #1

Page 5: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 5

What just happened?

The Arduino IDE is a text editor combined with programming tools.

Page 6: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 6

ArduinoSoftware

Tools

What just happened?

Your code

The Arduino code library

Binary file

...0100100100110010000111001110...

When you press the “Upload” button, your code is combined with the Arduino library and made into a file that the Arduino microcontroller is programmed with.

Page 7: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 7

What just happened?

… and then gets sent down the USB cable to the Arduino. Once there, it stays there until you re-program it, even if the power is removed.

Binary file

...0100100100110010000111001110...

USB

Page 8: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 8

Serial Monitor

Code Along #2

Page 9: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 9

Variables

Code Along #3

Page 10: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 10

Variables

Named places to store your data

int loop_counter = 0;

loop_counter

0

Page 11: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 11

Variables

loop_counter = loop_counter + 1;

0

loop_counter = 0 + 1;loop_counter = 1 ;

1

Page 12: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 12

Variables

loop_counter = loop_counter + 1;

1

loop_counter = 1 + 1;loop_counter = 2 ;

2

Page 13: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 13

Variables: Size and Limits

char Character 'a', 'b', 'c'... or -128 to 127 1 byte

unsigned char 0 to 255 1 byte

int -32768 to 32767 2 bytes

unsigned int 0 to 65535 2 bytes

bool true or false 1 bytes

String String hello = “Hello!”; ???

Page 14: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 14

The Arduino Uno

USB

Power 7-12V dc

Digital pins

Analog inputs

Reset button

Microcontroller

Power pins

USB interface

Voltage regulator

LED (pin 13)

Power LED

Page 15: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 15

Breadboard

Page 16: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 16

Using other components

Page 17: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 17

Voltage, Current, Resistance

Pressure

FlowSqueezing

Return path (the water cycle!)

Page 18: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 18

Another blinking LED

Change your breadboard circuit as shown.

Code Along #4

Page 19: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 19

Tactile Switch

Page 20: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 20

Switch controlling LED

Change your breadboard circuit as shown.

Code Along #5

Page 21: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 21

High Power Loads

● These devices need more current than the Arduino can supply.

● They might need more voltage too.● We use a transistor to increase the current and/or voltage.● Transistor acts as a Arduino controlled switch.● Need protection from inductive loads (usually wound coils

such as motors and relays).● NPN Bipolar and N-channel MOSFET are commonly

used with the Arduino.

Page 22: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 22

N-Channel MOSFET

Page 23: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 23

Motor Control

Change your breadboard circuit as shown.

Code Along #6

Page 24: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 24

Pulse Width Modulation

e

● Not available on all pins! On the Uno, pins 3, 5, 6, 9, 10, 11 can be used

● Use analogWrite(pin, value), where value is between 0 and 255

● Gives motors torque AND speed control!

Page 25: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 25

Reading real-world signals

● Arduino has 6 analog inputs● Read with:

– int value = analogRead(pin);

– Pin is 0-5 or A0-A5

– Value from 0 to 1023 representing voltage of 0-5V

Page 26: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 26

Change your breadboard circuit as shown.

Code Along #7

Potentiometer(Variable Resistor)

Page 27: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 27

Doing more than one thing

Code Along #8

Page 28: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 28

Functions

FunctionInput Output

Named blocks of code that perform a particular job

● Arduino library provides loads of them for you.● Using a function is known as “calling” or “invoking” it.● loop and setup are functions in your sketch.● You can write your own!

e.g.digitalWrite (inputs, no output)digitalRead (inputs and output)loop, setup (no input or output)

Functions may have inputs and outputs.

Page 29: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 29

Change your breadboard circuit as shown.

Light DependantResistor

Page 30: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 30

Doing more than one thing

Code Along #8

Page 31: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 31

Functions

FunctionInput Output

Named blocks of code that perform a particular job

● Arduino library provides loads of them for you.● Using a function is known as “calling” or “invoking” it.● loop and setup are functions in your sketch.● You can write your own!

e.g.digitalWrite (inputs, no output)digitalRead (inputs and output)loop, setup (no input or output)

Functions may have inputs and outputs.

Page 32: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 32

Functions

Code Along #9

Page 33: Introduction to · These devices need more current than the Arduino can supply. They might need more voltage too. We use a transistor to increase the current and/or voltage. Transistor

http://wiki.nottinghack.co.uk/wiki/Arduino101 33

That's It!

@hsnotts@fowkc

@iandickinson


Recommended