ARDUINO FOR BEGINNERS Smitha Pisupati and Sushma Rao Apr 26 2015 - - PowerPoint PPT Presentation

arduino for beginners
SMART_READER_LITE
LIVE PREVIEW

ARDUINO FOR BEGINNERS Smitha Pisupati and Sushma Rao Apr 26 2015 - - PowerPoint PPT Presentation

ARDUINO FOR BEGINNERS Smitha Pisupati and Sushma Rao Apr 26 2015 What is Arduino An open source electronics platform Easy to use HW and SW Make interactive projects No electronics background required The HW Arduino


slide-1
SLIDE 1

ARDUINO FOR BEGINNERS

Smitha Pisupati and Sushma Rao Apr 26 2015

slide-2
SLIDE 2

What is Arduino

¨ An open source electronics platform ¨ Easy to use HW and SW ¨ Make interactive projects ¨ No electronics background required

slide-3
SLIDE 3

The HW – Arduino UNO

slide-4
SLIDE 4

The Hardware

slide-5
SLIDE 5

The Software

Download: http://arduino.cc/en/Main/Software

slide-6
SLIDE 6

Blink an LED

slide-7
SLIDE 7

Blink an LED

¨ Connect the Arduino to the PC/Mac ¨ Open the Blink example

File -> Examples -> 01.Basics -> Blink

¨ Upload!

slide-8
SLIDE 8

Let’s look at the code

slide-9
SLIDE 9
slide-10
SLIDE 10
slide-11
SLIDE 11
slide-12
SLIDE 12

Hey Arduino, Run this part when you power up! Hey Arduino, Run this part over and over, forever!

slide-13
SLIDE 13

Set Pin 13 to

  • utput

Set Pin 13 to HIGH Set Pin 13 to LOW Wait 1 second Wait 1 second

slide-14
SLIDE 14

Digital Output

Connect an External LED

slide-15
SLIDE 15

Breadboard

http://www.crifan.com/arduino_and_bread_board/

Connections in the breadboard Breadboard Internals

slide-16
SLIDE 16

External LED

slide-17
SLIDE 17

What makes the LED glow?

slide-18
SLIDE 18

Electricity!

slide-19
SLIDE 19

Electricity!

slide-20
SLIDE 20

Resistor

¨ Limits amount of charge flowing through the circuit ¨ Has a “resistance” ¨ Higher the resistance,

lower the amount of charge flow

slide-21
SLIDE 21

Schematic

¨ Circuit diagram ¨ Uses symbols for electronic components

slide-22
SLIDE 22

Analog Sensor

Control the Blink Rate

slide-23
SLIDE 23

Meet the Potentiometer

¨ A.K.A The Pot ¨ Variable resistor

slide-24
SLIDE 24

How does it work?

¨ Voltage divider ¨ Voltage at A0 is

a fraction of 5V DC

slide-25
SLIDE 25

Adding a potentiometer

slide-26
SLIDE 26

Changes to Blink code

¨ In the loop function, add the following line:

int delayVal = analogRead(A0);

¨ Change delay(1000) to the following:

delay(delayVal); // delayVal will be a number between 0 and 1023.

slide-27
SLIDE 27

Adding serial debug

slide-28
SLIDE 28

Add Serial Debug

¨ Add the following line to the setup() function

Serial. Serial.begin(9600);

¨ Add the following line to the loop() function

Serial.println(delayVal);

slide-29
SLIDE 29

Serial Monitor

¨

More details at http://www.arduino.cc/en/Reference/Serial

slide-30
SLIDE 30

Digital Sensor

Ultrasonic Distance Sensor

slide-31
SLIDE 31

Ultrasonic distance sensor

¨ 4 pins

¤ VCC ¤ GND ¤ Trigger ¤ Echo

slide-32
SLIDE 32
slide-33
SLIDE 33

Reading Values from the Sensor

¨

Add the following at the top of the file

unsigned long distanceInCm = 0;

¨

Add the following lines of code in the setup() function

pinMode (trigger, OUTPUT); pinMode(echo, INPUT);

¨

Add the following in the loop() function

// Hold trigger pin high for 10 microseconds digitalWrite(trigger, HIGH); delayMicroseconds(10); digitalWrite(trigger, LOW); // Get the width of the pulse with pulseIn count = pulseIn(echo, HIGH); // get distance in cm. Divide by 148 for inches distanceInCm = count / 58;

slide-34
SLIDE 34

Glowing the LED

¨ Add the following at the top of the file

int ledPin = 13;

¨ Add the following lines of code in the setup() function

pinMode(ledPin, OUTPUT);

¨ Add the following in the loop() function

if(distanceInCm < 10) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); }

slide-35
SLIDE 35

Finally…

¨ Add the following at the end of the

loop

count = 0; // add a delay for stable behaviour delay(200);

slide-36
SLIDE 36

Building the Theremin

slide-37
SLIDE 37
slide-38
SLIDE 38

Let’s Code It

slide-39
SLIDE 39

Repeat the LED code 6 more times

¨ Add the following at the top of the file

int ledPin1 = 13; int ledPin2 = 12; int ledPin3 = 11; …

slide-40
SLIDE 40

Repeat the LED code 6 more times

¨ Add the following lines of code in the setup()

function

pinMode(ledPin1, OUTPUT); pinMode(ledPin2, OUTPUT); pinMode(ledPin3, OUTPUT); …

slide-41
SLIDE 41

Repeat the LED code 6 more times

¨ Add the following in the loop() function

if(distanceInCm < 10) { digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, HIGH); digitalWrite(ledPin3, HIGH); … } else { digitalWrite(ledPin1, LOW); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); … }

slide-42
SLIDE 42

Test It!

¨ Upload and check that this works…

slide-43
SLIDE 43

Adding an else-if

if(distanceInCm < 10) { digitalWrite(ledPin1, HIGH); … } else if (distanceInCm < 12) { digitalWrite(ledPin1, HIGH); digitalWrite(ledPin2, LOW); digitalWrite(ledPin3, LOW); … } else { digitalWrite(ledPin1, LOW); … }

slide-44
SLIDE 44

Notes to play

¨ link to source ¨ Copy the top part of the file that looks like this:

#define NOTE_B0 31 #define NOTE_C1 33 #define NOTE_CS1 35 #define NOTE_D1 37 #define NOTE_DS1 39 #define NOTE_E1 41 #define NOTE_F1 44 #define NOTE_FS1 46 #define NOTE_G1 49

slide-45
SLIDE 45

Adding the tone

¨ Connect the Piezo buzzer at pin 5 ¨ Add this line to the top of the file

int piezo = 5;

¨ Add this to the setup() function

pinMode(piezo, OUTPUT);

¨ Add this to the loop() function

// To play the tone tone(piezo,<NOTE>); // to stop the tone noTone(piezo);

slide-46
SLIDE 46

Make Music!

slide-47
SLIDE 47

References

¨ http://www.arduino.cc/en/Reference/Tone ¨ http://www.arduino.cc/en/Tutorial/HomePage