arduino 入门版使用教程 - dfrobot.com.cn start kit manual... · 常有趣例子 程序。 ......

Download Arduino 入门版使用教程 - dfrobot.com.cn Start kit Manual... · 常有趣例子 程序。 ... 过把相一些参数设置都凼数化,用我去了览他底层,让我了览

If you can't read please download the document

Upload: truongbao

Post on 23-May-2018

216 views

Category:

Documents


2 download

TRANSCRIPT

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 1 91

    Arduino

    www.DFRobot.com.cn

    :V 0.23

    2010 09 1 3

    www.DFRobot.com.cn

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 2 91

    ......................................................................................................................................................... 3

    ............................................................................................................................................. 3

    Arduino .................................................................................................................................... 4

    ................................................................................................................................................... 4

    Arduino C ............................................................................................................................. 5

    ..................................................................................................................................................... 8

    ..................................................................................................................................................... 8

    Arduino ............................................................................................................................... 10

    ................................................................................................................................... 29

    ................................................................................................................................................... 31

    led ................................................................................................................. 31

    ......................................................................................................................... 42

    ......................................................................................................................... 47

    ............................................................................................................................. 54

    ..................................................................................................................... 64

    ................................................................................................................... 67

    ................................................................................................................... 70

    ......................................................................................................................... 74

    ..................................................................................................................... 79

    ............................................................................................................................. 83

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 3 91

    Arduino

    Arduino

    Arduino

    Arduino 328 1

    1

    1

    LED 2

    1

    4

    1

    1

    1

    1

    220 1K 10K 3

    LM35 1

    USB 1

    20

    6 5 1

    mini 1

    Arduino 1

    1

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 4 91

    Arduino

    Arduino

    Arduino Simple i/o

    Arduino Arduino

    LED

    Arduino

    !!

    LED

    (ATMEGA328)

    Digital I/O / 0~13

    Analog I/O / 0~5

    ISP

    USB 5V~ 9V

    5V 3.3V

    Atmel Atmega 328

    Arduino 70mm X 54mm

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 5 91

    Arduino C

    Arduino C/C++ C Arduino

    AVR

    Arduino

    if

    if...else

    for

    switch case

    while

    do... while

    break

    continue

    return

    goto

    ;

    {}

    //

    /* */

    =

    +

    -

    *

    /

    %

    ==

    !=

    http://arduino.cc/en/Reference/Ifhttp://arduino.cc/en/Reference/Elsehttp://arduino.cc/en/Reference/Forhttp://arduino.cc/en/Reference/SwitchCasehttp://arduino.cc/en/Reference/Whilehttp://arduino.cc/en/Reference/DoWhilehttp://arduino.cc/en/Reference/Breakhttp://arduino.cc/en/Reference/Continuehttp://arduino.cc/en/Reference/Returnhttp://arduino.cc/en/Reference/Gotohttp://arduino.cc/en/Reference/SemiColonhttp://arduino.cc/en/Reference/Braceshttp://arduino.cc/en/Reference/Commentshttp://arduino.cc/en/Reference/Commentshttp://arduino.cc/en/Reference/Ifhttp://arduino.cc/en/Reference/If

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 6 91

    <

    >

    =

    &&

    ||

    !

    ++

    --

    +=

    -=

    *=

    /=

    boolean

    char

    byte

    int

    unsigned int

    long

    unsigned long

    float

    double

    string

    array

    void

    HIGH | LOW IO HIGH 1 LOW 0

    INPUT | OUTPUT IO INPUT OUTPUT

    AVR 5V 40mA

    http://arduino.cc/en/Reference/Ifhttp://arduino.cc/en/Reference/Ifhttp://arduino.cc/en/Reference/Ifhttp://arduino.cc/en/Reference/Ifhttp://arduino.cc/en/Reference/Booleanhttp://arduino.cc/en/Reference/Booleanhttp://arduino.cc/en/Reference/Booleanhttp://arduino.cc/en/Reference/Incrementhttp://arduino.cc/en/Reference/Incrementhttp://arduino.cc/en/Reference/IncrementCompoundhttp://arduino.cc/en/Reference/IncrementCompoundhttp://arduino.cc/en/Reference/IncrementCompoundhttp://arduino.cc/en/Reference/IncrementCompoundhttp://arduino.cc/en/Reference/BooleanVariableshttp://arduino.cc/en/Reference/Charhttp://arduino.cc/en/Reference/Bytehttp://arduino.cc/en/Reference/Inthttp://arduino.cc/en/Reference/UnsignedInthttp://arduino.cc/en/Reference/Longhttp://arduino.cc/en/Reference/UnsignedLonghttp://arduino.cc/en/Reference/Floathttp://arduino.cc/en/Reference/Doublehttp://arduino.cc/en/Reference/Stringhttp://arduino.cc/en/Reference/Arrayhttp://arduino.cc/en/Reference/Voidhttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constants

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 7 91

    true | false true 1 false 0

    c

    http://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constantshttp://arduino.cc/en/Reference/Constants

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 8 91

    void setup ()

    void loop ()

    I/O

    pinMode (pin, mode) IO pin 0 13 mode

    INPUT OUTPUT

    digitalWrite (pin, value) IO pin 0 13 value

    HIGH LOW HIGH LED

    int digitalRead (pin) IO pin 0 13 value HI

    GH LOW

    I/O

    int analogRead (pin) IO pin 0 5 Arduino Diecimila 0 5

    Arduino nano 0 7 10 AD 0 5V 0 1023

    analogWrite (pin, value) - PWM IO PWM Arduino IO

    PWM IO pin 3, 5, 6, 9, 10, 11 value 0 255

    PWM

    delay (ms) ms

    dela yMicroseconds (us) us

    http://arduino.cc/en/Reference/Setuphttp://arduino.cc/en/Reference/Loophttp://arduino.cc/en/Reference/PinModehttp://arduino.cc/en/Reference/DigitalWritehttp://arduino.cc/en/Reference/DigitalReadhttp://arduino.cc/en/Reference/AnalogReadhttp://arduino.cc/en/Reference/AnalogWritehttp://arduino.cc/en/Reference/Delayhttp://arduino.cc/en/Reference/DelayMicroseconds

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 9 91

    min (x, y)

    max(x, y)

    abs(x)

    constrain (x, a, b) a b x ab

    map (value, fromLow, fromHigh, toLow, toHigh) value fromLow

    toLow fromHigh toHigh

    pow (base, exponent) base exponent

    sq(x)

    sqrt (x)

    http://arduino.cc/en/Reference/Minhttp://arduino.cc/en/Reference/Maxhttp://arduino.cc/en/Reference/Abshttp://arduino.cc/en/Reference/Constrainhttp://arduino.cc/en/Reference/Maphttp://arduino.cc/en/Reference/Powhttp://arduino.cc/en/Reference/Sqhttp://arduino.cc/en/Reference/Sqrt

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 10 91

    Arduino

    1 Arduino

    Prototype shield

    1

    2

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 11 91

    Prototype shield

    3

    Arduino 328

    4

    Prototype shield Arduino 328

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 12 91

    5

    2 Arduino

    Arduino 0018

    Arduino0018

    3 USB

    Arduino328

    6

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 13 91

    USB

    7

    Arduino328

    8

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 14 91

    9

    arduino0018

    drivers

    10

    drivers FTDI USB Drivers

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 15 91

    11

    12

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 16 91

    13

    4 LED

    220 8

    .

    14

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 17 91

    15

    5 arduino

    arduino0018 arduino.exe

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 18 91

    16

    Arduino 0018

    17

    led

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 19 91

    18

    7

    compiling.....

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 20 91

    19

    Done compiling

    896

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 21 91

    20

    pinMode ledPin,OUTPUT

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 22 91

    21

    1 } 2

    void setup } 3 }

    8

    com Tools ->Board

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 23 91

    22

    Arduino 328

    COM

    .

    23

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 24 91

    24

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 25 91

    25

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 26 91

    26

    USB Serial Port COM3 COM3

    arduino Serial Port COM

    COM3

    27

    COM arduino

    28

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 27 91

    Uploading to I/O Board

    TX RX

    29

    Done Uploading

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 28 91

    30

    Done Uploading

    USB COM

    led 1s 1s

    Arduino

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 29 91

    1

    170 Arduino

    ProtoShield

    1.8"x1.4" Arduino

    2

    31

    170 10 17

    5 17 5 5

    5

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 30 91

    32

    1 5

    17

    0.4 0.6mm

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 31 91

    led

    1

    LED Ga AS P

    1.1

    LED

    PN

    P N N P PN

    N P

    http://baike.baidu.com/view/1016.htmhttp://baike.baidu.com/view/158655.htmhttp://baike.baidu.com/view/920534.htmhttp://baike.baidu.com/view/710222.htmhttp://baike.baidu.com/view/50720.htm

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 32 91

    2

    5

    R

    R E VF I

    E VF LED I LED

    1.5 2.0V 10 20mA 5v

    220

    3 Led

    1.2

    Led led I/O

    led led

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 33 91

    1.3 1

    led I/O led

    led

    1.4 2

    1 220 Prototype

    Shield 8 digital I/O

    GND

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 34 91

    1.5

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 35 91

    led

    1)

    Led 1

    220 1

    2)

    Arduino Prototype Shied

    1.5 8

    3)

    8 led 1s 8

    led 1s led 1s 1s

    led

    led led

    4)

    Code\ Lesson1 led1

    led1.pde

    arduino

    int ledPin=8 // LED IO

    void setup()

    {

    pinMode(ledPin,OUTPUT);// IO OUTPUT

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 36 91

    }

    void loop()

    {

    digitalWrite(ledPin,HIGH); // PIN8 HIGH = 5V

    delay(1000); // 1000 = 1

    digitalWrite(ledPin,LOW); // PIN8 LOW = 0V

    delay(1000); // 1000 = 1

    }

    Arduino Arduino setup() loop()

    setup()

    setup() IO pinM ode pin

    mode 8

    loop() loop()

    IO digitalWrite (pin, value) 8

    led delay(ms) ms 1000ms

    1s IO digitalWrite (pin, value) 8

    led delay(ms) ms 1000ms

    1s loop()

    5

    arduino

    6

    1s

    http://arduino.cc/en/Reference/DigitalWritehttp://arduino.cc/en/Reference/DigitalWrite

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 37 91

    1

    Led 6

    220 6

    2

    LED

    1~6

    1.6

    3

    led

    led led

    led

    led 200ms led 1.6

    200ms led led

    200ms led

    k j

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 38 91

    k j

    k j

    400ms 400ms

    400ms k j

    400ms 400ms

    4

    Code\ Lesson2 led2

    led2.pde

    arduino

    // Led IO

    int Led1 = 1;

    int Led2 = 2;

    int Led3 = 3;

    int Led4 = 4;

    int Led5 = 5;

    int Led6 = 6;

    //led 1

    void style_1(void)

    {

    unsigned char j;

    for( j=1;j=1;j -- )// 200ms 6~1 led

    {

    digitalWrite( j,LOW);// j led

    delay(200);// 200ms

    }

    }

    //

    void flash(void)

    {

    unsigned char j,k;

    for(k=0;k

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 39 91

    for( j=1;j

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 40 91

    digitalWrite( j,HIGH);//

    digitalWrite( j+k,HIGH);//

    delay(400);// 400ms

    digitalWrite( j,LOW);//

    digitalWrite( j+k,LOW);//

    k +=2;//k 2

    }

    }

    void se tup()

    {

    unsigned char i;

    for(i=1;i; < >) ;

    , ;

    , ;

    ";" : for(i=1; i10 ,

    5

    arduino

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 41 91

    6

    led >

    > > > >

    led

    led

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 42 91

    1

    2.1

    , (

    llmm)

    a b a) b)

    http://baike.baidu.com/view/421745.htmhttp://baike.baidu.com/view/1366381.htm

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 43 91

    a b

    a 9mm b 8mm

    Rxl : "+"

    ;

    (

    ) ;

    1.5~15V , , 1.5~2.5kHZ

    2

    3

    GND

    http://www.ke-sen.com/ch/ProductList.asp?SortID=13http://www.ke-sen.com/ch/ProductList.asp?SortID=15http://baike.baidu.com/view/746794.htmhttp://baike.baidu.com/view/84213.htmhttp://baike.baidu.com/view/30363.htm

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 44 91

    2.1

    1

    1

    2

    Arduino Prototype shield

    7

    3

    1ms 80

    2ms 100

    4

    Code\ Lesson3 buzzer

    buzzer.pde

    arduino

    int buzzer=8;// IO

    void setup()

    {

    pinMode(buzzer,OUTPUT);// IO OUTPUT

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 45 91

    }

    void loop()

    {

    unsigned char i,j;//

    while(1)

    {

    for(i=0;i

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 46 91

    0

    5

    arduino

    6

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 47 91

    1

    .

    3.1

    1 2 4

    3.2

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 48 91

    (COM)

    COM +5V

    3.3

    (COM)

    PWR PWR

    3.4

    2

    COM +5V

    3

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 49 91

    I/O

    COM +5V

    GND

    1

    1

    220 8

    2

    Arduino Prototype shield

    g 9 3.4 a

    f 8 5V a b

    7 6 e d 10 11 c DP 5

    4

    3.5

    3

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 50 91

    1 b c

    2s

    1 8

    4

    Code\ Lesson4\ digital_tube1

    digital_tube1.pde

    arduino

    // IO

    int a=7;

    int b=6;

    int c=5;

    int d=11;

    int e=10;

    int f=8;

    int g=9;

    int dp=4;

    // 1

    void digital_1(void)

    {

    unsigned char j;

    digitalWrite( c,LOW);// 5 c

    digitalWrite(b,LOW);// b

    for( j=7;j

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 51 91

    }

    // 3

    void digital_3(void)

    {

    unsigned char j;

    digitalWrite(g,LOW);

    digitalWrite(d,LOW);

    for( j=5;j

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 52 91

    }

    // 7

    void digital_7(void)

    {

    unsigned char j;

    for( j=5;j

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 53 91

    }

    setup() loop()

    5

    arduino

    6

    1~8

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 54 91

    1

    4.1

    2

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 55 91

    4.2

    4.3

    1 4 2 3

    1 4 2 3 1 2 4 3

    3

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 56 91

    1

    5V 2 4 3

    0V 0

    5V 1023

    1 led

    1)

    1

    220 1

    Led 1

    2)

    Arduino Prototype shield

    5V

    0

    led 7

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 57 91

    4.4 led

    3)

    0V led

    5V 2.5V led

    4

    Code\ Lesson5 key1

    key1.pde

    arduino

    int key=7;// IO

    void setup()

    {

    pinMode(key,OUTPUT);// IO

    }

    void loop()

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 58 91

    {

    int i;//

    while(1)

    {

    i=analogRead( 0);// 0

    if(i> 1000)// 1000

    digitalWrite(key,HIGH);// led

    else

    digitalWrite(key,LOW);// led

    }

    }

    5

    arduino

    6

    led led

    2

    1

    1

    1

    220 8

    2

    0

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 59 91

    4.5

    3

    1~8 0 5V

    2.5V 0

    4

    Code\ Lesson6 key2

    key2.pde

    arduino arduino

    arduino arduino

    // IO

    int a=7;

    int b=6;

    int c=5;

    int d=11;

    int e=10;

    int f=8;

    int g=9;

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 60 91

    int dp=4;

    // 1

    void digital_1(void)

    {

    unsigned char j;

    digitalWrite(c,LOW);// 5 c

    digi talWrite(b,LOW);// b

    for( j=7;j

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 61 91

    digitalWrite(d,HIGH);

    }

    // 5

    void digital_5(void)

    {

    unsigned char j;

    for( j=7;j

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 62 91

    {

    pinMode(i,OUTPUT);// 4~11

    }

    }

    void loop()

    {

    while(1)

    {

    digital_1();// 1

    while(analogRead(0)>512);// 0 0

    delay(200);// 200ms

    digital_2();

    while(analogRead(0)>512);

    delay(200);

    digital_3();

    while(analogRead(0)>512);

    delay(200);

    digital_4();

    while(analogRead(0)>512);

    delay(200);

    digital_5();

    while(analogRead(0)>512);

    delay(200);

    digital_6();

    while(analogRead(0)>512);

    delay(200);

    digital_7();

    while(analogRead(0)>512);

    delay(200);

    digital_8();

    while(analogRead(0)>512);

    delay(200);

    }

    }

    5

    arduino

    6

    1~8

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 63 91

  • Arduino V0.23 http://www.DFRobot.com.cn

    , 64 91

    1

    5.1 SW 200D

    SW-200D SW-460 SW-300DA

    SW-200D

    2

    10