Arduino 電子秤設計與製作.pdf

232

Transcript of Arduino 電子秤設計與製作.pdf

  • 5/28/2018 Arduino .pdf

    1/232

  • 5/28/2018 Arduino .pdf

    2/232

    ~ 1 ~

    Arduino

    51099 36

    04-8325434

    04-8325434

    [email protected]

    102 8

    600

    I S B N 9789868936027

    51099 36

    04-8325434

    [email protected]

    Windows/Mac

    PDF

    2D

    PDF Reader

    Copyright All Reserved

    ~ ~

  • 5/28/2018 Arduino .pdf

    3/232

    ~ 2 ~

    Arduino

    Arduino

    idea

    Arduino

    Arduino

    Arduino

    Arduino

  • 5/28/2018 Arduino .pdf

    4/232

    ~ 3 ~

    follow

    2013

  • 5/28/2018 Arduino .pdf

    5/232

    ~ 4 ~

    (ICT)

    ICT

    Arduino

    Arduino

    Arduino

    Arduino

    ICT

    DIY(Do It Yourself)

  • 5/28/2018 Arduino .pdf

    6/232

    ~ 5 ~

    Arduino

    2013

  • 5/28/2018 Arduino .pdf

    7/232

    ~ 6 ~

    ........................................................................................................................2

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

    ......................................................................................................................6

    ....................................................................................................................9

    ..................................................................................................................11

    ......................................................................................................13

    Arduino .................................................................................................16

    Arduino ..............................................................................................16

    Arduino ...............................................................................................18

    Arduino ...............................................................................19

    ......................................................................................................22

    ..............................................................................................................26

    ..............................................................................................................27

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

    ......................................................................................................33

    ......................................................................................................39

    ......................................................................................43

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

    ......................................................................................................49

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

    ......................................................................................................55

  • 5/28/2018 Arduino .pdf

    8/232

    ~ 7 ~

    ......................................................................................................60

    ..............................................................................................................62

    ......................................................................................62

    ......................................................................................................65

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

    Strain gauge .........................................................70

    Strain gauge .............................................................................72

    ..............................................................................................73

    ......................................................................................................76

    Analog to Digital Coverters (ADC) .................................................78

    Analog to Digital Converters ......................................................78

    /A/D..............................................84

    ......................................................................................................97

    ..............................................................................................................99

    ..................................................................................99

    ............................................................................106

    ........................................................113

    ....................................................................................................116

    ............................................................................................................118

    ....................................................................118

    ....................................................................120

    LCD ...................................................................................................122

    LCD KeyPad Shield ....................................................................................130

  • 5/28/2018 Arduino .pdf

    9/232

    ~ 8 ~

    LCD ......................................................................135

    ....................................................................................................140

    ............................................................................................................142

    ........................................................................................142

    ............................................................................................143

    ....................................................................................................144

    ........................................................................148

    ................................................................................154

    Arduino .....................................................................................159

    ........................................................162

    ....................................................................................................168

    ............................................................................................................170

    ....................................................................................................................171

    HX711 Arduino .............................................................................171

    LCD 1602 .....................................................................................175

    LCD&Keypad Shield ...................................................................189

    DS1307 .........................................................................................195

    HX711 ......................................................................................202

    LCDKeypad Shield ...............................................................211

    LCM 1602 ................................................................................212

    ............................................................................................................228

  • 5/28/2018 Arduino .pdf

    10/232

    ~ 9 ~

    1 Arduino Duemilanove ...............................................20

    2 Arduino UNO ............................................................21

    3 Arduino Mega2560 ...................................................22

    4 ............................................................................................62

    5 .........................................................................69

    6 ............................................................................69

    7 ........................................................................70

    8 ........................................................................................73

    9 ........................................................................................74

    10 .......................................................75

    11 HX711 ADC .........................................................................78

    12 HX711 ADC .................................................................79

    13 AD ......................................................82

    14 A 128db .......................................................................83

    15 HX711 ........................................84

    16 HX711 ..........................................................................86

    17 HX711 SOP-16 ....................................................................86

    18 HX711 ..................................................................................94

    19 HX711 ......................................................................95

    20 HX711 ..................................................................96

    21 ....................................................................101

    22 ()..................................................102

    23 100 .............................................................102

  • 5/28/2018 Arduino .pdf

    11/232

    ~ 10 ~

    24 ( 100 )..........................................103

    25 500 .............................................................104

    26 ( 500 )..........................................105

    27 ....................................................................107

    28 ()......................................108

    29 100 .................................109

    30 ( 100 )......................109

    31 500 .................................110

    32 ( 500 )...................... 111

    33 ADC .................................................112

    34 ............................................................113

    35 ............................................116

    36 ........................................................118

    37 LCD1602 ...............................................................................123

    38 LCD 1602 ...................................................................125

    39 LCD 1602 ...........................................................................125

    40 LCD Keypad Shield........................................................................131

    41 LCD Keypad ShieldPCB Layout ...........................................132

    42 keypadshield ..................................................................135

    43 ........................................................140

    44 USB TTL ..........................................................................153

    45 ............................................................153

    46 .....................................................159

    47 Tiny RTC I2C ................................................................160

    48 ............................168

  • 5/28/2018 Arduino .pdf

    12/232

    ~ 11 ~

    1 ................................................................................49

    2 HX711 SOP-16 ()....................................................87

    3 HX711 SOP-16 ..............................................................88

    4 HX711 () ................................................................89

    5 HX711 ...........................................................................90

    6A/D ........................................................93

    7 HX711 ....................................................................................94

    8 HX711 ..............................................99

    9 HX711 Arduino ...........................................100

    10 ()..............................................................101

    11 ( 100 )......................................................103

    12 ( 500 )......................................................104

    13 ()..............................................107

    14 ( 100 )......................................109

    15 ( 500 )..................................110

    16 ............................................................................112

    17 ....................................................................114

    18 .....................................................115

    19 ....................................119

    20 HX711 Arduino ..................................................................120

    21 ................................................................121

    22 LCD1602 ...................................................................123

  • 5/28/2018 Arduino .pdf

    13/232

    ~ 12 ~

    23 LCD Keypad Shield ...........................................................132

    24 LCD Keypad Shield Arduino ............................136

    25 HX711 Arduino .........................................136

  • 5/28/2018 Arduino .pdf

    14/232

    ~ 13 ~

  • 5/28/2018 Arduino .pdf

    15/232

    ~ 14 ~

    Arduino C

  • 5/28/2018 Arduino .pdf

    16/232

    ~ 15 ~

    Arduino

  • 5/28/2018 Arduino .pdf

    17/232

    ~ 16 ~

    Arduino

    Arduino

    Massimo Banzi Ivrea

    2005 Massimo Banzi

    David Cuartielles David Cuartielles

    Banzi David Mellis

    David Mellis

    Arduino

    Arduino

    Arduino

    BanziCuartielles Mellis

    (Open Source)

    CC (Creative_Commons, 2013)

    CC(Creative_Commons, 2013)

    GPL1license2 (Free Software Foundation)

    GNU (GNU GPL) CC

    1 GNUGNU General Public License GNU GPL

    GPLGNU

    2

  • 5/28/2018 Arduino .pdf

    18/232

    ~ 17 ~

    Arduino

    Arduino

    CC Arduino

    Arduino Arduino3

    Arduino

    Arduino (Arduino, 2013)

    ArduinoMassimo BanziDavid Cuartielles

    Tom IgoeGianluca MartinoDavid Mellis Nicholas Zambetti(Arduino,

    2013) ArduinoArduino

    http://www.arduino.cc/

    Arduino Atmel AVR

    (Atmel_Corporation, 2013)

    Simple I/O Java C

    Processing4/Wiring (Reas, 2013, Reas and Fry, 2007, Reas and Fry,

    2010)Processing MIT (Aesthetics & Computation

    Group) Ben Fry(http://benfry.com/) Casey Reas Processing

    Open Source

    Arduino Arduino

    3

    4 Processing Open Source

  • 5/28/2018 Arduino .pdf

    19/232

    ~ 18 ~

    SwitchLED

    Arduino IDE

    (Banzi, 2009)

    Arduino

    http://www.arduino.cc/!!

    Arduino ISCP IC bootloader

    (http://arduino.cc/en/Hacking/Bootloader?from=Main.Bootloader)

    (http://www.arduino.cc/) Arduino

    (,,,

    ,,)

    (ATMEGA8-16)

    USB 9VDC

    ArduinoCCD

  • 5/28/2018 Arduino .pdf

    20/232

    ~ 19 ~

    Arduino

    Duemilanove

    :USB

    : ATMEGA328

    USB/

    ATmega328

    5V

    (recommended)7-12 V (limits)6-20 V

    I/O Pins14 (of which 6 provide PWM output)

    Pins6

    DC Current per I/O Pin40 mA

    DC Current for 3.3V Pin50 mA

    Flash Memory32 KB (of which 2 KB used by bootloader)

    SRAM2 KB

    EEPROM1 KB

    Clock Speed16 MHz

    bootloader5

    Arduino

    Arduino USB

    5

    boot loader

  • 5/28/2018 Arduino .pdf

    21/232

    ~ 20 ~

    1 Arduino Duemilanove

    UNO

    ATMega 8U2 USB- ICSP

    MEGA8U2 ~ FTDI

    USB ~ Arduino IC 3.3V

    ATmega328

    5V

    (recommended)7-12 V

    (limits)6-20 V

    I/O Pins14 (of which 6 provide PWM output)

    Pins6

    DC Current per I/O Pin40 mA

    DC Current for 3.3V Pin50 mA

    Flash Memory32 KB (of which 0.5 KB used by bootloader)

    SRAM2 KB

    EEPROM1 KB

    Clock Speed16 MHz

  • 5/28/2018 Arduino .pdf

    22/232

    ~ 21 ~

    2 Arduino UNO

    MEGA2560

    Arduino

    ATmega2560

    5V

    (recommended)7-12 V

    (limits)6-20 V

    I/O Pins54 (of which 14 provide PWM output)

    UART:4

    Pins16

    DC Current per I/O Pin40 mA

    DC Current for 3.3V Pin50 mA

    Flash Memory256 KB of which 8 KB used by bootloader

    SRAM8 KB

    EEPROM4 KB

    Clock Speed16 MHz

  • 5/28/2018 Arduino .pdf

    23/232

    ~ 22 ~

    3 Arduino Mega2560

    Arduino

    Language Reference (http://arduino.cc/en/Reference/HomePage)

    Arduino

    setup()

    loop()

    Arduino (SKETCH)

  • 5/28/2018 Arduino .pdf

    24/232

    ~ 23 ~

    void setup()

    Arduino -

    (loop())Arduino pin

    void loop()

    Arduino

    Arduino

    (block structure) C {}

    C

    (Compound Statement)

    (

    ) (CPU

    )

  • 5/28/2018 Arduino .pdf

    25/232

    ~ 24 ~

    (naming space)C (naming space)

    (local variable) ()

    int

    z

    {

    int x, r;

    x=10;

    r=20;

    {

    int y, z;

    float r;

    y = x;

    x = 1;

    r = 10.5;

    }

    z = x; // z

    }

    r

    (scope)

    (Lifetime)

  • 5/28/2018 Arduino .pdf

    26/232

    ~ 25 ~

    r r float

    C

    {

    int tmp;

    for (tmp=0; tmp

  • 5/28/2018 Arduino .pdf

    27/232

    ~ 26 ~

    ; //()

    Arduino

    delay(100);

    {}()

    loop()

    void loop(){

    Serial.pritln("Hello !! Welcome to Arduino world");

    }

    (

    )

    Arduino

    Arduino

  • 5/28/2018 Arduino .pdf

    28/232

    ~ 27 ~

    //

    /*

    */

    (identifier) C

    int char C (keyword)

    31

    (declaration)

    HIGH | LOW

    INPUT | OUTPUT

    true | false

    Integer Constants

  • 5/28/2018 Arduino .pdf

    29/232

    ~ 28 ~

    boolean

    char

    byte

    int

    unsigned int

    long

    unsigned long

    float

    double

    string

    array

    void

    Arduino HIGH LOW

    Arduino (pin)INPUT OUTPUT

    Arduino (pin)true false

    Arduino

    Arduino

    Arduino : boolean

  • 5/28/2018 Arduino .pdf

    30/232

    ~ 29 ~

    (true)(false)

    char AArduino

    -128 127

    PSASCII UNICODE

    ASCII 127

    UNICODE

    ASCII

    byte 0 255

    (8 )

    int 2 32,768

    32,767; Arduino

    unsigned int 2

    0 65,535

  • 5/28/2018 Arduino .pdf

    31/232

    ~ 30 ~

    long

    2,147,483,648 2,147,483,647

    unsigned long 0 4,294,967,295

    float

    RAM

    double 1.7976931348623157 x 10308

    stringASCII (

    )

    Ardunio

    char word1 = "Arduino world"; // 7 + 1

    char word2 = "Arduino is a good developed kit"; //

    array LED

    light01light02light03light04light05light06

    int light = {0, 20, 40, 65, 80, 100};

  • 5/28/2018 Arduino .pdf

    32/232

    ~ 31 ~

    "array" []{}

    char()

    byte()

    int()

    long()

    float()

    char()

    char(x)

    x:

    byte()

    byte(x)

    x:

  • 5/28/2018 Arduino .pdf

    33/232

    ~ 32 ~

    int(x)

    int(x)

    x:

    long()

    int(x)

    x:

    float()

    float(x)

  • 5/28/2018 Arduino .pdf

    34/232

    ~ 33 ~

    x:

    if

    if...else

    for

    switch case

    while

    do... while

    break

    continue

    return

    Ardunio

    if else

    If(expression)

    else .

    if else

  • 5/28/2018 Arduino .pdf

    35/232

    ~ 34 ~

    #define LED 12

    void setup()

    {

    int val =1;

    if (val == 1) {

    digitalWrite(LED,HIGH);

    }

    }

    void loop()

    {

    }

    for

    void setup()

    {

    for (int i = 1; i < 9; i++) {

    Serial.print("2 * ");

    Serial.print(i);

    Serial.print(" = ");

    Serial.print(2*i);

    }

    }

    void loop()

    {

    }

    switch case

  • 5/28/2018 Arduino .pdf

    36/232

    ~ 35 ~

    if switch case swith

    case if swith

    case

    :

    void setup()

    {

    int sensorValue;

    sensorValue = analogRead(1);

    switch (sensorValue) {

    case 10:

    digitalWrite(13,HIGH);

    break;

    case 20:

    digitalWrite(12,HIGH);

    break;

    default: //

    digitalWrite(12,LOW);

    digitalWrite(13,LOW);

    }

    }

    void loop()

    {

    }

    while

    while

    :

    void setup(){

  • 5/28/2018 Arduino .pdf

    37/232

    ~ 36 ~

    int sensorValue;

    // sensor 256 LED 1

    sensorValue = analogRead(1);

    while (sensorValue < 256) {

    digitalWrite(13,HIGH);

    delay(100);

    digitalWrite(13,HIGH);

    delay(100);

    sensorValue = analogRead(1);

    }

    }

    void loop()

    {

    }

    do while

    while while

    dowhile

    :

    void setup()

    {

    int sensorValue;

    do

    {

    digitalWrite(13,HIGH);

    delay(100);

    digitalWrite(13,HIGH);

    delay(100);

    sensorValue = analogRead(1);

    }

    while (sensorValue < 256);

    }void loop()

  • 5/28/2018 Arduino .pdf

    38/232

    ~ 37 ~

    {

    }

    break

    Break

    break switch case

    :

    void setup()

    {

    }

    void loop()

    {

    int sensorValue;

    do {

    //

    if (digitalRead(7) == HIGH)

    break;digitalWrite(13,HIGH);

    delay(100);

    digitalWrite(13,HIGH);

    delay(100);

    sensorValue = analogRead(1);

    }

    while (sensorValue < 512);

    }

    continue

    continue

  • 5/28/2018 Arduino .pdf

    39/232

    ~ 38 ~

    :

    #define PWMpin 12

    #define Sensorpin 8

    void setup()

    {

    }

    void loop()

    {

    int light;

    int x ;

    for (light = 0; light < 255; light++)

    {// 140 200

    x = analogRead(Sensorpin) ;

    if ((x > 140) && (x < 200))

    continue;

    analogWrite(PWMpin, light);

    delay(10);

    }

    }

    return

    return

    computeTemperature()

    temperature

    #define PWMpin 12

    #define Sensorpin 8

    void setup()

    {

  • 5/28/2018 Arduino .pdf

    40/232

    ~ 39 ~

    }

    void loop()

    {

    int light;

    int x ;

    for (light = 0; light < 255; light++)

    {

    // 140 200

    x = computeTemperature() ;

    if ((x > 140) && (x < 200))

    continue;

    analogWrite(PWMpin, light);

    delay(10);

    }

    }

    int computeTemperature() {

    int temperature = 0;

    temperature = (analogRead(Sensorpin) + 45) / 100;

    return temperature;}

    = ()

    + ()

    - ()

    * ()

  • 5/28/2018 Arduino .pdf

    41/232

    ~ 40 ~

    / ()

    % ()

    Arduino +

    */

    (%)

    ()

    :

    #define PWMpin 12

    #define Sensorpin 8

    void setup()

    {

    int sensorValue;

    int light;

    int remainder;

    sensorValue = analogRead(Sensorpin) ;

    light = ((12 * sensorValue) - 5 ) / 2;

    remainder = 3 % 2;

    }

    void loop()

    {

    }

    == ()

  • 5/28/2018 Arduino .pdf

    42/232

    ~ 41 ~

    != ()

    < ()

    > ()

    = ()

    if,while, for

    == a==1

    != a!=1

    < a a>1

    =1

    && (and)

    || (or)

    ! (not)

    5 10

    #define PWMpin 12

    #define Sensorpin 8

    void setup()

    {

  • 5/28/2018 Arduino .pdf

    43/232

    ~ 42 ~

    }

    void loop()

    {

    int light;

    int sensor ;

    for (light = 0; light < 255; light++)

    {

    // 140 200

    sensor = analogRead(Sensorpin) ;

    if ((sensor >= 5) && (sensor

  • 5/28/2018 Arduino .pdf

    44/232

    ~ 43 ~

    ++ (increment)

    -- (decrement)

    += (compound addition)

    -= (compound subtraction)

    *= (compound multiplication)

    /= (compound division)

    (++ --)

    1 1 i++++i

    i++i i i+1++i i

    i i 1

    += , =, *= and /=

    Int value = 10 ;value = value +5 ; // ()

    value += 5 ; // ()

    / pinMode()

    digitalWrite()

    digitalRead()

    / analogRead()

  • 5/28/2018 Arduino .pdf

    45/232

    ~ 44 ~

    analogWrite() - PWM

    Arduino

    pinMode(pin, mode)

    (digital pin)

    #define sensorPin 7

    #define PWNPin 8

    void setup()

    {

    pinMode(sensorPin,INPUT); // sensorPin (7)

    }

    void loop()

    {}

    :

    digitalWrite(pin, value)

    pinMode

    digitalWrite

    :

    #define PWNPin 8

    #define sensorPin 7

    void setup()

    {

    digitalWrite(PWNPin,OUTPUT); // PWNPin (8)

    }

    void loop()

  • 5/28/2018 Arduino .pdf

    46/232

    ~ 45 ~

    {}

    int digitalRead(pin)

    HIGH

    LOW

    :

    #define PWNPin 8

    #define sensorPin 7

    void setup()

    {

    pinMode(sensorPin,INPUT); // sensorPin (7)

    val = digitalRead(7); // 7 val

    }

    void loop()

    {

    }

    int analogRead(pin)

    0 1023 0 5

    :

    #define PWNPin 8

    #define sensorPin 7

    void setup()

    {

    pinMode(sensorPin,INPUT); // sensorPin (7)

    val = analogRead(7); // 7 val

    }

    void loop(){

  • 5/28/2018 Arduino .pdf

    47/232

    ~ 46 ~

    }

    analogWrite(pin, value)

    PWM 356910 11value

    0-255 2.5 V 128

    :

    #define PWNPin 8

    #define sensorPin 7

    void setup()

    {

    analogWrite (PWNPin,OUTPUT); // PWNPin (8)

    }

    void loop()

    { }

    I/O tone()

    noTone()

    shiftOut()

    pulseIn()

    shiftOut(dataPin, clockPin, bitOrder, value)

    bitOrderLSBFIRST

    MSBFIRST value byte

    :

  • 5/28/2018 Arduino .pdf

    48/232

    ~ 47 ~

    #define dataPin 8

    #define clockPin 7

    void setup()

    {

    shiftOut(dataPin, clockPin, LSBFIRST, 255);

    }

    void loop()

    { }

    unsigned long pulseIn(pin, value)

    :

    #define dataPin8

    #define pulsein7

    void setup()

    {Int time ;

    time = pulsein(pulsein,HIGH); // 7

    HIGH

    }

    void loop()

    { }

    millis()

    micros()

    delay()

    delayMicroseconds()

  • 5/28/2018 Arduino .pdf

    49/232

    ~ 48 ~

    unsigned long millis()

    :

    int lastTime ,duration;

    void setup()

    {

    lastTime = millis() ;

    }

    void loop()

    {

    duration = -lastTime; // "lastTime"

    }

    delay(ms)

    :

    void setup()

    {

    Serial.begin(9600);

    }

    void loop()

    {

    Serial.print(millis()) ;

    delay(500); //500

    }

    10 3 10 3

    0.001 1

  • 5/28/2018 Arduino .pdf

    50/232

    ~ 49 ~

    1

    p pico 10 12

    n nano 10 9

    u micro 10 6

    m milli 10 3

    K kilo 10 3

    M mega 10 6

    G giga 10 9

    T tera tera

    delay Microseconds(us)

    :

    void setup()

    {

    Serial.begin(9600);

    }

    void loop()

    {

    Serial.print(millis()) ;

    delayMicroseconds (1000); //500

    }

    min()

    max()

    abs() constrain()

  • 5/28/2018 Arduino .pdf

    51/232

    ~ 50 ~

    map()

    pow()

    sq()

    sqrt()

    min(x, y)

    #define sensorPin1 7#define sensorPin2 8

    void setup()

    {

    int val;

    pinMode(sensorPin1,INPUT); // sensorPin1 (7)

    pinMode(sensorPin2,INPUT); // sensorPin2 (8)

    val = min(analogRead (sensorPin1), analogRead (sensorPin2)) ;

    }

    void loop()

    { }

    max(x, y)

    #define sensorPin1 7

    #define sensorPin2 8

    void setup()

    {

    int val;

    pinMode(sensorPin1,INPUT); // sensorPin1 (7)

    pinMode(sensorPin2,INPUT); // sensorPin2 (8)

    val = max (analogRead (sensorPin1), analogRead (sensorPin2)) ;

  • 5/28/2018 Arduino .pdf

    52/232

    ~ 51 ~

    }

    void loop()

    { }

    abs(x)

    #define sensorPin1 7

    void setup(){

    int val;

    pinMode(sensorPin1,INPUT); // sensorPin (7)

    val = abs(analogRead(sensorPin1)-500);

    // -500

    }

    void loop()

    { }

    constrain(x, a, b)

    x a b x a a a b

    x b b

    #define sensorPin1 7

    #define sensorPin2 8

    #define sensorPin 12

    void setup()

    {

    int val;

    pinMode(sensorPin1,INPUT); // sensorPin1 (7)

    pinMode(sensorPin2,INPUT); // sensorPin2 (8)

  • 5/28/2018 Arduino .pdf

    53/232

    ~ 52 ~

    pinMode(sensorPin,INPUT); // sensorPin (12)

    val = constrain(analogRead(sensorPin), analogRead (sensorPin1),

    analogRead (sensorPin2)) ;

    // 255

    }

    void loop()

    {

    }

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

    value fromLow fromHigh toLow toHigh

    #define sensorPin1 7

    #define sensorPin2 8

    #define sensorPin 12

    void setup(){

    int val;

    pinMode(sensorPin1,INPUT); // sensorPin1 (7)

    pinMode(sensorPin2,INPUT); // sensorPin2 (8)

    pinMode(sensorPin,INPUT); // sensorPin (12)

    val = map(analogRead(sensorPin), analogRead (sensorPin1), analogRead

    (sensorPin2),0,100) ;

    // analog0 100 200 }

    void loop()

    { }

    double pow(base, exponent)

    (base)(exponent)

  • 5/28/2018 Arduino .pdf

    54/232

    ~ 53 ~

    int y=2;

    double x = pow(y, 32); // x y 32

    double sqrt(x)

    double

    int y=2123;double x = sqrt(y); // 2123

    sin()

    cos()

    tan()

    double sin(rad)

    radians sine

    int y=45;

    double sine = sin(y); // 0.70710678118654

    double cos(rad)

    radians cosine

    int y=45;

  • 5/28/2018 Arduino .pdf

    55/232

    ~ 54 ~

    double cosine = cos(y); // 0.70710678118654

    double tan(rad)

    radians tangent

    int y=45;

    double tangent = tan(y); // 1

    randomSeed()

    random()

    randomSeed(seed)

    Arduino

    #define sensorPin 7

    void setup()

    {

    randomSeed(analogRead(sensorPin)); //

    }

    void loop(){

  • 5/28/2018 Arduino .pdf

    56/232

    ~ 55 ~

    }

    long random(max)long random(min, max)

    long 0

    #define sensorPin 7

    long randNumber;

    void setup(){Serial.begin(9600);

    // if analog input pin sensorPin(7) is unconnected, random analog

    // noise will cause the call to randomSeed() to generate

    // different seed numbers each time the sketch runs.

    // randomSeed() will then shuffle the random function.

    randomSeed(analogRead(sensorPin));

    }

    void loop() {

    // print a random number from 0 to 299

    randNumber = random(300);

    Serial.println(randNumber);

    // print a random number from 0 to 100

    randNumber = random(0, 100); // 0 99

    Serial.println(randNumber);

    delay(50);

    }

  • 5/28/2018 Arduino .pdf

    57/232

    ~ 56 ~

    Serial.begin(speed)

    Arduino 9600 bps

    115,200 bps

    void setup() {

    Serial.begin(9600); // open the serial port at 9600 bps:

    }

    void loop() {

    }

    Serial.print(data)

    int x = 0; // variable

    void setup() {

    Serial.begin(9600); // open the serial port at 9600 bps:

    }

    void loop() {

    // print labels

    Serial.print("NO FORMAT"); // prints a label

    Serial.print("\t"); // prints a tab

    Serial.print("DEC");

    Serial.print("\t");

    Serial.print("HEX");

    Serial.print("\t");

    Serial.print("OCT");

    Serial.print("\t");

    Serial.print("BIN");

  • 5/28/2018 Arduino .pdf

    58/232

    ~ 57 ~

    Serial.print("\t");

    }

    Serial.println(data)

    Serial.println(data, encoding)

    Serial.print()

    Enter

    int x = 0; // variable

    void setup() {

    Serial.begin(9600); // open the serial port at 9600 bps:

    }

    void loop() {

    // print labels

    Serial.print("NO FORMAT"); // prints a label

    Serial.print("\t"); // prints a tab

    Serial.print("DEC");Serial.print("\t");

    Serial.print("HEX");

    Serial.print("\t");

    Serial.print("OCT");

    Serial.print("\t");

    Serial.print("BIN");

    Serial.print("\t");

    for(x=0; x< 64; x++){ // only part of the ASCII chart, change to suit

    // print it out in many formats:

    Serial.print(x); // print as an ASCII-encoded decimal - same as

    "DEC"

    Serial.print("\t"); // prints a tab

    Serial.print(x, DEC); // print as an ASCII-encoded decimal

    Serial.print("\t"); // prints a tab

    Serial.print(x, HEX); // print as an ASCII-encoded hexadecimal

    Serial.print("\t"); // prints a tab

  • 5/28/2018 Arduino .pdf

    59/232

    ~ 58 ~

    Serial.print(x, OCT); // print as an ASCII-encoded octal

    Serial.print("\t"); // prints a tab

    Serial.println(x, BIN); // print as an ASCII-encoded binary

    // then adds the carriage return with "println"

    delay(200); // delay 200 milliseconds

    }

    Serial.println(""); // prints another carriage return

    }

    int Serial.available()

    bytes read()

    0 read()

    int incomingByte = 0; // for incoming serial data

    void setup() {

    Serial.begin(9600); // opens serial port, sets data rate to 9600

    bps}

    void loop() {

    // send data only when you receive data:

    if (Serial.available() > 0) {

    // read the incoming byte:

    incomingByte = Serial.read();

    // say what you got:

    Serial.print("I received: ");Serial.println(incomingByte, DEC);

    }

    }

    int Serial.read()

    1byte

  • 5/28/2018 Arduino .pdf

    60/232

    ~ 59 ~

    int incomingByte = 0; // for incoming serial data

    void setup() {

    Serial.begin(9600); // opens serial port, sets data rate to 9600 bps

    }

    void loop() {

    // send data only when you receive data:

    if (Serial.available() > 0) {

    // read the incoming byte:

    incomingByte = Serial.read();

    // say what you got:

    Serial.print("I received: ");Serial.println(incomingByte, DEC);

    }

    }

    int Serial.write()

    void setup(){

    Serial.begin(9600);

    }

    void loop(){

    Serial.write(45); // send a byte with the value 45

    int bytesSent = Serial.write("hello Arduino , I am a beginner in the

    Arduino world");

    }

    Serial.flush()

  • 5/28/2018 Arduino .pdf

    61/232

    ~ 60 ~

    (buffer)

    void setup(){

    Serial.begin(9600);

    }

    void loop(){

    Serial.write(45); // send a byte with the value 45

    int bytesSent = Serial.write("hello Arduino , I am a beginner in theArduino world");

    Serial.flush();

    }

    Arduino

  • 5/28/2018 Arduino .pdf

    62/232

    ~ 61 ~

  • 5/28/2018 Arduino .pdf

    63/232

    ~ 62 ~

    CPU

    CPU

    4

  • 5/28/2018 Arduino .pdf

    64/232

    ~ 63 ~

    1

    2

    3

    4

    30Kg

    30-300Kg

    300Kg

    5

    I 10-6

    II 10-5

  • 5/28/2018 Arduino .pdf

    65/232

    ~ 64 ~

    2.

    3. ()

    4.

    5.

    6.

    7. ()

    8.

    9.

    10. e

    11.

    1. ()

    2.

    3. 120%

    4.

    5.

    6. ;d

    7. 60Kg5g5g

    8. =( e )300g

    0.001g0.001g

    9. 10g 10g

    100kg10g(1001000)10=1000010000

  • 5/28/2018 Arduino .pdf

    66/232

    ~ 65 ~

    10. 6000g

    0.5g 05/6000=1/12000 1/12000

    11.

    12.

    13.

    14. CPU

    Counting Scale

    15. ;

    16. OFFSET COUNT

  • 5/28/2018 Arduino .pdf

    67/232

    ~ 66 ~

  • 5/28/2018 Arduino .pdf

    68/232

    ~ 67 ~

    1971 Ralph S.Shoberg

    (Shoberg, 1971, Shoberg, 1976, Shoberg, 1978)

    4

    (Load Cell) 5

  • 5/28/2018 Arduino .pdf

    69/232

    ~ 68 ~

    5

    6(Strain Gage)(Window and Holister,

    1982) 6

    (Strain Gage)

    7

    (Hannah and Reed, 1992)

  • 5/28/2018 Arduino .pdf

    70/232

    ~ 69 ~

    5

    6

  • 5/28/2018 Arduino .pdf

    71/232

    ~ 70 ~

    7

    Strain gauge

    ()

    resistivity

    (1).....cA

    LR =

    resistivity

    -m

    Eq. (1)

    (2).....)(

    c

    cc

    A

    LdAdLLdAdR

    +=

    Eq. (2) Eq. (1)

    (3).....c

    c

    A

    dA

    L

    dLd

    R

    dR+=

  • 5/28/2018 Arduino .pdf

    72/232

    ~ 71 ~

    Poissons ratio

    (4).....2

    =

    L

    dL

    A

    dA

    c

    c

    Eq. (4) Eq. (3)

    (5).....2

    +=

    L

    dL

    L

    dLd

    R

    dR

    Eq. (5) Eq. (6)

    (6).....)21(

    ++=

    L

    dLd

    R

    dR

    Gage Factor (GF)

    (7).....21

    L

    dL

    d

    L

    dLR

    dR

    GF

    ++==

    Eq. (7)

    d

    0 Poisons ratio

    0.3 6.121 += GF

    L

    dL

    (axial strain)

    (8).....

    L

    dL=

  • 5/28/2018 Arduino .pdf

    73/232

    ~ 72 ~

    Eq. (7) Eq. (8)= Gage Factor (GF)

    (9).....GF=

    R

    dR

    (strain

    gage)(Beckwith, et al., 2007)

    Strain gauge

    strain gauge, strain gage(

    8 )1938 Edward E. Simmons(Simmons, 1942, Simmons,

    1944) Arthur C. Ruge(C, 1943, Ruge, 1943)

    (AA 502 )(Coover, 1956)

    ( 8 )

  • 5/28/2018 Arduino .pdf

    74/232

    ~ 73 ~

    ( 8 )

    :(a).(Wire)(b).(foil)

    ()

    8

    8

    Wheatstone bridge

    1833 Samuel Hunter Christie 1843

    (Stein, 1990)

  • 5/28/2018 Arduino .pdf

    75/232

    ~ 74 ~

    9

    9

    (, et al., 2003)

    3

    2

    4

    1

    R

    R

    R

    R= RR =2

    ( RRRR === 431 ) RRR +=2

    1 (, et al., 2003)

  • 5/28/2018 Arduino .pdf

    76/232

    ~ 75 ~

    ( )( )( )

    exc

    exc

    exc

    exc

    exc

    excexc

    R

    R

    R

    RR

    RRRifRRR

    RR

    RRR

    RRRRRR

    R

    R

    RR

    RR

    RR

    R

    RRR

    RRE

    V4

    1

    V4

    24V24

    V22

    222

    V22

    VV

    2

    2

    2

    22

    0

    =

    =

    >>

    +

    =

    +

    ++=

    +

    +=

    +

    ++

    +=

    1

    (, et al., 2003)

    strain gauge, strain gage 10

    10

    (, et al., 2003)

    RRRR ==31

    C

    RRRR +== 42 T

  • 5/28/2018 Arduino .pdf

    77/232

    ~ 76 ~

    (, et al., 2003)

    exc

    exc

    exc

    excexc

    R

    RE

    R

    R

    RRRRRRRR

    RR

    RRRR

    RRE

    V

    VR

    V2

    VV

    0

    0

    =

    =

    ++=

    ++

    ++

    +=

    2

    (, et al., 2003)

    (Load Cell)(Load Cell)

    Arduino

    ( 10 )

    24 Analog to Digital Converters (ADC)

  • 5/28/2018 Arduino .pdf

    78/232

    ~ 77 ~

    DC

  • 5/28/2018 Arduino .pdf

    79/232

    ~ 78 ~

    Analog to Digital Coverters

    (ADC)

    Analog to Digital Converters

    (, 2013)

    HX711 ad(, 2013)

    1112

    (MCU)

    11 HX711 ADC

  • 5/28/2018 Arduino .pdf

    80/232

    ~ 79 ~

    12 HX711 ADC

    HX711 24 A/D

    A

    B A 128

    6420mV 40mV B

    64

    A/D

    HX711

    4.8-5.5v

    1.6mA

    2.9cm * 1.7cm * 0.4cm

  • 5/28/2018 Arduino .pdf

    81/232

    ~ 80 ~

    (STC15F104)

    3264 128

    A/D

    Tx/Rx

    10Hz 80Hz

    50Hz 60Hz

    < 1.7mA, < 1A

    2.6 ~ 5.5V

    -20 ~ +85

    (Load Cell)

    AA+ A-

  • 5/28/2018 Arduino .pdf

    82/232

    ~ 81 ~

    BB+ B-

    HX711DIOSCK

    22k

    J1

    HX71180hz/10hz

    4.7V5.5V5.5V

    4.7V

    BB+ B-

    HX711

    13 HX711

    13

  • 5/28/2018 Arduino .pdf

    83/232

    ~ 82 ~

    13 AD

    Arduino 14

    115200

    /do/ck

    1 A 128db

  • 5/28/2018 Arduino .pdf

    84/232

    ~ 83 ~

    14 A 128db

    HX711

    15HX7118STCSTC15F104

    SOP8 15

  • 5/28/2018 Arduino .pdf

    85/232

    ~ 84 ~

    15 HX711

    /A/D

    HX711 24A/D

    MCU

    A B

    A 128 64

    20mV 40mV B 32

  • 5/28/2018 Arduino .pdf

    86/232

    ~ 85 ~

    A/D

    64 128

    A/D

    Tx/Rx

    10Hz 80Hz

    50Hz 60Hz

    < 1.7mA,

    < 1A

    2.6 ~ 5.5V

  • 5/28/2018 Arduino .pdf

    87/232

    ~ 86 ~

    -20 ~ +85

    16 HX711

    16 HX711

    (, 2013)

    17 HX711Pin

    SOP-16

    17 HX711 SOP-16

    (, 2013)

    2 HX711

  • 5/28/2018 Arduino .pdf

    88/232

    ~ 87 ~

    3 HX711

    2 HX711 SOP-16 ()

    Pin # Name Function Description

    1 VSUP Power Regulator supply: 2.7 ~ 5.5V

    2 BASE Analog Output Regulator control outputNC when not used

    3 AVDD Power Analog supply: 2.6 ~ 5.5V

    4 VFB Analog Input Regulator control inputconnect to AGND

    when not used

    5 AGND Ground Analog Ground

    6 VBG Analog Output Reference bypass output

    7 INA- Analog Input Channel A negative input

    8 INA+ Analog Input Channel A positive input

    9 INB- Analog Input Channel B negative input

    10 INB+ Analog Input Channel B positive input

    11 PD_SCK Power down control (high active) and serial

    clock input

    12 DOUT Digital Output Serial data output

    13 XO Digital I/O Crystal I/O (NC when not used

    14 XI Digital Input Crystal I/O or external clock input, 0: use

    on-chip oscillator

    15 RATE Digital Input Output data rate control, 0: 10Hz; 1: 80Hz

    16 DVDD Power Digital supply: 2.6 ~ 5.5V

    (, 2013)

  • 5/28/2018 Arduino .pdf

    89/232

    ~ 88 ~

    3 HX711 SOP-16

    1 VSUP : 2.6 ~ 5.5V

    AVDD

    2 BASE

    3 AVDD : 2.6 ~ 5.5V

    4 VFB

    5 AGND

    6 VBG

    7 INA- A

    8 INA+ A

    9 INB- B

    10 INB+ B

    11 PD_SCK Tx/Rx

    12 DOUT Tx/Rx

    13 XO

    14 XI 0:

    15 RATE 0: 10Hz; 1: 80Hz

    16 DVDD : 2.6 ~ 5.5V

    (, 2013)

    4 HX711 Pin 5 HX711 Pin

  • 5/28/2018 Arduino .pdf

    90/232

    ~ 89 ~

    4 HX711 ()

    Parameter Notes MIN TYP MAX UNIT

    Full scale

    differential

    input range

    V(inp)-V(inn) 0.5(AVDD/GAIN) V

    Common mode

    input

    AGND+1.2 AVDD-1.3 V

    Internal Oscillator, RATE = 0 10

    Internal Oscillator, RATE =

    DVDD

    80

    Crystal or external clock,

    RATE = 0

    fclk/1,105,920

    Output data rate

    Crystal or external clock,

    RATE = DVDD

    fclk/138,240

    Hz

    Output data coding 2s complement 800000 7FFFFF HEX

    RATE = 0 400Output settling time

    RATE = DVDD 50

    50

    Gain = 128 0.2Input offset drift

    Gain = 64 0.4

    mV

    Gain = 128RATE = 0 50Input noise

    Gain = 128RATE = DVDD 90

    nV(rms)

    Input offsetGain = 128 6 nV/Temperature drift

    GainGain = 128 5 ppm/

    Input common

    mode

    rejection

    Gain = 128RATE = 0 100 dB

  • 5/28/2018 Arduino .pdf

    91/232

    ~ 90 ~

    Power supply

    rejection

    Gain = 128RATE = 0 100 dB

    Reference bypass

    VBG

    1.25 V

    Crystal or external

    clock frequency

    1 11.0592 20 MHz

    DVDD 2.6 5.5Power supply

    voltage AVDDVSUP 2.6 5.5

    V

    Normal 1400Analog supply

    current (including

    regulator)Power down 0.3

    A

    Normal 100Digital supply

    currentPower down 0.2

    A

    (, 2013)

    5 HX711

    V(inp)-V(inn) 0.5(AVDD/GAIN) V

    AGND+0.6 AVDD-0.6 V

    RATE = 0 10 Hz

    RATE

    = DVDD

    80

    RATE

    = 0

    fclk/1,105,920

  • 5/28/2018 Arduino .pdf

    92/232

    ~ 91 ~

    RATE = DVDD fclk/138,240

    800000 7FFFFF(HEX)

    RATE = 0 400 ms(1)

    RATE = DVDD 50

    = 128 0.2 mV

    = 64 0.8

    = 128RATE = 0 50 nV(rms)

    = 128RATE =

    DVDD

    90

    =

    128

    7 nV/

    = 128 3 ppm/

    = 128RATE = 0 100 dB

    = 128RATE = 0 100 dB

    VBG 1.25 V

    1 11.0592 30 MHz

    DVDD 2.6 5.5 V

    AVDDVSUP 2.6 5.5

    1600

    0.3

    A

    100 A

    0.2

    (, 2013)

  • 5/28/2018 Arduino .pdf

    93/232

    ~ 92 ~

    A

    A/D

    128 64

    20mV 40mV B 32

    80mV B

    (DVDD) MCU HX711

    A/D

    (VSUP) (DVDD)

    VAVDD R1R2 VBG

    1VAVDD=VBG(R1+R2)/R

    (VSUP) 100mV VSUP

    AVDD 2.65.5V

    VBG VFB BASE

    XI HX711

    10Hz 80Hz

    20pF XIXI XO

    11.0592MHz,

    10Hz 80Hz

    MCU

  • 5/28/2018 Arduino .pdf

    94/232

    ~ 93 ~

    20pF XI

    150mV

    Tx/Rx

    Tx/RxPD_SCK DOUT

    DOUT A/D

    Tx/RxPD_SCK DOUT

    PD_SCK 25 27

    24

    MSB24 24

    2527 A/D

    6

    6A/D

    PD_SCK 25 A 12826 B 3227 A 64

    PD_SCK 25 27Tx/Rx

    A/D A/D 4

    DOUT 4

  • 5/28/2018 Arduino .pdf

    95/232

    ~ 94 ~

    18 HX711

    7 HX711

    Symbol Note MIN TYP MAX Unit

    T1 DOUT falling edge to PD_SCK rising edge 0.1 s

    T2 PD_SCK rising edge to DOUT data ready 0.1 s

    T3 PD_SCK high time 0.2 1 50 s

    T4 PD_SCK low time 0.2 1 s

    (, 2013)

    PD_SCK HX711 PD_SCK

  • 5/28/2018 Arduino .pdf

    96/232

    ~ 95 ~

    19 HX711

    (, 2013)

    PD_SCK 60sHX711

    19

    A/D PD_SCK

    A 128 A/D

    PD_SCK Tx/Rx

    A/D 4

    DOUT 4

    20HX711

    (XI=0)10Hz (RATE=0) 2.7

    5.5V) MCU

    PNP S8550 R1R2 A/D

    A B

  • 5/28/2018 Arduino .pdf

    97/232

    ~ 96 ~

    20

    20 HX711

    (, 2013)

    \

    HX711 1. RATE XI PD_SCK

    2.

    3. A B

    4. PNP S8550

    MOS

    5. A/D

    6. 25 27 Tx/Rx

  • 5/28/2018 Arduino .pdf

    98/232

    ~ 97 ~

    HX711Analog to Digital Converters (ADC)

    Arduino

  • 5/28/2018 Arduino .pdf

    99/232

    ~ 98 ~

  • 5/28/2018 Arduino .pdf

    100/232

    ~ 99 ~

    (Load Cell)

    Arduino

    13 (Load Cell)

    HX711 8 (Load Cell)

    HX711

    HX711 ( 11 & 12)

    Arduino 9 HX711 Arduino

    9

    8 HX711

    HX711 E+() +(:) E-() GND(:) A+(/) A+(:) ()A-() A-(:) ()

  • 5/28/2018 Arduino .pdf

    101/232

    ~ 100 ~

    9 HX711 Arduino

    HX711 Arduino Do Rx Arduino digital output pin 8 DO/RX Clock Arduino digital output pin 9 CK/TX Vcc Arduino pin 5V 5V GND Arduino pin Gnd

    Arduino sketch

    Arduino

    HX711 (hx711_1)

    #include // HX711Arduino library

    #define datapin 8 //

    #define clockpin 9 //

    HX711 hx(clockpin, datapin,128); // HX711

    void setup() {

    Serial.begin(9600);

    }

    void loop()

    {

    double sum = 0; // 10 for (int i = 0; i < 10; i++) //

    sum += hx.read(); //

    Serial.println(sum/10); //

    }

    21

    10

  • 5/28/2018 Arduino .pdf

    102/232

    ~ 101 ~

    21

    10 ()

    -14175.70

    -14365.20

    -14380.20-14514.20

    -14388.90

    -14452.90

    -14481.20

    -14498.90

    -14593.50

    -14456.00

    -14555.50

    -14387.70

    -14504.30

  • 5/28/2018 Arduino .pdf

    103/232

    ~ 102 ~

    ()

    -20000

    -100000

    10000

    1 26 51 76 101 126 151 176 201

    0()

    22 ()

    23 100

    11

    23 100

  • 5/28/2018 Arduino .pdf

    104/232

    ~ 103 ~

    11 ( 100 )

    16838.60

    16870.40

    16894.50

    16787.20

    16744.50

    16901.50

    16845.60

    16821.20

    16844.90

    16878.10

    16890.00

    16803.00

    16875.00

    (100)

    0

    5000

    10000

    15000

    20000

    1 16 31 46 61 76 91 1 06 121 136 151 166 181 196

    100()

    24 ( 100 )

    25 500

    12

  • 5/28/2018 Arduino .pdf

    105/232

    ~ 104 ~

    25 500

    12 ( 500 )

    142037.90

    142217.09

    142129.40

    142273.40

    142258.40

    142298.59

    142302.20

    142069.79

    142172.90

    141995.50

    142230.20

    142085.79

    142271.50

  • 5/28/2018 Arduino .pdf

    106/232

    ~ 105 ~

    (500)

    0100000

    200000

    1 28 55 82 109 136 163 190

    500()

    26 ( 500 )

    10 -14370.82875

    12 100 16876.45 500

    142028.1371 11

    a = -14370.82875

    100 c=16876.45

    500 b=142028.1371

    3

    )A-A(p

    DCDC=

    3

    3

    )A-A(p

    DCDC=

  • 5/28/2018 Arduino .pdf

    107/232

    ~ 106 ~

    100

    870.00320027875))(-14370.82-16876.45(

    100p ==

    400 150.0031961216876.45)-71(142028.13

    400p ==

    500

    0.0031977841 0.0031977841

    0.0031977841

    27

    13

    Step2

    HX711 (hx711_2)

    #include // HX711Arduino library

    #define datapin 8 //

    #define clockpin 9 //

    HX711 hx(clockpin, datapin,128, 0.0031977841 ); // HX711

    void setup() {

    Serial.begin(9600);

    }

    void loop(){

  • 5/28/2018 Arduino .pdf

    108/232

    ~ 107 ~

    HX711 (hx711_2)

    double sum = 0; // 10

    for (int i = 0; i < 10; i++) //

    sum += hx.read(); //

    Serial.println(sum/10); //

    }

    27

    13 ()

    -13296.00

    -13239.10

    -13107.50

    -12982.90

    -13061.40

    -13083.80

    -13271.50

    -13161.10

    -13157.80-13309.20

  • 5/28/2018 Arduino .pdf

    109/232

    ~ 108 ~

    -13274.20

    -13311.60

    -13314.70

    ()

    -15000

    -10000

    -5000

    0

    5000

    1 17 33 49 65 81 97 113 129 145 161 177 193

    0()

    28 ()

    29 100

    11

  • 5/28/2018 Arduino .pdf

    110/232

    ~ 109 ~

    29 100

    14 ( 100 )

    18026.40

    18005.50

    18081.40

    17976.60

    17976.80

    18060.50

    17986.70

    17967.70

    18020.10

    18115.80

    18246.00

    18169.20

    18078.40

    (100)

    0

    5000

    10000

    15000

    20000

    1 15 29 43 57 71 85 99 113 127 141 155 169 183 197

    100

    30 ( 100 )

    31 500

    500 15

  • 5/28/2018 Arduino .pdf

    111/232

    ~ 110 ~

    31 500

    15 ( 500 )

    143485.59

    143496.20

    143591.29

    143614.90143578.29

    143534.70

    143440.20

    143461.59

    143406.90

    143367.59

    143293.20

    143509.20

    143402.20

  • 5/28/2018 Arduino .pdf

    112/232

    ~ 111 ~

    (500)

    0

    50000

    100000

    150000

    200000

    1 16 31 46 61 76 91 1 06 121 136 151 166 181 196

    500

    32 ( 500 )

    13 -13117.91613

    14 100 18148.34241 15

    500 143325.8016

    a =-13117.91613

    100 b=18148.34241

    500 c=143325.8016

    3

    )A-A(p

    DCDC=

    100

    600.00319833613))(-13117.91-118148.3424(

    100p ==

    400

    350.003195461)18148.3424-6143325.801(

    400p ==

  • 5/28/2018 Arduino .pdf

    113/232

    ~ 112 ~

    500

    16

    33 34

    0.0031977841

    0.0031977841

    16

    A DC ADC

    100 31250.76067 31266.25854 0.003199922110 0.003198335991 0.000001586118

    400 125148.2052 125177.4592 0.003196210440 0.003195463484 0.000000746956

    500 156398.9659 156443.7178 0.003196952085 0.003196037573 0.000000914512

    104265.9772 104295.8118 0.003197694878 0.003196612349 0.000001082529

    ADC

    -40

    -20

    0

    20

    40

    100 400 500

    ADC

    ADC

    ADC

    33 ADC

  • 5/28/2018 Arduino .pdf

    114/232

    ~ 113 ~

    0.0031920000000.0031940000000.0031960000000.003198000000

    0.0032000000000.003202000000

    100 400 500

    34

    0.0031977841

    ADC -13117.91613

    ADC -13117.91613 setup

    bias_read()

    read()

    HX711 (hx711_3)

    #include // HX711Arduino library

    #define datapin 8 //

    #define clockpin 9 //

    HX711 hx(clockpin, datapin,128,0.0031977841); // HX711

    void setup() {

    hx.set_offset(-13117.91613);

    Serial.begin(9600);

    }

    void loop() {delay(500);

  • 5/28/2018 Arduino .pdf

    115/232

    ~ 114 ~

    HX711 (hx711_3)

    double sum0 = 0;

    double sum1 = 0;

    for (int i = 0; i < 10; i++) {

    sum0 += hx.read();

    sum1 += hx.bias_read();

    }

    Serial.print(sum0/10);

    Serial.print(" ");

    Serial.println(sum1/10);

    }

    Arduino

    17

    17

    -24961.30 0.31

    -25042.10 0.06-24981.30 0.20

    37749.10 200.51

    37719.40 200.24

    37597.30 199.95

    37582.50 199.87

    37647.40 200.08

    69114.80 299.76

    69011.80 300.4468868.80 300.50

    100459.30 399.97

    100351.60 400.16

    100325.80 400.23

    131672.59 500.06

    131693.40 500.40

    131663.29 500.29

    37689.80 199.87

    37639.10 200.10

  • 5/28/2018 Arduino .pdf

    116/232

    ~ 115 ~

    22020.40 150.24

    22022.10 150.24

    EXCEL 18

    18 1

    0.165714286

    (0.165714286) 0.2

    18

    ADC

    1 -24961.3 0.31 0 0.31

    2 -25042.1 0.06 0 0.06

    3 -24981.3 0.2 0 0.2

    4 37749.1 200.51 200 0.51

    5 37719.4 200.24 200 0.24

    6 37597.3 199.95 200 -0.05

    7 37582.5 199.87 200 -0.138 37647.4 200.08 200 0.08

    9 69114.8 299.76 300 -0.24

    10 69011.8 300.44 300 0.44

    11 68868.8 300.5 300 0.5

    12 100459.3 399.97 400 -0.03

    13 100351.6 400.16 400 0.16

    14 100325.8 400.23 400 0.23

    15 131672.59 500.06 500 0.0616 131693.4 500.4 500 0.4

    17 131663.29 500.29 500 0.29

    18 37689.8 199.87 200 -0.13

    19 37639.1 200.1 200 0.1

    20 22020.4 150.24 150 0.24

    21 22022.1 150.24 150 0.24

    22 252.5467 252.381 0.165714

  • 5/28/2018 Arduino .pdf

    117/232

    ~ 116 ~

    -100

    0

    100

    200

    300400

    500

    600

    1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

    35

    18 35

    x

    (0.165714286)

    0.2

  • 5/28/2018 Arduino .pdf

    118/232

    ~ 117 ~

  • 5/28/2018 Arduino .pdf

    119/232

    ~ 118 ~

    (Load Cell)(Load Cell)

    36

    Analog to Digital Converters (ADC)

    19

    36

    0.0031977841 Analog

    to Digital Converters (ADC)-13117.91613 Arduino

  • 5/28/2018 Arduino .pdf

    120/232

    ~ 119 ~

    hx.set_offset(-13117.91613)-13117.91613

    0

    19 0 -61.72

    19

    ADC

    -32433 -61.72 0.013333

    -32463.9 -61.81 -0.076670

    -32427.6 -61.67 0.063333

    -61.7333

    -1108.5 38.41 0.1125

    -1121.9 38.28 -0.0175

    -1181.9 38.17 -0.1275

    100

    -1129.9 38.33 0.0325

    38.2975

    30153.8 138.27 -0.09

    30155.4 138.39 0.03

    30175.4 138.44 0.08

    30142.5 138.32 -0.04

    200

    30154.9 138.38 0.02

    138.36

    92688.9 338.59 0.16

    92759.1 338.27 -0.16

    92683.8 338.56 0.13

    92716.9 338.21 -0.22

    400

    92688.6 338.52 0.09

    338.43

    123959.2 438.420.12

    124046 438.5 0.2

    123939.9 438.3 0

    123906.6 438.26 -0.04

    123918.5 438.09 -0.21

    500

    123937.7 438.35 0.05

    438.3

    0.005217391

    19

  • 5/28/2018 Arduino .pdf

    121/232

    ~ 120 ~

    0.005217391 Analog to Digital Converters (ADC)

    0

    HX711 Arduino 20

    void tare(int t)

    20 HX711 Arduino

    HX711(byte sck, byte dout, byte amp = 128, double co = 1); // sckdout

    128 1

    void set_amp(byte amp); // read()

    bool is_ready(); // hx711 read()

    long read(); // hx711

    double bias_read(); // (read() - ) *

    void tare(int t = 10); // read();

    void set_co(double co = 1); // 1

    void set_offset(long offset = 0); // 0

    setup(){} void tare(int t );

    // Analog to

    Digital Converters (ADC)

    HX711 (hx711_4)#include // HX711 Arduinolibrary

  • 5/28/2018 Arduino .pdf

    122/232

    ~ 121 ~

    HX711 (hx711_4)

    #define datapin 8 //

    #define clockpin 9 //

    HX711 hx(clockpin, datapin,128,0.0031977841); // HX711 void setup() {

    hx.set_offset(-13117.91613);

    Serial.begin(9600);

    hx.tare(50); // 50

    }

    void loop() {

    delay(500);

    double sum0 = 0;

    double sum1 = 0;

    for (int i = 0; i < 10; i++) {

    sum0 += hx.read();

    sum1 += hx.bias_read();

    }

    Serial.print((int)sum0/10); //

    Serial.print(" ");

    Serial.println((int)sum1/10); //

    }

    21 Analog to

    Digital Converters (ADC)

    21

    ADC

    0 -1398 0

    0 -1373 0

    0 -1333 0

    0 -1374 0

    100 -2820 100

    100 -2765 100100 -2829 100

  • 5/28/2018 Arduino .pdf

    123/232

    ~ 122 ~

    100 -2817 100

    100 -2827 100

    200 2297 200

    200 2238 200

    200 2295 200

    300 819 300

    300 789 300

    300 777 300

    400 -684 400

    400 -706 400

    400 -758 400

    400 -723 400500 -2198 500

    500 -2267 500

    500 -2243 500

    LCD

    Arduino sketcch

    ( 4)

    Arduino LCD 1602 LCD

    1602 HD4478062x16 LCD

    16

    ()

    LED LED

    6 Hitachi HD44780 LCD controlleris one of the most common dot matrix liquid crystal display

    (LCD) display controllers available. Hitachi developed the microcontroller specifically to drive

    alphanumeric LCD display with a simple interface that could be connected to a general purpose

    microcontroller or microprocessor

  • 5/28/2018 Arduino .pdf

    124/232

    ~ 123 ~

    37 LCD 1602

    16 22

    37 LCD1602

    22 LCD1602

    1 Ground (0V) (0V)2 Supply voltage; 5V (4.7V 5.3V) (+5V)3 Contrast adjustment; through a

    variable resistor(0-5V), 1k

    4 Selects command register when low;and data register when high

    Register Select:

    1: D0 D7

    0: D0 D7

    5 Low to write to the register; High toread from the register

    Read/Write mode:

    1: LCD

    0: LCD

    LCD

  • 5/28/2018 Arduino .pdf

    125/232

    ~ 124 ~

    I/O

    6 Sends data to data pins when a highto low pulse is given Enable

    7 Bit 0 LSB8 Bit 19 Bit 210 Bit 311 Bit 412 Bit 513 Bit 614

    8-bit data pins

    Bit 7 MSB15 Backlight VCC(5V) (330 R )16 Backlight Ground (0V) (GND)

    (Guangzhou_Tinsharp_Industrial_Corp._Ltd., 2013)

    LCD1602

    (Guangzhou_Tinsharp_Industrial_Corp._Ltd., 2013) 38

    LCD 1602 Arduino 39 LCD 1602

    Arduino LCD 1602

    LCD 1602 LiquidCrystal Library

    Arduino LiquidCrystal Library

    http://arduino.cc/en/Reference/LiquidCrystal LCD 1602

    LCD 1602

    (Guangzhou_Tinsharp_Industrial_Corp._Ltd., 2013)

    LCD 1602 4-bit 8-bit 4-bit

    I/O 4 (D4-D7)D0-D3

    LCD 1602 4

    4

  • 5/28/2018 Arduino .pdf

    126/232

    ~ 125 ~

    38 LCD 1602

    by Fritzing (Interaction_Design_Lab, 2013)

    39 LCD 1602

    by Fritzing (Interaction_Design_Lab, 2013)

  • 5/28/2018 Arduino .pdf

    127/232

    ~ 126 ~

    Arduino LiquidCrystal Library (

    Arduino LiquidCrystal Library

    http://arduino.cc/en/Reference/LiquidCrystal) LCD 1602

    Arduino LCD 1602

    LiquidCrystal LCD 1602 (lcd1602_hello)

    /*

    LiquidCrystal Library - Hello World

    Use a 16x2 LCD display The LiquidCrystal

    library works with all LCD displays that are compatible with the

    Hitachi HD44780 driver.

    This sketch prints "Hello World!" to the LCD

    and shows the time.

    */

    // include the library code:

    #include

    // initialize the library with the numbers of the interface pins

    LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //use db4-db7 as pin 5-2

    void setup() {

    // set up the LCD's number of columns and rows:

    lcd.begin(16, 2);

    // Print a message to the LCD.

    lcd.print("hello, world!");

    }

    void loop() {

    lcd.setCursor(0, 1);

    lcd.print(millis()/1000); }

    LCD 1602 LiquidCrystal

  • 5/28/2018 Arduino .pdf

    128/232

    ~ 127 ~

    LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6, d7)

    1. LiquidCrystal lcd ()

    2.

    LiquidCrystal(rs, enable, d4, d5, d6, d7)

    LiquidCrystal(rs, enable, d0, d1, d2, d3,d4, d5, d6, d7)

    LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)

    LiquidCrystal(rs, rw, enable, d0, d1, d2, d3, d4, d5, d6, d7)

    LiquidCrystal.begin(16, 2)

    1. lcd ()

    2.

    LiquidCrystal.begin(16, 2)

    lcd 16

    LiquidCrystal.setCursor(0, 1)

    1. LiquidCrystal.setCursor(,) 0 , 0

    2.

    LiquidCrystal.setCursor(0, 1)

    16

    LiquidCrystal.print()

    1. LiquidCrystal.print () char, byte, int, long, or string

  • 5/28/2018 Arduino .pdf

    129/232

    ~ 128 ~

    2.

    lcd.print("hello, world!");

    hello, world!

    LiquidCrystal.autoscroll()

    1. lcd

    2.

    lcd.autoscroll();

    lcd.print(thisChar);

    16

    LiquidCrystal - Text Direction

    print()

    LiquidCrystal.noAutoscroll()

    1. lcd

    2.

    lcd.noAutoscroll();

    lcd.print(thisChar);

    16

    print()

    16

  • 5/28/2018 Arduino .pdf

    130/232

    ~ 129 ~

    LiquidCrystal.blink()

    1. lcd

    2.

    lcd.blink();

    lcd

    LiquidCrystal.noBlink()

    1. lcd

    2.

    lcd.noBlink();

    lcd

    LiquidCrystal.cursor()

    1. lcd

    2.

    lcd.cursor();

    lcd

    LiquidCrystal.clear()

    1. lcd

    2.

  • 5/28/2018 Arduino .pdf

    131/232

    ~ 130 ~

    lcd.clear();

    lcd

    LiquidCrystal.home()

    1. lcd

    2.

    lcd.home();

    lcd

    LCD KeyPad Shield Arduinosketcch

    ( 4)

    Arduino 40 LCD

    1602 button LCD KeyPad LCD

    (DFRobot, 2013)

  • 5/28/2018 Arduino .pdf

    132/232

    ~ 131 ~

    40 LCD Keypad Shield

    (DFRobot, 2013)

    Arduino 40 LCD

    1602 (buttons) LCD Keypad Shield (DFRobot,

    2013) LCD

  • 5/28/2018 Arduino .pdf

    133/232

    ~ 132 ~

    41 LCD Keypad Shield PCB Layout

    (DFRobot, 2013)

    41 LCD Keypad Shield 40

    23

    23 LCD Keypad Shield

    Keypad Arduino D4 Arduino digital output pin 4D5 Arduino digital output pin 5D6 Arduino digital output pin 6D7 Arduino digital output pin 7

    LCD 1602

    RS Arduino digital output pin 8 Register SelectionsEnable Arduino digital output pin 9 ENABLE SIGNALA0 Arduino Analog input pin 0 Key buttons ()5V Arduino pin 5V 5V GND Arduino pin Gnd

  • 5/28/2018 Arduino .pdf

    134/232

    ~ 133 ~

    keypad shield keypad shield

    LCD 1602 (Buttons) 42

    keypad shield

    KeyPads Shield (keypad_keytest1)

    //Using LiquidCrystal library

    #include

    /*******************************************************

    This program will test the LCD panel and the buttons

    ********************************************************/

    // select the pins used on the LCD panel LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    // LiquidCrystal(rs, enable, d4, d5, d6, d7)

    // LiquidCrystal(rs, rw, enable, d4, d5, d6, d7)

    // LiquidCrystal(rs, enable, d0, d1, d2, d3, d4, d5, d6

    // define some values used by the panel and buttons

    int lcd_key = 0;

    int adc_key_in = 0;

    #define btnRIGHT 0

    #define btnUP 1

    #define btnDOWN 2

    #define btnLEFT 3

    #define btnSELECT 4

    #define btnNONE 5

    // read the buttons

    int read_LCD_buttons()

    {

    adc_key_in = analogRead(0); // read the value from the sensor

    if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed

    reasons since it will be the most likely result

    if (adc_key_in < 50) return btnRIGHT;

    if (adc_key_in < 250) return btnUP;

    if (adc_key_in < 450) return btnDOWN;

    if (adc_key_in < 650) return btnLEFT;

    if (adc_key_in < 850) return btnSELECT;

    return btnNONE; // when all others fail, return this...

  • 5/28/2018 Arduino .pdf

    135/232

    ~ 134 ~

    KeyPads Shield (keypad_keytest1)

    }

    void setup()

    {

    lcd.begin(16, 2); // start the library

    lcd.setCursor(0,0);

    lcd.print("Push the buttons"); // print the message

    }

    void loop()

    {

    lcd.setCursor(9,1); // move cursor to second line "1" and 9 spaces over

    lcd.print(millis()/1000); // display seconds elapsed since power-up

    lcd.setCursor(0,1); // move to the begining of the second line

    lcd_key = read_LCD_buttons(); // read the buttons

    switch (lcd_key) {

    case btnRIGHT:

    {

    lcd.print("RIGHT ");

    break;

    }

    case btnLEFT: {

    lcd.print("LEFT ");

    break;

    }

    case btnUP:

    {

    lcd.print("UP ");

    break; }

    case btnDOWN:

    {

    lcd.print("DOWN ");

    break;

    }

    case btnSELECT:

    {

    lcd.print("SELECT");

  • 5/28/2018 Arduino .pdf

    136/232

    ~ 135 ~

    KeyPads Shield (keypad_keytest1)

    break;

    }

    case btnNONE:

    {

    lcd.print("NONE ");

    break;

    }

    }

    }

    42 keypadshield

    LCD

    Arduinosketcch

    ( 4)

    24 LCD Keypad Shield Arduino

  • 5/28/2018 Arduino .pdf

    137/232

    ~ 136 ~

    24

    24 LCD Keypad Shield Arduino

    Keypad Arduino D4 Arduino digital output pin 4D5 Arduino digital output pin 5D6 Arduino digital output pin 6D7 Arduino digital output pin 7

    LCD 1602

    RS Arduino digital output pin 8 Register SelectionsEnable Arduino digital output pin 9 ENABLE SIGNALA0 Arduino Analog input pin 0 Key buttons ()5V Arduino pin 5V 5V GND Arduino pin Gnd

    HX711 ( 11 & 12)

    Arduino 25 HX711 Arduino

    25

    25 HX711 Arduino

    HX711 Arduino Do Rx Arduino digital output pin 10 Do/Rx Clock Arduino digital output pin 11 Ck/Tx Vcc Arduino pin 5V 5V GND Arduino pin Gnd

    (Load Cell)HX711 Arduino

    Arduino sketch

    (hx711_5)

    #include // HX711 Arduinolibrary #include

  • 5/28/2018 Arduino .pdf

    138/232

    ~ 137 ~

    (hx711_5)

    #define datapin 10 //

    #define clockpin 11 //

    HX711 hx(clockpin, datapin,128,0.0031977841); // HX711

    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    int lcd_key = 0;

    int adc_key_in = 0;

    #define btnRIGHT 0

    #define btnUP 1

    #define btnDOWN 2

    #define btnLEFT 3

    #define btnSELECT 4

    #define btnNONE 5int read_LCD_buttons()

    {

    adc_key_in = analogRead(0); // read the value from the sensor

    if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for speed

    reasons since it will be the most likely result

    if (adc_key_in < 50) return btnRIGHT;

    if (adc_key_in < 250) return btnUP;

    if (adc_key_in < 450) return btnDOWN; if (adc_key_in < 650) return btnLEFT;

    if (adc_key_in < 850) return btnSELECT;

    return btnNONE; // when all others fail, return this...

    }

    void setup() {

    hx.set_offset(-13117.91613);

    Serial.begin(9600);

    hx.tare(50); // 50

    lcd.begin(16, 2); // start the library

    lcd.setCursor(0,0);

    // lcd.print("Push the buttons"); // print a simple message

    }

    void loop() {

    int key ;

    delay(500);

    double sum0 = 0;

    double sum1 = 0;

  • 5/28/2018 Arduino .pdf

    139/232

    ~ 138 ~

    (hx711_5)

    key = checkkey();

    if (key == 11)

    {

    lcd.clear();

    lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over

    lcd.print("tare .........");

    hx.tare(50); // 50

    delay(1000);

    }

    for (int i = 0; i < 10; i++) {

    sum0 += hx.read();

    sum1 += hx.bias_read(); }

    lcd.clear();

    lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over

    lcd.print("ADC :"); // display adc value

    lcd.print((int)sum0/10); // display adc value

    lcd.print(" "); // display adc value

    lcd.print(key); // display adc value

    lcd.setCursor(0,1); // move to the begining of the second line lcd.print((int)sum1/10); //

    lcd.print(" g "); //

    lcd.print(sum1/10); //

    lcd.print(" g"); //

    Serial.print(sum0/10); //

    Serial.print(" ");

    Serial.println((int)sum1/10); //

    // checkkey();

    }

    int checkkey()

    {

    lcd_key = read_LCD_buttons(); // read the buttons

    switch (lcd_key) {

    case btnRIGHT:

    {

    return 1 ;

    break;

  • 5/28/2018 Arduino .pdf

    140/232

    ~ 139 ~

    (hx711_5)

    }

    case btnLEFT:

    {

    return 2 ;

    break;

    }

    case btnUP:

    {

    return 3 ;

    break;

    }

    case btnDOWN: {

    return 4 ;

    break;

    }

    case btnSELECT:

    {

    return 11 ;

    break; }

    case btnNONE:

    {

    return 0 ;

    break;

    }

    } }

    Arduino

    43Keypad Shield

    LCD 1602 Select

    (Tare)

  • 5/28/2018 Arduino .pdf

    141/232

    ~ 140 ~

    43

    (Analog Sensor)

    (Analog Sensor) Arduino 10

    (Analog to Digital Convert)

    24 (Analog to Digital Convert)

    HX711(, 2013)

    HX711 ( 11 12)

    (Analog Sensor)

    [email protected] ([email protected], 2013)

    Arduino HX711(AD Convert)

  • 5/28/2018 Arduino .pdf

    142/232

    ~ 141 ~

  • 5/28/2018 Arduino .pdf

    143/232

    ~ 142 ~

  • 5/28/2018 Arduino .pdf

    144/232

    ~ 143 ~

    e

  • 5/28/2018 Arduino .pdf

    145/232

    ~ 144 ~

    (Internal Clock)

    Arduino

    Arduino (Tx/Rx),

    Arduino http://arduino.cc/en/Reference/SoftwareSerial

    Arduoino

    Arduino

    Arduino SoftwareSerial Library

    1.

    2. Mega and Mega 2560

    RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8

    (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).

  • 5/28/2018 Arduino .pdf

    146/232

    ~ 145 ~

    3. Leonardo

    RX: 8, 9, 10, 11, 14 (MISO), 15 (SCK), 16 (MOSI).

    (Uart_test1)

    /*

    Software serial multple serial test

    The circuit: * RX is digital pin 10 (connect to TX of other device)

    * TX is digital pin 11 (connect to RX of other device)

    Not all pins on the Mega and Mega 2560 support change interrupts,

    so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53,62, 63, 64, 65, 66, 67, 68, 69

    Not all pins on the Leonardo support change interrupts,

    so only the following can be used for RX: 8, 9, 10, 11, 14 (MISO), 15

    (SCK), 16 (MOSI).

    */

    #include

    #define RXPin 5

    #define TXPin 6

    SoftwareSerial mySerial(RXPin, TXPin); // RX, TX

    void setup()

    {

    // Open serial communications and wait for port to open:

    Serial.begin(9600);

    Serial.println("Goodnight moon!");

    // set the data rate for the SoftwareSerial port

    mySerial.begin(9600);

    mySerial.println("Hello, world?");

    }

    void loop() // run over and over

    {

    if (mySerial.available())

    Serial.write(mySerial.read());

    if (Serial.available())

    mySerial.write(Serial.read());

    }

  • 5/28/2018 Arduino .pdf

    147/232

    ~ 146 ~

    Arduino (Uart)

    (Crowe, et al., 1988, Gulick, et al., 1990, Gulick, et al., 1993, Michael, 1989,

    Michael, 1993, Michael, 1995, Michael, 1996, Michael, 1999, Story, et al., 1998,

    Takahashi and Ibuka, 1998)(Method)

    SoftwareSerial(rxPin, txPin))

    SoftwareSerial mySerial = SoftwareSerial(rxPin,

    txPin);( Uart mySerial,(rxPin, txPin)

    SoftwareSerial(rxPin, txPin)

    SoftwareSerial.begin(speed)

    (baud rate) 300, 600, 1200, 2400, 4800, 9600,

    14400, 19200, 28800, 31250, 38400, 57600, and 115200 9600 bps(bit per

    second)

    SoftwareSerial.begin(9600)

    9600 bps( 9600 )

    SoftwareSerial.available()

    (Rx)(Bytes)

    if (SoftwareSerial: available() > 0) //

    data = SoftwareSerial.read() ; //

    endif

    ,(

  • 5/28/2018 Arduino .pdf

    148/232

    ~ 147 ~

    )

    SoftwareSerial.isListening()

    if (SoftwareSerial: isListening > 0) //

    Serial.println("Port One is listening!"); //

    endif

    SoftwareSerial.print(data)

    SoftwareSerial.println(data)

    Tx

    SoftwareSerial: println("Hello World:) ; // Hello World

    Hello World Tx

    SoftwareSerial.read()

    (Bytes)

    if (SoftwareSerial: available() > 0) //

    data = SoftwareSerial.read() ; //

    endif

    (Bytes)

    SoftwareSerial.write(Byte Data)

    (Bytes)(Tx)

    SoftwareSerial.write(byte) ; // byte (Tx)

    endif

  • 5/28/2018 Arduino .pdf

    149/232

    ~ 148 ~

    (Bytes)(Tx)

    SoftwareSerial.peek()

    (Rx)(Bytes)

    peek()

    if (SoftwareSerial: available() > 0) //

    data = SoftwareSerial.peek() ; //

    endif

    (Rx)(Bytes)

    peek()

    SoftwareSerial.overflow()

    true

    ( false)

    if (SoftwareSerial.overflow()) //

    Serial.println("SoftwareSerial overflow!"); //

    endif

    true

    ( false)

    Uart_test1 & HX711_5

    HX711_6()USBTTL( 44) Arduino

  • 5/28/2018 Arduino .pdf

    150/232

    ~ 149 ~

    Com277(

    )(USB TTL ( 44))

    putty8(Tatham, 2013) ( Simon

    Tatham ).

    http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html

    45 45 Arduino

    HX711_6( Tx/Rx )

    #include // HX711Arduino library

    #include

    #include

    #define datapin 10 //

    #define clockpin 11 //

    #define RXPin 2 // Rx pin

    #define TXPin 3 // Tx pinHX711 hx(clockpin, datapin,128,0.0031977841); // HX711

    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    SoftwareSerial mySerial(RXPin, TXPin); // RX, TX

    int lcd_key = 0;

    int adc_key_in = 0;

    #define btnRIGHT 0

    #define btnUP 1#define btnDOWN 2

    #define btnLEFT 3

    #define btnSELECT 4

    #define btnNONE 5

    int read_LCD_buttons()

    7

    8

    PuTTYTelnetSSHrloginTCPPuTTY Simon TathamMIT licence

  • 5/28/2018 Arduino .pdf

    151/232

    ~ 150 ~

    HX711_6( Tx/Rx )

    {

    adc_key_in = analogRead(0); // read the value from the sensor

    if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for

    speed reasons since it will be the most likely result

    if (adc_key_in < 50) return btnRIGHT;

    if (adc_key_in < 250) return btnUP;

    if (adc_key_in < 450) return btnDOWN;

    if (adc_key_in < 650) return btnLEFT;

    if (adc_key_in < 850) return btnSELECT;

    // For V1.0 comment the other threshold and use the one below:

    return btnNONE; // when all others fail, return this...

    }

    void setup() {

    hx.set_offset(-13117.91613);

    Serial.begin(9600);

    mySerial.begin(9600);

    hx.tare(50); // 50

    lcd.begin(16, 2); // start the library

    lcd.setCursor(0,0);

    // lcd.print("Push the buttons"); // print a simple message}

    void loop() {

    int key ;

    delay(500);

    double sum0 = 0;

    double sum1 = 0;

    key = checkkey();

    if (key == 11){

    lcd.clear();

    lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over

    lcd.print("tare .........");

    hx.tare(50); // 50

    delay(1000);

    }

    for (int i = 0; i < 10; i++) {

    sum0 += hx.read();

  • 5/28/2018 Arduino .pdf

    152/232

    ~ 151 ~

    HX711_6( Tx/Rx )

    sum1 += hx.bias_read();

    }

    lcd.clear();

    lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over

    lcd.print("ADC :"); // display adc value

    lcd.print((int)sum0/10); // display adc value

    lcd.print(" "); // display adc value

    lcd.print(key); // display adc value

    lcd.setCursor(0,1); // move to the begining of the second line

    lcd.print((int)sum1/10); //

    lcd.print(" g "); //

    lcd.print(sum1/10); //lcd.print(" g"); //

    Serial.print(sum0/10); //

    Serial.print(" ");

    Serial.println((int)sum1/10); //

    mySerial.print(sum0/10); //

    mySerial.print(" ");

    mySerial.println((int)sum1/10); //

    // checkkey();}

    int checkkey()

    {

    lcd_key = read_LCD_buttons(); // read the buttons

    switch (lcd_key) // depending on which button was pushed, we perform an

    action

    {

    case btnRIGHT:{

    return 1 ;

    break;

    }

    case btnLEFT:

    {

    return 2 ;

    break;

    }

  • 5/28/2018 Arduino .pdf

    153/232

    ~ 152 ~

    HX711_6( Tx/Rx )

    case btnUP:

    {

    return 3 ;

    break;

    }

    case btnDOWN:

    {

    return 4 ;

    break;

    }

    case btnSELECT:

    {

    return 11 ;

    break;

    }

    case btnNONE:

    {

    return 0 ;

    break;

    }}

    }

  • 5/28/2018 Arduino .pdf

    154/232

    ~ 153 ~

    44 USB TTL

    45

    45

  • 5/28/2018 Arduino .pdf

    155/232

    ~ 154 ~

    HX711_7 newflag

    oldWht

    HX711_7( Tx/Rx )

    #include // HX711rduino library

    #include

    #include

    #define datapin 10

    #define clockpin 11

    #define RXPin 2 // Rx pin

    #define TXPin 3 // Tx pin

    //------define key button ------

    #define btnRIGHT 0

    #define btnUP 1

    #define btnDOWN 2

    #define btnLEFT 3

    #define btnSELECT 4

    #define btnNONE 5

    //------define key button ------

    int lcd_key = 0 ;

    int adc_key_in = 0 ;

    double sum0 = 0 ;

    double sum1 = 0 ;

    int newflag = 0 ;

    int oldWht = 0 ;

    HX711 hx(clockpin, datapin,128,0.0031977841);LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

  • 5/28/2018 Arduino .pdf

    156/232

    ~ 155 ~

    HX711_7( Tx/Rx )

    SoftwareSerial mySerial(RXPin, TXPin); // RX, TX

    void setup() {

    // int oldWht;

    hx.set_offset(-13117.91613);

    Serial.begin(9600);

    mySerial.begin(9600);

    hx.tare(50);

    lcd.begin(16, 2); // start the library

    lcd.setCursor(0,0);

    // lcd.print("Push the buttons");

    // print a simple message

    sum0 = 0;

    sum1 = 0;

    for (int i = 0; i < 10; i++)

    {

    sum0 += hx.read();

    sum1 += hx.bias_read();}

    oldWht = sum1/10 ;

    newflag = 0 ;

    }

    void loop() {

    int tmpno = 0 ;

    int key ;key = checkkey();

    if (key == 11)

    {

    lcd.clear();

    lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over

    lcd.print("tare .........");

    hx.tare(50);

    delay(1000);

    }

  • 5/28/2018 Arduino .pdf

    157/232

    ~ 156 ~

    HX711_7( Tx/Rx )

    sum0 = 0;

    sum1 = 0;

    for (int i = 0; i < 10; i++)

    {

    sum0 += hx.read();

    sum1 += hx.bias_read();

    }

    tmpno = (int)sum1/10 ;

    lcd.clear();

    lcd.setCursor(0,0);

    lcd.print("ADC :");

    lcd.print((int)sum0/10);

    lcd.print(" ");

    lcd.print(key);

    lcd.setCursor(0,1);

    lcd.print((int)sum1/10); \

    lcd.print(" g ");

    lcd.print(sum1/10);

    lcd.print(" g");Serial.print(sum0/10);

    Serial.print(" ");

    Serial.println((int)sum1/10);

    if( (tmpno> 0) && (tmpno != oldWht) )

    {

    newflag = 1 ;

    }

    else{

    newflag = 0 ;

    }

    if ( newflag == 1)

    {

    mySerial.print(tmpno) ;

    mySerial.println("g") ;

    oldWht = tmpno ;

    }

  • 5/28/2018 Arduino .pdf

    158/232

    ~ 157 ~

    HX711_7( Tx/Rx )

    // checkkey();

    delay(500);

    }

    int read_LCD_buttons()

    {

    adc_key_in = analogRead(0); // read the value from the sensor

    if (adc_key_in > 1000) return btnNONE; // We make this the 1st option for

    speed reasons since it will be the most likely result

    if (adc_key_in < 50) return btnRIGHT;

    if (adc_key_in < 250) return btnUP;

    if (adc_key_in < 450) return btnDOWN;

    if (adc_key_in < 650) return btnLEFT;

    if (adc_key_in < 850) return btnSELECT;

    // For V1.0 comment the other threshold and use the one below:

    return btnNONE; // when all others fail, return this...

    }

    int checkkey()

    {

    lcd_key = read_LCD_buttons(); // read the buttons

    switch (lcd_key) // depending on which button was pushed, we perform an

    action

    {

    case btnRIGHT:

    {return 1 ;

    break;

    }

    case btnLEFT:

    {

    return 2 ;

    break;

    }

    case btnUP:

  • 5/28/2018 Arduino .pdf

    159/232

    ~ 158 ~

    HX711_7( Tx/Rx )

    {

    return 3 ;

    break;

    }

    case btnDOWN:

    {

    return 4 ;

    break;

    }

    case btnSELECT:

    {

    return 11 ;

    break;

    }

    case btnNONE:

    {

    return 0 ;

    break;

    }

    }}

    46

  • 5/28/2018 Arduino .pdf

    160/232

    ~ 159 ~

    46

    Arduino

    Arduino (Internal Clock)

    Arduino Tiny RTC I2C 47

    Tiny RTC I2C DS1307

    DS1307 (Jeelab, 2013) Tiny RTC

    I2C (DS1307_test1) Arduino

  • 5/28/2018 Arduino .pdf

    161/232

    ~ 160 ~

    47 Tiny RTC I2C

    DS1307_test1(Tiny RTC I2C )

    // Date and time functions using a DS1307 RTC connected via I2C and Wire

    lib

    #include

    #include "RTClib.h"

    RTC_DS1307 RTC;

    void setup () {

    Serial.begin(9600);

    Wire.begin();

    RTC.begin();

    Serial.print("System Date Time:(");

    Serial.print(__DATE__);

    Serial.print("^");

    Serial.print(__TIME__);

    Serial.println(")");

    if (! RTC.isrunning()) {

    Serial.println("RTC is NOT running!");

    Serial.print("(");

    Serial.print(__DATE__);

    Serial.print("^");

    Serial.print(__TIME__);

    Serial.println(")");// following line sets the RTC to the date & time this sketch was compiled

  • 5/28/2018 Arduino .pdf

    162/232

    ~ 161 ~

    DS1307_test1(Tiny RTC I2C )

    RTC.adjust(DateTime(__DATE__, __TIME__));

    }

    }

    void loop () {

    DateTime now = RTC.now();

    Serial.print(now.year(), DEC);

    Serial.print('/');

    Serial.print(now.month(), DEC);

    Serial.print('/');

    Serial.print(now.day(), DEC);

    Serial.print(' ');

    Serial.print(now.hour(), DEC);

    Serial.print(':');

    Serial.print(now.minute(), DEC);

    Serial.print(':');

    Serial.print(now.second(), DEC);

    Serial.println();

    Serial.print(" since midnight 1/1/1970 = ");Serial.print(now.unixtime());

    Serial.print("s = ");

    Serial.print(now.unixtime() / 86400L);

    Serial.println("d");

    // calculate a date which is 7 days and 30 seconds into the future

    DateTime future (now.unixtime() + 7 * 86400L + 30);

    Serial.print(" now + 7d + 30s: ");

    Serial.print(future.year(), DEC);Serial.print('/');

    Serial.print(future.month(), DEC);

    Serial.print('/');

    Serial.print(future.day(), DEC);

    Serial.print(' ');

    Serial.print(future.hour(), DEC);

    Serial.print(':');

    Serial.print(future.minute(), DEC);

    Serial.print(':');

  • 5/28/2018 Arduino .pdf

    163/232

    ~ 162 ~

    DS1307_test1(Tiny RTC I2C )

    Serial.print(future.second(), DEC);

    Serial.println();

    Serial.println();

    delay(1000);

    }

    Arduino

    ( Arduino

    )

    (HX711_8) 48

    (Rx/Tx) RS232 (Rx/Tx) RS485

    e

    HX711_8()

    #include // HX711rduino library

    #include

    #include

    #include

    #include "RTClib.h"

  • 5/28/2018 Arduino .pdf

    164/232

    ~ 163 ~

    HX711_8()

    #define datapin 10

    #define clockpin 11

    #define RXPin 2 // Rx pin

    #define TXPin 3 // Tx pin

    //------define key button ------

    #define btnRIGHT 0

    #define btnUP 1

    #define btnDOWN 2

    #define btnLEFT 3

    #define btnSELECT 4

    #define btnNONE 5

    //------define key button ------

    int lcd_key = 0 ;

    int adc_key_in = 0 ;

    double sum0 = 0 ;

    double sum1 = 0 ;

    int newflag = 0 ;

    int oldWht = 0 ;char datetimestr1[24];

    HX711 hx(clockpin, datapin,128,0.0031977841);

    LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

    SoftwareSerial mySerial(RXPin, TXPin); // RX, TX

    RTC_DS1307 RTC; //init RTC

    void setup() {// int oldWht;

    hx.set_offset(-13117.91613);

    Serial.begin(9600);

    mySerial.begin(9600);

    Wire.begin(); // ds1307

    RTC.begin(); // lauch RTC

    hx.tare(50);

    lcd.begin(16, 2); // start the library

  • 5/28/2018 Arduino .pdf

    165/232

    ~ 164 ~

    HX711_8()

    lcd.setCursor(0,0);

    sum0 = 0;

    sum1 = 0;

    oldWht = 0 ; //

    newflag = 0 ; //

    }

    void loop() {

    int tmpno = 0 ;

    int key ;

    key = checkkey();

    if (key == 11)

    {

    lcd.clear();

    lcd.setCursor(0,0); // move cursor to second line "1" and 9 spaces over

    lcd.print("tare .........");

    hx.tare(50);

    oldWht = 0 ;

    newflag = 0 ;

    delay(200);}

    sum0 = 0;

    sum1 = 0;

    for (int i = 0; i < 10; i++)

    {

    sum0 += hx.read();

    sum1 += hx.bias_read();

    }tmpno = (int)sum1/10 ;

    lcd.clear();

    lcd.setCursor(0,0);

    lcd.print("ADC :");

    lcd.print((int)sum0/10);

    lcd.print(" ");

    lcd.print(key);

    lcd.setCursor(0,1);

  • 5/28/2018 Arduino .pdf

    166/232

    ~ 165 ~

    HX711_8()

    lcd.print((int)sum1/10); \

    lcd.print(" g ");

    lcd.print(sum1/10);

    lcd.print(" g");

    Seria