Tutorial by dfsdf224s

VIEWS: 13 PAGES: 34

									  Tutorial
Arduino Beginner Kit
                                LED Lesson

Introduction

Starting from a simple LED, this lesson gives the very basic introduction about
Arduino.

Part List

   •   DFRduio Duemilanove or Compatible Arduino Controller (1 unit)
   •   Green/Red/Yellow LED (1 unit)
   •   Resistor-220 ohm (1 unit)
   •   Prototyping Shield (1 unit)
   •   Mini Breadboard (1 unit)
   •   Jumper Cables (2 units)
Connection Diagram
Sample Code

//For Arduino Start kit

//Compatible with all Arduino version

//Last updated 2010-12-1

//www.dfrobot.com

int ledPin=8; //Connect led to Digital Pin 8

void setup()

{

    pinMode(ledPin,OUTPUT);//Set ledPin as output

}

void loop()

{

    digitalWrite(ledPin,HIGH); //Pull ledPin to high

    delay(1000); //Delay 1 second

    digitalWrite(ledPin,LOW); //Pull ledPin to low

    delay(1000); //Delay 1 second

}
                              Buzzer Lesson

Part List

   •   DFRduio Duemilanove or Compatible Arduino Controller (1 unit)
   •   Buzzer (1 unit)
   •   Prototyping Shield (1 unit)
   •   Mini Breadboard (1 unit)
   •   Jumper Cables (2 units)
Connection Diagram
Sample Code

//For Arduino Start kit

//Compatible with all Arduino version

//Last updated 2011-1-13

//www.dfrobot.com

int buzzer=8;//Connect the buzz positive Pin to Digital Pin 8

void setup()

{

    pinMode(buzzer,OUTPUT);//Set Pin Mode as output

}

void loop()

{

    unsigned char i,j;

    while(1)

    {

        for(i=0;i<80;i++) //Sound effect 1

        {

            digitalWrite(buzzer,HIGH);//Make some sound

            delay(1);//Delay 1ms

            digitalWrite(buzzer,LOW);//Be quiet

            delay(1);//Delay 1ms

        }

        for(i=0;i<100;i++) //Sound effect 2

        {
            digitalWrite(buzzer,HIGH);//Make some sound

            delay(2);//Delay 2ms

            digitalWrite(buzzer,LOW);//Be quiet

            delay(2);//Delay 2ms

        }

    }

}
                         Segment Display Lesson

Introduction




Part List

   •   DFRduio Duemilanove or Compatible Arduino Controller (1 unit)
   •   7 Segment Display (1 unit)
   •   Resistor-220 om (8 units)
   •   Prototyping Shield (1 unit)
   •   Mini Breadboard (1 unit)
   •   Jumper Cables (9 units)
Connection Diagram
Sample Code

//For Arduino Start kit

//Compatible with all Arduino version

//Last updated 2011-1-13

//www.dfrobot.com

//7 segment Display Lesson

//The LED Display has a common anode

//Define the Pinout of 7 segment display

int a=7;

int b=6;

int c=5;

int d=11;

int e=10;

int f=8;

int g=9;

int dp=4;

//Display Number 1

void digital_1(void)

{

    unsigned char j;

    digitalWrite(c,LOW);//Set C Segment to low which lights this segment

    digitalWrite(b,LOW);//Set B Segment to low which lights this segment

    for(j=7;j<=11;j++)//Set the rest Segments to high which turn off this segment.

     digitalWrite(j,HIGH);
 digitalWrite(dp,HIGH);//Turn off DP segment (the little dot on the right down
part)

}

//Display Number 2

void digital_2(void)

{

    unsigned char j;

    digitalWrite(b,LOW);

    digitalWrite(a,LOW);

    for(j=9;j<=11;j++)

     digitalWrite(j,LOW);

    digitalWrite(dp,HIGH);

    digitalWrite(c,HIGH);

    digitalWrite(f,HIGH);

}

//Display Number 3

void digital_3(void)

{

    unsigned char j;

    digitalWrite(g,LOW);

    digitalWrite(d,LOW);

    for(j=5;j<=7;j++)

     digitalWrite(j,LOW);

    digitalWrite(dp,HIGH);

    digitalWrite(f,HIGH);

    digitalWrite(e,HIGH);
}

//Display Number 4

void digital_4(void)

{

    digitalWrite(c,LOW);

    digitalWrite(b,LOW);

    digitalWrite(f,LOW);

    digitalWrite(g,LOW);

    digitalWrite(dp,HIGH);

    digitalWrite(a,HIGH);

    digitalWrite(e,HIGH);

    digitalWrite(d,HIGH);

}

//Display Number 5

void digital_5(void)

{

    unsigned char j;

    for(j=7;j<=9;j++)

     digitalWrite(j,LOW);

    digitalWrite(c,LOW);

    digitalWrite(d,LOW);

    digitalWrite(dp,HIGH);

    digitalWrite(b,HIGH);

    digitalWrite(e,HIGH);

}
//Display Number 6

void digital_6(void)

{

    unsigned char j;

    for(j=7;j<=11;j++)

     digitalWrite(j,LOW);

    digitalWrite(c,LOW);

    digitalWrite(dp,HIGH);

    digitalWrite(b,HIGH);

}

//Display Number 7

void digital_7(void)

