0% found this document useful (0 votes)
188 views

Interface Digital and Analog I/O Devices (Arduino Interfacing)

The document discusses interfacing various digital and analog input/output devices with Arduino including LEDs, switches, 7-segment displays, potentiometers, temperature sensors, accelerometers, keypads, DC motors, and LCD displays. It provides the objectives, concepts, code examples and programs for interfacing each device and applying them in applications like traffic lights, toggling an LED mode, and displaying sensor readings.

Uploaded by

Raggy Tanna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
188 views

Interface Digital and Analog I/O Devices (Arduino Interfacing)

The document discusses interfacing various digital and analog input/output devices with Arduino including LEDs, switches, 7-segment displays, potentiometers, temperature sensors, accelerometers, keypads, DC motors, and LCD displays. It provides the objectives, concepts, code examples and programs for interfacing each device and applying them in applications like traffic lights, toggling an LED mode, and displaying sensor readings.

Uploaded by

Raggy Tanna
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 29

Interface Digital and

Analog I/O devices


(Arduino Interfacing)

Hiren D. Shukla
Lecturer-EC
Objectives

 Basic Interfacing & I/O Concept (Code).


 Interfacing LED,Switch,7seg LED its and Code.
 Interfacing POT,LM35,Acelerometer (ADXL3C5C) &
its Code.
 Interfacing keypad and Code for it.
 Initialization for serial port and code for it.
 Interfacing DC motor & its code.
 Interfacing 16x2 LCD & its code.
Basic Interfacing & I/O Concept
(Code)
 Void setup ()
 Void loop ()
 Analog I/O
analogRead(pin)
analogWrite(pin, value)
 Digital I/O
pinMode(pin, mode)
digitalRead(pin)
digitalWrite(pin, value)
Interfacing LED & Code.
Code
int ledPin = 10;
void setup()
{
pinMode(ledPin, OUTPUT);
}
void loop()
{
digitalWrite(ledPin, HIGH);
delay(1000);
digitalWrite(ledPin, LOW);
delay(1000);
}
Traffic Signal System
 Write a program for Indian traffic signal system. (for the Two way roads)
• One way Red so the other way must have Green light signal. Yellow signal for both
way for crossing the road by foot.
Code
int r1 = 10;
int y1= 9;
int g1 = 8;
int r2 = 11;
int y2 = 12;
Int g2 = 13;
void setup()
{
pinMode(r1, OUTPUT);
pinMode(y1, OUTPUT);
pinMode(g1, OUTPUT);
pinMode(r2, OUTPUT);
pinMode(y2, OUTPUT);
pinMode(g2, OUTPUT);
}
Continue…
void loop()
{
digitalWrite(r1, HIGH); // turn the red light on
digitalWrite(g2, HIGH);
delay(5000);

digitalWrite(r2, HIGH);
digitalWrite(g1, HIGH);
delay(5000); // wait 5 seconds

digitalWrite(y1, HIGH);
digitalWrite(y2, HIGH);
digitalWrite(r1, LOW);
digitalWrite(r2, LOW);
digitalWrite(g1, LOW);
digitalWrite(g2, LOW);
delay(5000);
}
Interface a Switch
Code
Int ledPin=13;
Int inpin=2;
Void setup()
{
pinMode(ledpin,OUTPUT);
pinMode(inpin,INPUT);
}
Void loop()
{
if (digitalRead(inpin) == HIGH)
{
digitalWrite(ledpin, HIGH);
delay(1000);
digitalWrite(ledpin,LOW);
delay(1000);
}
}
Write a program to switch the mode of
LED.
Write a Program to switch the mode of LED.
 int in = 2; // the number of the input pin
 int out = 13; // the number of the output pin
 int state = HIGH; // the current state of the output pin
 int reading; // the current reading from the input pin
 int previous = LOW; // the previous reading from the input pin // the follow
variables are long's because the time, measured in miliseconds, // will
quickly become a bigger number than can be stored in an int.
 long time = 0; // the last time the output pin was toggled
 long debounce = 200; // the debounce time, increase if the output flickers
 void setup()
 {
 pinMode(in, INPUT);
 pinMode(out, OUTPUT);
 }
