Microprocessors Module 3 Interfacing of I/O Devices PDF
Document Details
Uploaded by SoulfulVuvuzela
FEU Alabang
2018
Tags
Related
Summary
This document is a module on interfacing I/O devices with microprocessors, focusing on various methods of controlling and interacting with input and output devices. The module covers different types of I/O, such as digital output, digital input, and high current output, and includes examples of Arduino programming.
Full Transcript
Microprocessors Module 3 Interfacing of I/O devices 1. Orient the students on the various devices that may be interfaced with the microcontroller. 2. Orient the students on how to manipulate the ports of the microcontroller to output or input data. Digital Output This is the basi...
Microprocessors Module 3 Interfacing of I/O devices 1. Orient the students on the various devices that may be interfaced with the microcontroller. 2. Orient the students on how to manipulate the ports of the microcontroller to output or input data. Digital Output This is the basic ‘hello world’ program used to simply turn something on or off. In this example, an LED is connected to pin 13, and is blinked every second. The resistor may be omitted on this pin since the Arduino has one built in. int ledPin = 13; void setup() { pinMode (ledPin, OUTPUT); } void loop() { digitalWrite(ledPin, HIGH); delay(1000); digitalWrite(ledPin, LOW); delay(1000); } Digital Input This is the simplest form of input with only two possible states: on or off. This example reads a simple or pushbutton connected to pin2. when the switch is closed the input pin will read HIGH and turn on LED. Digital Input Void loop() { int ledPin = 13; if (digitalRead(inPin) == int inPin = 2; LOW) { void setup() digitalWrite(ledPin, HIGH); { delay(1000); pinMode (ledPin, OUTPUT); digitalWrite(ledPin, LOW); pinMode(inPin, INPUT); delay(1000); } } } High Current Output Sometimes it is necessary to control more than 40mA from Arduino. In this case a MOSFET or transistor could be used to switch higher current loads. The following example quickly turns on and off the MOSFET 5 times every second. Note: the schematic shows a motor and protection diode but other non-inductive loads could be used without the diode. High Current Output void loop() { int outPin = 5; for (int i=0; i=0; i--) { void loop() analogWrite(ledPin, i); { delay(100); for (int i=0; i=0; i--) int analogPin = 0; { analogWrite(ledPin, i); void setup(){} delay(delayVal()); } void loop() } { for (int i=0; i