bionic arduino class3

Upload: sachin-bhat

Post on 05-Apr-2018

228 views

Category:

Documents


1 download

TRANSCRIPT

  • 8/2/2019 Bionic Arduino Class3

    1/46

    Bionic Arduino

    Introduction to Microcontrollers with Arduino

    Class 3

    18 Nov 2007 - machineproject - Tod E. Kurt

  • 8/2/2019 Bionic Arduino Class3

    2/46

  • 8/2/2019 Bionic Arduino Class3

    3/46

    compile

    upload

    sketch runs

    TX/RX flashLoad File/Sketchbook/Examples/Digital/Blink

    Recap: Blinky LEDMake sure things still work

    Change the delay() values to change blink rate

  • 8/2/2019 Bionic Arduino Class3

    4/46

    Class Kit 2 Contentsmotors & motion

  • 8/2/2019 Bionic Arduino Class3

    5/46

    Class Kit 2 Manifest

    Nintendo Wii Nunchuck

    Wii Nunchuck Adapter Large DC motor

    Small DC motor

    Small servo motor

    TIP120 power transistor

    1N4001 power diode

    Several 500 ohm resistors(green-brown-brown)

    Couple of popsicle sticks

    Colorful pipe cleaners

    motors & motion

  • 8/2/2019 Bionic Arduino Class3

    6/46

    DC Motors

    come in allshapes and sizes

    You probably have3-4 on you right now

    (cell vibrate, laptop fan, laptop dvd drive)

    the two motorsin the kit

    When motors first came out, people thought wed just have one for the house. The householdmotor. Various attachments for vacuuming, meat grinding, ceiling fan were available, and somehouses had intricate mazes of belts and gears routed through the house to supply this rotationalpower.

  • 8/2/2019 Bionic Arduino Class3

    7/46

    DC Motors

    direct-drive vs. gearhead built-in gears or not voltage what voltage it best operates at current (efficiency) how much current it needs to spin

    speed how fast it spins

    torque how strong it spins oh, and also: size, shaft diameter, shaft length,etc.

    A dizzying array of parameters specify a motor

    The two motors you have are small direct-drive,high-efficiency motors that work at 5 volts

    Gearhead motors are the best.

  • 8/2/2019 Bionic Arduino Class3

    8/46

    DC Motors

    Characteristics When the first start up, they draw a lot more

    current, up to 10x more.

    If you stall them (make it so they cantturn), they also draw a lot of current

    They can operate in either direction, byswitching voltage polarity

    Usually spin very fast: >1000 RPM To get slower spinning, need gearing

  • 8/2/2019 Bionic Arduino Class3

    9/46

    DC Motors

    MDC motorbattery

    polarity determines which way it rotates

    To drive them, apply a voltageThe higher the voltage, the faster the spinning

    Try this out real quick.Then swap polarity

    Dont let it go to long. These motors will work at 9V for awhile, but arent made to continuously runat that voltage.

  • 8/2/2019 Bionic Arduino Class3

    10/46

  • 8/2/2019 Bionic Arduino Class3

    11/46

    Transistors

    TIP120

    TIP120

    base

    collector emitter

    base

    collector

    emitter

    Act like switches

    Turning on the base connects the collector & emitter together

    schematic symbol

    electricity flicks the switch instead of your finger

    collector

    emitter

    base

    how it kind of works

    The dierences between the pins are very important. The names arent that important, but theirfunctions are. The base is the input that you use to open and close the switch across thecollector and emitter. On this type of transistor (called an NPN), you need to make sure thecollector is always more positive than the emitter. Generally you do this by connecting the emitterto ground.

  • 8/2/2019 Bionic Arduino Class3

    12/46

    Switching Motors with

    Transistors

    M

    DC motor

    transistorresistor

    battery

    + switch

    MDC motor

    transistorresistor

    + switch

    +

    +

    +

    big powersource

    transistors switch big signals with little signals

    little motor big motor

    switching a different power source

  • 8/2/2019 Bionic Arduino Class3

    13/46

  • 8/2/2019 Bionic Arduino Class3

    14/46

    Controlling a Motor

    Arduino

    board

    gnd

    pin 9

    +5V

    +5V

    M

    DC motor

    TIP120500

    1N4001

    (green-brown-brown)

    Can control speed of motor with analogWrite()just like controlling brightness of LED

    start with the tiny motorbce

    bc

    e

    motor

    Why 500 ohms? Because I have a lot of 500 ohm resistors. Typically you see 1k ohms. Anything 1kor below will work. The lower the value, the more current youre wasting to turn on the transistor.

  • 8/2/2019 Bionic Arduino Class3

    15/46

    Wiring up Motor Circuit

    transistorturnedaround tomake wiringeasier

    white diode line into +5Vmotor across diode

    Arduinoboard

    gnd

    pin 9

    +5V

    +5V

    M

    DC motor

    TIP120500

    1N4001

    (green-brown-brown)

    e bc

    b c

    e

  • 8/2/2019 Bionic Arduino Class3

    16/46

    SketchSerialMotorSpeed

    Type a number 0-9in Serial Monitor tocontrol the speed of

    the motor

    How would you change thisto control the motor speed

    with the potentiometer?

  • 8/2/2019 Bionic Arduino Class3

    17/46

    Controlling a Bigger Motor

    Arduinoboard

    gnd

    pin 9

    +5V

    +5V

    M

    DC motor

    TIP120500

    1N4001

    (green-brown-brown)

    +9V battery

    Same circuit as before, different voltage source

    Motor will spin faster for a given analogWrite() value

    9Vbattery

    motor w/ tapepropellor

    desk ding frommotor getting loose

    Actually with both of the motors you have, you can run o the Arduino power supply. But manymotors cannot because they either draw too much current or they need a voltage higher than 5volts.

  • 8/2/2019 Bionic Arduino Class3

    18/46

    Fun Motor Attachments

    tape propellerpipe cleaner squiggler popsicle stick beaterIm terrible at mechanical engineering. If anyone has good ways of mounting things to motors, letme know. :-)

  • 8/2/2019 Bionic Arduino Class3

    19/46

    Wiring Up Bigger Motor

    Dont just add 9V to +5v bus!Move the diode from +5 to another rowAdd red 9V wire to that row,

    Add black 9V wire to Gnd

    You might find it easier to push the red 9V wire in with the motor wire.

  • 8/2/2019 Bionic Arduino Class3

    20/46

    Can Switch Anything*

    Arduinoboard

    pin 7

    gnd

    1k

    TIP120

    1N4004

    +5V

    to load

    5V relay

    Just on/off, and a relay needs a diode too

    to load: light bulb, car ignition, washing machine, etc.

    Super bright LED light

    Arduinoboard

    gnd

    pin 9

    +12V+5V

    TIP120

    1k

    red LEDs

    120

    Relay switcher

    *Anything up to about 1 amp. Need a bigger transistor or a relay after that

    Full brightness control with PWM

  • 8/2/2019 Bionic Arduino Class3

    21/46

  • 8/2/2019 Bionic Arduino Class3

    22/46

    Piezo Knock Sensor

    To read a piezo you canjust hook it into ananalog input, but:

    You need to drain offany voltage with aresistor, or it just buildsup

    The protection diodesinside the AVR chipprotect against the highvoltage

    piezo input schematic

    Arduino

    board

    analog pin 2

    gnd

    +

    piezobuzzer

    1M

    (brown,

    black,green)

    Note polarity of piezo still matters.If youre doing this for real, youd probably want to add an external protection diode, called a zenerdiode. It acts invisible until the voltage gets over its designed value (like 5 volts in this case), thenit acts like a short circuit.

  • 8/2/2019 Bionic Arduino Class3

    23/46

  • 8/2/2019 Bionic Arduino Class3

    24/46

    Piezo Knock

    PiezoKnock

    Whack the piezo toprint out a numberbased on force of

    whack

    Waits for input to go over threshold,then to drop below threshold

    Number is t, the number of times it looped waiting for the value to drop below THRESHOLD.Notice how it doesnt work quite right.

  • 8/2/2019 Bionic Arduino Class3

    25/46

  • 8/2/2019 Bionic Arduino Class3

    26/46

  • 8/2/2019 Bionic Arduino Class3

    27/46

    Could make a MIDI Trigger

    Uses piezos & buttonsto send MIDI messages

    Can trigger drum soundsor arbitrary sound samples

    MIDIoutput

    buttons

    piezos

    I used this during Halloween a few years ago to trigger scary sounds.

  • 8/2/2019 Bionic Arduino Class3

    28/46

    Or Trigger Actuators

    Arduinoboard

    analog pin 2

    gnd

    +

    piezobuzzer

    1M

    (brown,

    black,green)

    pin 9

    +5V

    M

    DC motor

    TIP120500

    1N4001

    (green,

    brown,brown)

    If you still have yourmotor wired up

    PiezoMotorPulse

  • 8/2/2019 Bionic Arduino Class3

    29/46

  • 8/2/2019 Bionic Arduino Class3

    30/46

  • 8/2/2019 Bionic Arduino Class3

    31/46

  • 8/2/2019 Bionic Arduino Class3

    32/46

  • 8/2/2019 Bionic Arduino Class3

    33/46

  • 8/2/2019 Bionic Arduino Class3

    34/46

    Processing & Arduino

    Processing and Arduino both talk to serialdevices like the Arduino board

    Only one program per serial port So turn off Arduinos Serial Monitor when connecting

    via Processing and vice-versa.

    Processing has a Serial library to talk toArduino. E.g.:

    serial communications

    port = new Serial(..,my_port_name,19200)

    port.read(), port.write(), port.available(), etc.

    serialEvent() { }

    The built-in serial library adds a new function you can use to your sketch: serialEvent()The serialEvent() function will get called whenever serial data is available.Or you can poll with port.available().

  • 8/2/2019 Bionic Arduino Class3

    35/46

  • 8/2/2019 Bionic Arduino Class3

    36/46

  • 8/2/2019 Bionic Arduino Class3

    37/46

    Processing + Arduino

    ArduinoReadCircle

    The pot controlsthe hue of theonscreen circle

    Arduino is running PotSend,repeatedly sending a number from

    0-255 indicating knob position

    This sketch is in the handout, under processing_sketches.

  • 8/2/2019 Bionic Arduino Class3

    38/46

  • 8/2/2019 Bionic Arduino Class3

    39/46

    T S d

  • 8/2/2019 Bionic Arduino Class3

    40/46

    Triggering Sounds

    ArduinoSounds

    Every time thepiezo is knocked...a sound plays anda red disc appears

    onscreen

    This sketch needs theminim sound library.

    You can add your own sounds (WAV or MP3)Hook a piezo up to your front door, and plug your computer into your stereo.Every time someone knocks on your door, a sound is played: a custom doorbell!

    The zipfile for the minim library is in the handout, called minim-1.1-lib.zip.Unzip it and place the minim folder in the Processing 0133/libraries folder.

    Addi P i Lib i

  • 8/2/2019 Bionic Arduino Class3

    41/46

    Adding Processing LibrariesUnzip, drop into libraries folder

    drag

    unzip open

    Same for Windows and Mac OS X. Mac OS X shown.

  • 8/2/2019 Bionic Arduino Class3

    42/46

  • 8/2/2019 Bionic Arduino Class3

    43/46

    G i F th

  • 8/2/2019 Bionic Arduino Class3

    44/46

    Going Further

    Transistor switches

    Anytime you need to switch a signal more

    powerful than what Arduino can use

    These transistors switch up to 1 amp of DCvoltage. For AC household currents, use

    transistor to switch a relay

    Can control just about anything in your house

    G i F th

  • 8/2/2019 Bionic Arduino Class3

    45/46

    Going Further

    Processing & Serial communications

    Processing can talk to the Net. Its an

    Internet-to-Arduino gateway

    It can also talk to many computerperipherals, like video cameras

    Maybe: Arduino controls the motors,laptop controls the cameras of your robot

  • 8/2/2019 Bionic Arduino Class3

    46/46

    Tod E. Kurt

    [email protected]

    END Class 3

    http://todbot.com/blog/bionicarduino/

    Feel free to email me if you have any questions.

    mailto:[email protected]:[email protected]:[email protected]:[email protected]