29
Build cool stuff with Arduino Introductory Workshop 13 Dec 2013 William Hooi Wendell Wong Centre for Research & Applied Learning in Sciences Science Centre Singapore facebook.com/CRADLEsci

Build cool stuff with arduino for sci camp 16 dec13

Embed Size (px)

DESCRIPTION

Slides for Arduino workshop for Science Camp 2013

Citation preview

Page 1: Build cool stuff with arduino for sci camp 16 dec13

Build cool stuff with Arduino

Introductory Workshop

13 Dec 2013

William Hooi Wendell Wong

Centre for Research & Applied Learning in Sciences

Science Centre Singapore

facebook.com/CRADLEsci

Page 2: Build cool stuff with arduino for sci camp 16 dec13

What are microcontrollers?

• Really small computers

• With limited hardware resources

• Programmable

• Can be used to do anything imaginable

Page 3: Build cool stuff with arduino for sci camp 16 dec13

Fukushima nuclear

disaster

Doing good for humanity

DIY radiation detector built by Tokyo

Hackerspace, connected live to the Internet

Page 4: Build cool stuff with arduino for sci camp 16 dec13

Arduino as an Interative Device

Page 5: Build cool stuff with arduino for sci camp 16 dec13

Terminology

• Pins

– A leg on a microcontroller with some specific function (e.g. Power pin, ground pin, digital input pin, analog output pin)

Digital pins

Analog pins

Arduino has 13 digital pins that can be used as input or output

Arduino has 6 analog pins that can only be used as input

Page 6: Build cool stuff with arduino for sci camp 16 dec13

Using the breadboard

Horizontal tracks for power

vertical tracks for components

Page 7: Build cool stuff with arduino for sci camp 16 dec13

Connecting circuit

Page 8: Build cool stuff with arduino for sci camp 16 dec13

Program structure

void setup( ) { }

void loop( ) { }

Arduino use a

language similar to

C++

Page 9: Build cool stuff with arduino for sci camp 16 dec13

Where to start

Determine your

input

Input device:

Choose a device

Output device:

Determine your

output and device

Light

emitting

diode (LED)

Light-

dependent

resistor

(LDR)

Piezo

buzzer

Page 10: Build cool stuff with arduino for sci camp 16 dec13

Reading from serial monitor

Serial monitor Verify Upload

Page 11: Build cool stuff with arduino for sci camp 16 dec13

Activity 1: Blink an LED

330

longer leg

Page 12: Build cool stuff with arduino for sci camp 16 dec13

Activity 1: Blink an LED

Assign pin 13 as LED pin

Assign LED pin as output

Turn LED pin on

Wait for 0.5s

Turn Led pin off

Wait for 0.5s

Page 13: Build cool stuff with arduino for sci camp 16 dec13

Recap

pinMode (pin number, OUTPUT/INPUT);

digitalWrite(pin number, HIGH/LOW);

delay(milliseconds);

Page 14: Build cool stuff with arduino for sci camp 16 dec13

Activity 2: ..and beep a buzzer

330

Piezo

buzzer

Page 15: Build cool stuff with arduino for sci camp 16 dec13

Activity 2: ..and beep a buzzer

Assign pin 8 as tone pin

Play a tone on tone pin with 200 Hz and 250ms

Play a tone on tone pin with 600 Hz and 250ms

Page 16: Build cool stuff with arduino for sci camp 16 dec13

Use arrays for longer tunes

Page 17: Build cool stuff with arduino for sci camp 16 dec13

Challenge

Build a circuit and write the Arduino

sketch that will enable you to blink 4

LEDs intermittently & play a musical

tone

Page 18: Build cool stuff with arduino for sci camp 16 dec13

Controlling RGB

Page 19: Build cool stuff with arduino for sci camp 16 dec13

Activity 4: Light sensing

adafruit.com

Page 20: Build cool stuff with arduino for sci camp 16 dec13

Activity 4: Display light reading – Serial

Page 21: Build cool stuff with arduino for sci camp 16 dec13

Controlling servo motor

Page 22: Build cool stuff with arduino for sci camp 16 dec13

GND pin 0 +5V

Activity 5: Controlling servo motor

Page 23: Build cool stuff with arduino for sci camp 16 dec13

Control servo with trimmer pot #include <Servo.h>

Page 24: Build cool stuff with arduino for sci camp 16 dec13

Recap

#include <Servo.h>

Servo myservo;

myservo.attach (pin number);

myservo.write (angle);

Page 25: Build cool stuff with arduino for sci camp 16 dec13

Reading from serial monitor

create a servo object called ‘myservo’

Start serial comm at 9600bps

Assign servo to servo pin 9

Read analog pin 0, pass value to potLevel

Convert range to 180 divisions

Display something on serial monitor

Tell servo to rotate

#include <Servo.h>

Page 26: Build cool stuff with arduino for sci camp 16 dec13

Replace pot with light sensor

10k

Page 27: Build cool stuff with arduino for sci camp 16 dec13

10k

Page 28: Build cool stuff with arduino for sci camp 16 dec13

Ideas for projects

Page 29: Build cool stuff with arduino for sci camp 16 dec13

Thank you facebook.com/CRADLEsci