{

    unsigned char j;

    for(j=5;j<=7;j++)

     digitalWrite(j,LOW);

    digitalWrite(dp,HIGH);

    for(j=8;j<=11;j++)

     digitalWrite(j,HIGH);

}

//Display Number 8

void digital_8(void)

{

    unsigned char j;

    for(j=5;j<=11;j++)
        digitalWrite(j,LOW);

    digitalWrite(dp,HIGH);

}

void setup()

{

    int i;//Set Pin Mode as output

    for(i=4;i<=11;i++)

        pinMode(i,OUTPUT);

}

void loop()

{

    while(1)

    {

        digital_1();//Display Number 1

        delay(2000);//Delay 2 seconds

        digital_2();

        delay(2000);

        digital_3();

        delay(2000);

        digital_4();

        delay(2000);

        digital_5();

        delay(2000);

        digital_6();

        delay(2000);
        digital_7();

        delay(2000);

        digital_8();

        delay(2000);

    }

}
                           Button Control Lesson

Introduction




Part List

   •   DFRduio Duemilanove or Compatible Arduino Controller (1 unit)
   •   Green/Red/Yellow LED (1 unit)
   •   Mini Button (1 unit)
   •   Resistor-220 ohm (1 unit)
   •   Prototyping Shield (1 unit)
   •   Mini Breadboard (1 unit)
   •   Jumper Cables (2 units)
Connection Diagram
Sample Code

//For Arduino Start kit

//Compatible with all Arduino version

//Last updated 2011-1-13

//www.dfrobot.com

//Button Control Lesson

int light=7;//Connect the led to Digital Pin 7

void setup()

{

    pinMode(light,OUTPUT);//Set the Pinmode to output

}

void loop()

{

    int i;

    while(1)

    {

        i=analogRead(0);//Connect the button to analog pin 0

        if(i>512)//If the analog read is over 512 which is 2.5V

         digitalWrite(light,HIGH);//Turn on the led

        else

         digitalWrite(light,LOW);//Turn off the led

    }

}
                     Tilt Sensor Lesson

Connection Diagram
Sample Code

//For Arduino Start kit

//Compatible with all Arduino version

//Last updated 2011-1-14

//www.dfrobot.com

//Tilt Sensor Control Lesson

    int light=8;//Connect the led to Digital Pin 8

void setup()

{

     pinMode(light,OUTPUT);//C

}

void loop()

{

     int i;

     while(1)

     {

         i=analogRead(5);//Read Analog Pin 5 which connect to Tilt Sensor

         if(i>200)// if reading is over 200 1V (When you tilt the tilt sensor)

         {

             digitalWrite(light,HIGH);//Turn on led

         }

         else

         {

             digitalWrite(light,LOW);//Turn off led
        }

    }

}
Light Sensor Lesson
Connection Diagram
Code Sample

//For Arduino Start kit

//Compatible with all Arduino version

//Last updated 2011-1-13

//www.dfrobot.com

//Light Control Sound Lesson

void setup()

{

    pinMode(6,OUTPUT);

}

void loop()

{

    while(1)

    {

        char i,j;

    while(1)

    {

        for(i=0;i<80;i++)   //Make some sound

        {

        digitalWrite(6,HIGH);

        delay(1);

        digitalWrite(6,LOW);

        delay(1);

        }
        for(i=0;i<100;i++) //Make another sound

        {

        digitalWrite(6,HIGH);

        delay(2);

        digitalWrite(6,LOW);

        delay(2);

        }

    }

    }

}
                     Temperature Sensor Lesson

Connection Diagram
Sample Code

//For Arduino Start kit

//Compatible with all Arduino version

//Last updated 2011-1-13

//www.dfrobot.com

//Temperature Control Led Lesson

#define LED_GREEN 9//Connect Green Led to Digital Pin 9

#define LED_YELLOW 10//Connect Yellow Led to Digital Pin 10

#define LED_RED 11//Connect Red Led to Digital Pin 11

void setup()

{

    unsigned char j;

    for(j=9;j<=11;j++)//Set the led pin as output mode

    {

        pinMode(j,OUTPUT);

    }

}

void loop()

{

    int i;

    while(1)

    {

        i=analogRead(0);//Read temperature on Analog 0

        if(i>41&&i<61)//if the temperature is between 20-30

        {
            digitalWrite(LED_GREEN,HIGH);//Turn on Green led

            digitalWrite(LED_YELLOW,LOW);//Turn off Yellow led

            digitalWrite(LED_RED,LOW);//Turn off Red led

        }

        else if(i>=61&&i<81)//if the temperature is between 30~40

        {

            digitalWrite(LED_YELLOW,HIGH);//Turn on Yellow led

            digitalWrite(LED_GREEN,LOW);//Turn off Green led

            digitalWrite(LED_RED,LOW);//Turn off Red led

        }

        else//if the temperature is below 20 and over 40

             {

            digitalWrite(LED_RED,HIGH);//turn on Red led

            digitalWrite(LED_YELLOW,LOW);//Turn off yellow led

            digitalWrite(LED_GREEN,LOW);//Turn off green led

        }

    }

}
                        IR Remote Control Lesson

Part List

   •   DFRduio Duemilanove or Compatible Arduino Controller (1 unit)
   •   IR Receiver Unit (1 unit)
   •   Resistor-220 ohm (1 units)
   •   Prototyping Shield (1 unit)
   •   Mini Breadboard (1 unit)
   •   Jumper Cables (7 units)
Connection Diagram

								
To top