Professional Documents
Culture Documents
signals.
0 1 == High == True == 3-5V 0 0 == Low == False == 0-2V 0 And thus the binary number system was born.
Hardware communication
0 Every electronic system will have two logic levels called
and GND.
0 Digital Signals can only take the states of VCC and GND
states.
GND.
Ports
0 A microcontroller can digitally communicate with the
microcontroller.
Digital Pins
0 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.
circuits. (40mA)
10kohms)
LEDs
0 Light Emitting diode.
0 Do not connect LEDs in parallel!! 0 The longer end is VCC and the shorter end
is GND.
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?
Digital Input
0 Digital Input can be sensed by all digital pins of the
arduino.
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.
Switches
0 Switches are mechanical devices that switch
Switching states
0 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,
state through the pull-down resistor. (the Resistor pulls the pin to GND when no i/p is present) because it is the path of least resistance.
0 When pressed, the switch will read the VCC 0 If VCC and GND are swapped in the diagram, the
Reading a switch
0 Open 3. LED_Switch folder. 0 Connect switch + resistor and LED + resistor circuits
Code
0 Switch is read using digital read. This will return either 1
or 0. (HIGH / LOW).
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.
Interrupts
0 Interrupts are signals that indicate to the
0 Internal 0 Divide by 0 interrupts 0 Timer interrupts 0 ADC interrupts 0 External 0 Pin 2 & 3
External Interrupt
0 Pin 2 and 3 are set up for external interrupts. 0 Allow the arduino to continue doing tasks intstead of
function.
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.
The ISR
0 The interrupt service routine is the function that is
0 Delay() and millis() are not supported inside an ISR. 0 Serial data received might be lost when the ISR
returns.
volatile.
#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; }
Remember
0 Make sure there are no loose connections on the
breadboard.
are one.
Communication
0 Information is also transferred from arduino to
0 Each of this 1s and 0s are called as bits. 0 Because the data is transferred one after another on
TX and RX pins
0 These pins light up when serial 0 In the Arduino, the serial port
data is transmitted or received. goes through the FTDI chip and is converted to USB. serial data can be tapped from these pins. during serial transfers.
Baud rate
0 Baud rate is the unit of symbol rate.
machine and the transmitting system should be set to the same baud rate. (9600/11500 usually)
usage
0 In setup(){ } put serial.begin(9600); 0 In loop, use serial.println(data) 0 Open serial monitor to see data.
Serial Program
0 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.
Question Time