0
Signals0 Information is transferred in the digital/analogue world by signals.0 Electrical Signals are given a logic equiva...
Digital and Analogue            information0 Signals can be defined as any time varying quantity that can be said to repre...
Hardware communication0 Every electronic system will have two logic levels called VCC and GND.0 Analogue signals in this c...
Ports0 A microcontroller can digitally communicate with the outside world through Ports.0 Every microcontroller has its ow...
PORTS on the arduino0 The atmega328 has three ports   0 B (digital pin 8 to 13)   0 C (analog input pins)   0 D (digital p...
Digital Pins0 Numbered 1 – 13 on the ardiono.0 Can be set to Input/Output by pinMode(pin) function.0 Can be set to output ...
Digital PIN as output0 The pin is in a state of low impedance.0 This means the pin can supply current to other circuits. (...
LEDs0 Light Emitting diode.0 Use R = (VS - VL) / I to calculate the  resistor value to put in series.  0 Vs = 5V; VL = 2V ...
PIN13 on the Arduino0 The arduino has an LED + resistor mounted on the board.0 Open the program in folder 1. Blink in the ...
Connecting External LED0 Open folder 2.LED Breadboard0 Connect LEDs as shown in the circuit diagram.0 Avoid connecting mul...
Digital Input0 Digital Input can be sensed by all digital pins of the  arduino.0 Pins when set up as inputs are said to be...
Switches0 Switches are mechanical devices that “switch” between VCC and GND states.
Switching states0 We need to switch between VCC and GND to use with  digitalread().0 But, tactile switches can only open a...
Enter Pull-down resistors0 Using these resistors (10kohms) provide both states with a single push button switch.0 When unp...
Reading a switch0 Open 3. LED_Switch folder.0 Connect switch + resistor and LED + resistor circuits from the breadboard as...
Code0 Switch is read using digital read. This will return either 1  or 0. (HIGH / LOW).0 This is stored in a variable.0 LE...
Interrupts0 Interrupts are signals that indicate to the microcontroller that a particular event has occurred.0 Internal   ...
External Interrupt0 Pin 2 and 3 are set up for external interrupts.0 Allow the arduino to continue doing tasks intstead of...
attachInterrupt(interrupt, function, mode)0 Interrupt: can be either 0 or 1 signifing which interrupt is being set up.0 Fu...
The ISR0 The interrupt service routine is the function that is called every time the interrupt fires.0 Delay() and millis(...
#include <avr/interrupt.h>int ledPin = 12;volatile int state = LOW;void setup() {  Serial.begin(9600);  pinMode(12, OUTPUT...
Remember0 Make sure there are no loose connections on the breadboard.0 Make sure you’ve gotten the upload successful messa...
Communication0 Information is also transferred from arduino to computer by setting a pin HIGH or LOW in sucession to creat...
TX and RX pins0 These pins light up when serial  data is transmitted or received.0 In the Arduino, the serial port  goes t...
Baud rate0 Baud rate is the unit of symbol rate.0 A baud rate of 1 kBd = 1,000 Bd is synonymous to a  symbol rate of 1,000...
usage0 In setup(){ } put serial.begin(9600);0 In loop, use serial.println(data)0 Open serial monitor to see data.
Serial Program0 Open the folder 4. Serial and upload the arduino with the code.0 The program prints numbers from 1-100 seq...
Question Time
02   General Purpose Input -  Output on the Arduino
02   General Purpose Input -  Output on the Arduino
02   General Purpose Input -  Output on the Arduino
Upcoming SlideShare
Loading in...5
×

02 General Purpose Input - Output on the Arduino

1,478

Published on

Learn how to use LEDs, Switches effectively on the Arduino microcontroller platform.

Published in: Education, Business, Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,478
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
67
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Transcript of "02 General Purpose Input - Output on the Arduino"

  1. 1. Signals0 Information is transferred in the digital/analogue world by signals.0 Electrical Signals are given a logic equivalency to enable control and sensing from the physical universe.0 1 == High == True == 3-5V0 0 == Low == False == 0-2V0 And thus the binary number system was born.
  2. 2. Digital and Analogue information0 Signals can be defined as any time varying quantity that can be said to represent information.0 Digital signals, at any given point of time take up only one of a few discrete predefined states.0 Analogue signals are not restricted to any particular state but continuously changes itself w.r.t. time.
  3. 3. Hardware communication0 Every electronic system will have two logic levels called VCC and GND.0 Analogue signals in this can take any value between VCC and GND.0 Digital Signals can only take the states of VCC and GND states.0 Digital devices either control or respond to either VCC or GND.
  4. 4. Ports0 A microcontroller can digitally communicate with the outside world through Ports.0 Every microcontroller has its own PORTs controlled by specific port registers.0 Ports are a collection of PINS on the microcontroller.0 Each pin can be controlled digitally by the microcontroller.
  5. 5. PORTS on the arduino0 The atmega328 has three ports 0 B (digital pin 8 to 13) 0 C (analog input pins) 0 D (digital pins 0 to 7)0 Each Port has a 0 PORTx register that controls the value of the port. 0 DDRx register that controls the port from output/input mode.
  6. 6. Digital Pins0 Numbered 1 – 13 on the ardiono.0 Can be set to Input/Output by pinMode(pin) function.0 Can be set to output by digitalwrite(pin, state) function.0 digitalread(pin) returns the state of the pin.
  7. 7. Digital PIN as output0 The pin is in a state of low impedance.0 This means the pin can supply current to other circuits. (40mA)0 Shorts or attempting to draw more current can damage the transistors on that pin (or fry the board).0 Use resistors to limit current from the pins. (1- 10kohms)
  8. 8. LEDs0 Light Emitting diode.0 Use R = (VS - VL) / I to calculate the resistor value to put in series. 0 Vs = 5V; VL = 2V (depends on color) 0 I = 40mA (max current required)0 Do not connect LEDs in parallel!!0 The longer end is VCC and the shorter end is GND.
  9. 9. PIN13 on the Arduino0 The arduino has an LED + resistor mounted on the board.0 Open the program in folder 1. Blink in the arduino IDE.0 Upload that program onto the board.0 Watch blinky!0 Can you make it blink faster?0 Then slower?
  10. 10. Connecting External LED0 Open folder 2.LED Breadboard0 Connect LEDs as shown in the circuit diagram.0 Avoid connecting multiple LEDs to a single PIN.0 If the PIN is HIGH the LED will light up.
  11. 11. Digital Input0 Digital Input can be sensed by all digital pins of the arduino.0 Pins when set up as inputs are said to be in a High impedance state.0 Which means they tend to draw very little current from the circuit they are sensing and that means that small changes in current are enough to change the state of the PIN.0 If an input pin is left unconnected: 0 State may change randomly 0 Pin may capacitively couple & report the state of a nearby pin.
  12. 12. Switches0 Switches are mechanical devices that “switch” between VCC and GND states.
  13. 13. Switching states0 We need to switch between VCC and GND to use with digitalread().0 But, tactile switches can only open and close circuits.0 In each of the cases, if switch is pressed, the PIN goes into a state, when released the PIN is disconnected or in a random state.
  14. 14. Enter Pull-down resistors0 Using these resistors (10kohms) provide both states with a single push button switch.0 When unpressed, the PIN state will read the GND state through the pull-down resistor. (the Resistor pulls the pin to GND when no i/p is present)0 When pressed, the switch will read the VCC because it is the path of least resistance.0 If VCC and GND are swapped in the diagram, the resistor is called a Pull-up resistor with reversal in logic levels.
  15. 15. Reading a switch0 Open 3. LED_Switch folder.0 Connect switch + resistor and LED + resistor circuits from the breadboard as shown.0 Run Switch 1.pde on the arduino IDE and upload it onto the arduino.
  16. 16. Code0 Switch is read using digital read. This will return either 1 or 0. (HIGH / LOW).0 This is stored in a variable.0 LED is set to that variable.0 So if switch is pressed, 1 is sensed and LED is set to 1.0 When switch is released, 0 is sensed and LED turns off.0 Voila!! LED is controlled by a switch.
  17. 17. Interrupts0 Interrupts are signals that indicate to the microcontroller that a particular event has occurred.0 Internal 0 Divide by 0 interrupts 0 Timer interrupts 0 ADC interrupts0 External 0 Pin 2 & 3
  18. 18. External Interrupt0 Pin 2 and 3 are set up for external interrupts.0 Allow the arduino to continue doing tasks intstead of continuosly checking for external signal changes.0 INT0 is on pin2 and INT1 is on pin30 Use attachinterrupt() to associate interrupts to a function.
  19. 19. attachInterrupt(interrupt, function, mode)0 Interrupt: can be either 0 or 1 signifing which interrupt is being set up.0 Function : is the name of the function to be called when the interrupt fires.0 Mode: 0 LOW to trigger the interrupt whenever the pin is low, 0 CHANGE to trigger the interrupt whenever the pin changes value 0 RISING to trigger when the pin goes from low to high, 0 FALLING for when the pin goes from high to low.
  20. 20. The ISR0 The interrupt service routine is the function that is called every time the interrupt fires.0 Delay() and millis() are not supported inside an ISR.0 Serial data received might be lost when the ISR returns.0 All variables that get modified within the ISR must be volatile.
  21. 21. #include <avr/interrupt.h>int ledPin = 12;volatile int state = LOW;void setup() { Serial.begin(9600); pinMode(12, OUTPUT); attachInterrupt(0, blink, FALLING);}void loop() { digitalWrite(ledPin,state);}void blink(){ state = !state;}
  22. 22. Remember0 Make sure there are no loose connections on the breadboard.0 Make sure you’ve gotten the upload successful message on the IDE.0 Make sure switch GND, LED’s GND and arduino’s GND are one.0 Don’t dismantle your circuits after completion.
  23. 23. Communication0 Information is also transferred from arduino to computer by setting a pin HIGH or LOW in sucession to create a data waveform.0 Each of this ‘1’s and ‘0’s are called as “bits”.0 Because the data is transferred one after another on the same line, it is called serial transfer of data.0 Kinda simillarish to morse code.
  24. 24. TX and RX pins0 These pins light up when serial data is transmitted or received.0 In the Arduino, the serial port goes through the FTDI chip and is converted to USB.0 Pins 0 & 1 are the serial pins and serial data can be tapped from these pins.0 Don’t use these pins for GPIO during serial transfers.
  25. 25. Baud rate0 Baud rate is the unit of symbol rate.0 A baud rate of 1 kBd = 1,000 Bd is synonymous to a symbol rate of 1,000 symbols per second.0 In binary, a symbol is either a ‘1’ or ‘0’.0 In serial communication systems, both the receiving machine and the transmitting system should be set to the same baud rate. (9600/11500 usually)
  26. 26. usage0 In setup(){ } put serial.begin(9600);0 In loop, use serial.println(data)0 Open serial monitor to see data.
  27. 27. Serial Program0 Open the folder 4. Serial and upload the arduino with the code.0 The program prints numbers from 1-100 sequentially.0 Use the serial monitor on the Arduino to see the stream.0 Any program can open the COMx port associated with your arduino and read data transmitted by the arduino.
  28. 28. Question Time
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×