module

19
ARDUINO’S MODULE What is Arduino? Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. It's an open-source physical computing platform based on a simple microcontroller board, and a development environment for writing software for the board. Arduino can be used to develop interactive objects, taking inputs from a variety of switches or sensors, and controlling a variety of lights, motors, and other physical outputs. Arduino projects can be stand-alone, or they can communicate with software running on your computer (e.g. Flash, Processing, MaxMSP.) The boards can be assembled by hand or purchased preassembled; the open-source IDE can be downloaded for free. Why Arduino? 1. Inexpensive – assembled by hand or pre-assembled 2. Cross-platform – Microsoft, Macintosh, Linux OS 3. Simple-clear programming environment – Processing, IDE 4. Open source and extensible software – the language expanded through C++ 5. Open source and extensible hardware – extending the microcontroller board

Upload: atheerahfarah

Post on 18-Dec-2015

14 views

Category:

Documents


2 download

DESCRIPTION

Arduino

TRANSCRIPT

  • ARDUINOS MODULE

    What is Arduino? Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. It's an open-source physical computing platform based on a simple microcontroller board, and a development environment for writing software for the board. Arduino can be used to develop interactive objects, taking inputs from a variety of switches or sensors, and controlling a variety of lights, motors, and other physical outputs. Arduino projects can be stand-alone, or they can communicate with software running on your computer (e.g. Flash, Processing, MaxMSP.) The boards can be assembled by hand or purchased preassembled; the open-source IDE can be downloaded for free.

    Why Arduino?

    1. Inexpensive assembled by hand or pre-assembled 2. Cross-platform Microsoft, Macintosh, Linux OS 3. Simple-clear programming environment Processing, IDE 4. Open source and extensible software the language expanded through C++ 5. Open source and extensible hardware extending the microcontroller board

  • Arduinos Family

    UNO

    Leonardo

    Due

    Yun

    Mega ADK

    Mega 2560

    Ethernet

    Esplora

    Nano

    Pro Mini

    Lilypad

    Lilypad Simple

  • Inside this KIT (Check your kit)

    Arduino UNO R3

    Jumper wire

    Red LED

    Resistor 330ohm

    Buzzer

    Yellow LED

    Button

    Photoresistor

    Green LED

    Temperature Sensor (LM35)

    Potentiometer

    RGB

    Relay

    Transistor P2N2222

    LCD 1602

    Servo motor

  • Arduino UNO

    Summary Microcontroller ATmega328 Operating Voltage 5V Input Voltage (recommended) 7-12V Input Voltage (limits) 6-20V Digital I/O Pins 14 (of which 6 provide PWM output) Analog Input Pins 6 DC Current per I/O Pin 40 mA DC Current for 3.3V Pin 50 mA Flash Memory 32 KB (ATmega328) of which 0.5 KB used by bootloader SRAM 2 KB (ATmega328) EEPROM 1 KB (ATmega328) Clock Speed 16 MHz

    Each of the 14 digital pins

    It operates at 5 volts.

    Each pin can provide or receive a maximum of 40 mA

    Serial: 0 (RX) and 1 (TX). Used to receive (RX) and transmit (TX) TTL serial data.

    PWM: 3, 5, 6, 9, 10, and 11. Provide 8-bit PWM output with the analogWrite() function.

    SPI: 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK).

    LED: 13. There is a built-in LED connected to digital pin 13. When the pin is HIGH value, the LED is on, when the pin is LOW, it's off.

    The Uno has 6 analog inputs, labeled A0 through A5, each of which provide 10 bits of resolution

    Digital Pin

    Analog Pin

    Power Input

  • TWI: A4 or SDA pin and A5 or SCL pin. Support TWI communication using the Wire library.

    AREF. Reference voltage for the analog inputs.

    Reset. Bring this line LOW to reset the microcontroller.

    Breadboard

    Ground (gnd)

    Voltage (vcc)

  • Integrated Development Environment (IDE) 1. Download from http://arduino.cc/en/Main/Software 2. Choose your version and OS, whether Classic (1.0.5) or Beta (1.5.7) and Microsoft or

    Macintosh X or Linux. 3. Install Done 4. Connect your UNO via USB cable given 5. Check your UNO port from Windows > Devices and Printers > Unspecified 6. Click your Arduino IDE icon 7. IDE display (figure below)

    8. Select the right board and port Tools > Board > Arduino UNO and Tools > Port > COM1

    Verify

    Upload

    New

    Open

    Save

  • 9. Start upload the code, go to (File > Examples > 01.Basics > Blink) then click upload

    10. You can see that LED will be blinking

    11. Now you can start do the tutorial given below, Enjoy it !

  • BLINK LED Led blinking 1 second (1 second ON, 1 second OFF, then repeat) Parts required

    1. Red LED x 1 2. Resistor 330ohm x 1 3. Jumper wires

    //Coding = File > Examples > Basics > Blink int led = 13; // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(led, OUTPUT); } // the loop routine runs over and over again forever: void loop() { digitalWrite(led, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(led, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }

    PUSH BUTTON Parts required

    1. Push button x 1 2. Resistor 330ohm x 1 3. Resistor 10kohm x 1 4. Jumper wires

    +

    -

  • //Coding = File > Examples > Digital > Button const int buttonPin = 8; // the number of the pushbutton pin const int ledPin = 13; // the number of the LED pin // variables will change: int buttonState = 0; // variable for reading the pushbutton status void setup() { // initialize the LED pin as an output: pinMode(ledPin, OUTPUT); // initialize the pushbutton pin as an input: pinMode(buttonPin, INPUT); } void loop(){ // read the state of the pushbutton value: buttonState = digitalRead(buttonPin); // check if the pushbutton is pressed. // if it is, the buttonState is HIGH: if (buttonState == HIGH) { // turn LED on: digitalWrite(ledPin, HIGH); } else { // turn LED off: digitalWrite(ledPin, LOW); } }

    BUZZER Create the melody using the coding given. Make the tone faster and slower. Parts required

    1. Buzzer

  • 2. Jumper wires

    //Coding = File > Example > Digital > toneMelody #include "pitches.h" // notes in the melody: int melody[] = { NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4}; // note durations: 4 = quarter note, 8 = eighth note, etc.: int noteDurations[] = { 4, 8, 8, 4,4,4,4,4 }; void setup() { // iterate over the notes of the melody: for (int thisNote = 0; thisNote < 8; thisNote++) { // to calculate the note duration, take one second // divided by the note type. //e.g. quarter note = 1000 / 4, eighth note = 1000/8, etc. int noteDuration = 1000/noteDurations[thisNote]; tone(2, melody[thisNote],noteDuration); // to distinguish the notes, set a minimum time between them. // the note's duration + 30% seems to work well: int pauseBetweenNotes = noteDuration * 1.30; delay(pauseBetweenNotes); // stop the tone playing: noTone(2); } } void loop() { // no need to repeat the melody. }

  • PHOTORESISTOR Parts required

    1. Red led x 1 2. Photoresistor x 1 3. Resistor 330ohm x 1 4. Resistor 10kohm x 1 5. Jumper wires

    //photoresistor

    int photoPin = 1; // select the input pin for the photoresistor

    int ledPin = 13; // select the pin for the LED

    int val; // variable to store the value coming from the sensor

    void setup() {

    Serial.begin(9600);

    pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT

    }

    void loop() {

    val = analogRead(photoPin); // read the value from the sensor

    Serial.println(val);

    //val=map(val, 0, 1023,0, 255); // val=map(variable, min, max,0, 255);

    analogWrite(ledPin, val); // turn the ledPin brightness

    }

    POTENTIOMETER Control the LED brightness Parts required

    1. Potentiometer x 1 2. Red LED 3. Jumper wire

  • //potentiometer

    int potPin = 0; // select the input pin for the potentiometer

    int ledPin = 11; // select the pin for the LED

    int val = 0; // variable to store the value coming from the sensor

    void setup() {

    Serial.begin(9600);

    pinMode(ledPin, OUTPUT); // declare the ledPin as an OUTPUT

    }

    void loop() {

    val = analogRead(potPin); // read the value from the sensor

    Serial.println(val);

    val=map(val, 0, 1023,0, 255);

    analogWrite(ledPin, val); // turn the ledPin brightness

    }

    RGB Parts required

    1. RGB 2. Resistor 330ohm 3. Jumper wires

  • //Coding int ledcolor = 0; int a = 1000; //this sets how long the stays one color for int red = 11; //this sets the red led pin int green = 10; //this sets the green led pin int blue = 9; //this sets the blue led pin void setup() { //this sets the output pins pinMode(red, OUTPUT); pinMode(green, OUTPUT); pinMode(blue, OUTPUT); } void loop() { int ledcolor = random(7); //this randomly selects a number between 0 and 6 switch (ledcolor) { case 0: //if ledcolor equals 0 then the led will turn red analogWrite(red, 51); delay(a); analogWrite(red, 255); break; case 1: //if ledcolor equals 1 then the led will turn green digitalWrite(green, LOW); delay(a); digitalWrite(green, HIGH); break; case 2: //if ledcolor equals 2 then the led will turn blue digitalWrite(blue, LOW); delay(a); digitalWrite(blue, HIGH); break; case 3: //if ledcolor equals 3 then the led will turn yellow analogWrite(red, 95); digitalWrite(green, LOW); delay(a); analogWrite(red, 255); digitalWrite(green, HIGH); break; case 4: //if ledcolor equals 4 then the led will turn cyan analogWrite(red, 168);

  • digitalWrite(blue, LOW); delay(a); analogWrite(red, 255); digitalWrite(blue, HIGH); break; case 5: //if ledcolor equals 5 then the led will turn magenta digitalWrite(green, LOW); digitalWrite(blue, LOW); delay(a); digitalWrite(green, HIGH); digitalWrite(blue, HIGH); break; case 6: //if ledcolor equals 6 then the led will turn white analogWrite(red, 155); digitalWrite(green, LOW); digitalWrite(blue, LOW); delay(a); analogWrite(red, 255); digitalWrite(green, HIGH); digitalWrite(blue, HIGH); break; } }

    TEMPERATURE SENSOR Display the environment temperature in Serial monitor Parts required

    1. Temperature Sensor LM35 x 1 2. Jumper wires

    //temperature float temp; int tempPin = 2; int led = 2;

  • void setup() { Serial.begin(9600); pinMode(led,OUTPUT); } void loop() { temp = analogRead(tempPin); temp = temp * 0.48828125; if(temp>27){ digitalWrite(led,HIGH); } else{ digitalWrite(led,LOW); } Serial.print("TEMPERATURE = "); Serial.print(temp); Serial.print(char(176)); Serial.print("C"); Serial.println(); delay(1000); }

    RELAY Parts required

    1. Green LED 2. Yellow LED 3. Relay 4. Transistor P2N2222 5. Resistor 330ohm 6. Diode 1N4148 7. Jumper wire

    int relayPin = 4;

  • // the setup routine runs once when you press reset: void setup() { // initialize the digital pin as an output. pinMode(relayPin, OUTPUT); } // the loop routine runs over and over again forever: void loop() { digitalWrite(relayPin, HIGH); // turn the LED on (HIGH is the voltage level) delay(1000); // wait for a second digitalWrite(relayPin, LOW); // turn the LED off by making the voltage LOW delay(1000); // wait for a second }

    SERVO MOTOR Sweep servo motor from 0o to 180o and back to 0o, then repeat again. Parts required

    1. Servo motor 2. Jumper wire

    //Coding = File > Examples > Servo > Sweep #include Servo myservo; // create servo object to control a servo // a maximum of eight servo objects can be created int pos = 0; // variable to store the servo position void setup() { myservo.attach(9); // attaches the servo on pin 9 to the servo object } void loop()

  • { for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees { // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees { myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } }

    LCD 1602 Parts required

    1. LCD 1602 2. Potentiometer 3. Jumper wires

    //Coding = File > Examples > LiquidCrystal > HelloWorld // include the library code: #include // initialize the library with the numbers of the interface pins LiquidCrystal lcd(12, 11, 5, 4, 3, 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() { // set the cursor to column 0, line 1

  • // (note: line 1 is the second row, since counting begins with 0): lcd.setCursor(0, 1); // print the number of seconds since reset: lcd.print(millis()/1000); }

    Task 1 TRAFFIC LIGHT Please develop traffic light led blinking using three different led colour. Start with green led, followed by yellow and red led.

    Task 2 WARNING LED Develop a code to turn on led after the sensor reach more than 30 degrees. Parts required

    1. Red LED x 1 2. Resistor 330ohm x 1 3. Temperature sensor LM35 x 1 4. Jumper wire

  • Task 3 TEMPERATURE LCD DISPLAY