Build cool stuff with arduino for sci camp 16 dec13

Post on 14-May-2015

377 views 4 download

Tags:

description

Slides for Arduino workshop for Science Camp 2013

transcript

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

What are microcontrollers?

• Really small computers

• With limited hardware resources

• Programmable

• Can be used to do anything imaginable

Fukushima nuclear

disaster

Doing good for humanity

DIY radiation detector built by Tokyo

Hackerspace, connected live to the Internet

Arduino as an Interative Device

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

Using the breadboard

Horizontal tracks for power

vertical tracks for components

Connecting circuit

Program structure

void setup( ) { }

void loop( ) { }

Arduino use a

language similar to

C++

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

Reading from serial monitor

Serial monitor Verify Upload

Activity 1: Blink an LED

330

longer leg

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

Recap

pinMode (pin number, OUTPUT/INPUT);

digitalWrite(pin number, HIGH/LOW);

delay(milliseconds);

Activity 2: ..and beep a buzzer

330

Piezo

buzzer

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

Use arrays for longer tunes

Challenge

Build a circuit and write the Arduino

sketch that will enable you to blink 4

LEDs intermittently & play a musical

tone

Controlling RGB

Activity 4: Light sensing

adafruit.com

Activity 4: Display light reading – Serial

Controlling servo motor

GND pin 0 +5V

Activity 5: Controlling servo motor

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

Recap

#include <Servo.h>

Servo myservo;

myservo.attach (pin number);

myservo.write (angle);

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>

Replace pot with light sensor

10k

10k

Ideas for projects

Thank you facebook.com/CRADLEsci