curieelectronics
Published © GPL3+

Reading Inputs with Pull Up & Pull Down

Shows how to read switches and sensor connected to Arduino.

IntermediateFull instructions provided14,711
Reading Inputs with Pull Up & Pull Down

Things used in this project

Hardware components

Arduino UNO
Arduino UNO
×1
Breadboard (generic)
Breadboard (generic)
×1
Tactile Switch, Top Actuated
Tactile Switch, Top Actuated
×2
Resistor 4.75k ohm
Resistor 4.75k ohm
×2
5 mm LED: Red
5 mm LED: Red
×2

Software apps and online services

Arduino IDE
Arduino IDE

Story

Read more

Schematics

Interfacing Switch

Code

Switch Interface

Arduino
//CURIE PROJECTS
const int ledPin1 = 13; // choose the pin for the LED1
const int ledPin2=12;  // choose the pin for the LED1
const int inputPin1 = 9;  // choose the input pin input1
const int inputPin2=10;  // choose the input pin input2
int SW1State ; // Pullup resistor connected to GPIO 9
int SW2State;  // Pulldown resistor connected to GPIO 9
int value1 = HIGH;  // variable for reading the pin status
int value2=LOW;
 
void setup()
{
  pinMode(ledPin1, OUTPUT);      // declare LED1 as output
  pinMode(ledPin2, OUTPUT);      // declare LED2 as output
  pinMode(inputPin1, INPUT);     // declare switch1 as input  
  pinMode(inputPin2, INPUT);     // declare switch2 as input 
}
 
void loop()
  {
  value1 = digitalRead(inputPin1);  // read input1 value
  value2 = digitalRead(inputPin2);  // read input2 value
          if (value1== HIGH)
          SW1State = HIGH;
          if (value1 == LOW)
          SW1State = LOW;
          
          if (value2== HIGH)
          SW2State = HIGH;
          if (value2 == LOW)
          SW2State = LOW;
    if(SW1State==HIGH)
    {
    digitalWrite(ledPin1,HIGH);
    }
    else
    {
    digitalWrite(ledPin1,LOW);
     
    }

    if(SW2State==HIGH)
    {
    digitalWrite(ledPin2,HIGH);
    }
    else
    {
    digitalWrite(ledPin2,LOW);
     
    }

  }

Credits

curieelectronics
0 projects • 0 followers
Contact

Comments

Please log in or sign up to comment.