Continue…
 void loop()
 {
 reading = digitalRead(in); // if the input just went from LOW and HIGH and we've waited
long enough // to ignore any noise on the circuit, toggle the output pin and remember //
the time
 if (reading == HIGH && previous == LOW && millis() - time > debounce)
 // interrupt will increment a variable after every millisecond
 {
 if (state == HIGH)
 state = LOW;
 else
 state = HIGH;
 time = millis();
 }
 digitalWrite(out, state);
 previous = reading;
 }
Interface 7 Segment LED
Serial Communication
 Sets the data rate in bits per second (baud) for serial data
transmission. For communicating with the computer, use
one of these rates: 300, 600, 1200, 2400, 4800, 9600,
14400, 19200, 28800, 38400, 57600, or 115200.
 Syntax
Serial.begin(speed)
Interface LM35 (Temperature Sensor)S
LM 35 Discription
LM35 Code
 Float temp;
int temp_pin=0;
void setup()
{
Serial.begin(9600);
}
void loop()
{
temp=analogRead(temp_pin);
temp=temp * 0.48828;
Serial.print (“ Temperature = “);
Serial.print(temp);
Serial.print(“ *C”);
Serial.println();
delay(1000);
}
Accelerometer (ADXL 3C5C) Arduino
Interfacing.
int groundpin = 18;             // analog input pin 4 -- ground
int powerpin = 19;              // analog input pin 5 -- voltage
int xpin = A3;                  // x-axis of the accelerometer
int ypin = A2;                  // y-axis
int zpin = A1;                  // z-axis (only on 3-axis models)

void setup()
{
  
  Serial.begin(9600);
  
  pinMode(groundpin, OUTPUT);
  pinMode(powerpin, OUTPUT);
  digitalWrite(groundpin, LOW); 
  digitalWrite(powerpin, HIGH);
}

void loop()
{
  
  Serial.print(analogRead(xpin));
  Serial.print("\t");
  Serial.print(analogRead(ypin));
  Serial.print("\t");
  Serial.print(analogRead(zpin));
  Serial.println();  
  delay(100);
}
Keypad Interfacing
Code
#include <Keypad.h>

const byte ROWS = 4; //four rows


const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {'1','2','3'},
  {'4','5','6'},
  {'7','8','9'},
  {'#','0','*'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

void setup(){
  Serial.begin(9600);
}
void loop(){
  char key = keypad.getKey();

  if (key != NO_KEY){
    Serial.println(key);
  }
}
Interfacing DC motor
Code
int motor_forward = 7;
int motor_reverse = 6;
void setup() {pinMode(motor_forward, OUTPUT);
pinMode(motor_reverse, OUTPUT); }
void loop() { digitalWrite(motor_forward,1);
digitalWrite(motor_reverse,0);
delay(5000);
digitalWrite(motor_forward,0);
digitalWrite(motor_reverse,1);
delay(5000);
digitalWrite(motor_forward,0);
digitalWrite(motor_reverse,0);
delay(5000);
Interfacing 16x2 LCD
Code
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);
}
Switch Case
 void setup() {  
  Serial.begin(9600); 
  for (int thisPin = 2; thisPin < 7; thisPin++) {
    pinMode(thisPin, OUTPUT); }

void loop() {
    if (Serial.available() > 0) {
    int inByte = Serial.read();
       switch (inByte) {
      case 'a':
        digitalWrite(2, HIGH);
        break;
      case 'b':
        digitalWrite(3, HIGH);
        break;
      case 'c':
        digitalWrite(4, HIGH);
        break;
      case 'd':
        digitalWrite(5, HIGH);
        break;
      case 'e':
        digitalWrite(6, HIGH);
        break;
      default:
      for (int thisPin = 2; thisPin < 7; thisPin++) {
      digitalWrite(thisPin, LOW);
 } } }
Programs

 Display the temperature on LCD screen.[Use lcd.print(temp) command to


print the temperature reading]
 Make a digital Clock with the use of 7-segment display. (or display the time
on lcd screen)
 Enter the number from keypad and rotate the motor for that much of second
in forward direction and than in reverse direction.
 Write a program to display the number on 7-segment whichever is entered by
Keypad.(use switch case)
 display the reading of accelerometer on LCD screen

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy