This project was done under  "Making for Innovation" course. The objective of the project was to do stuff using the input from two push button switches using Arduino.
 
For this project I used 5 LEDs in total, and 2 pushbuttons. One end of the push buttons are connected to to pin 1 & 2 respectively and the other ends are grounded through 10k resistors.
We used resistors with each LED. These are connected to the Arduino Pins 8,9,10 ,11 respectively, The resistors  are used at the ground ends. One Green LED is there to point out the start of the numbering as the button state combinations are numbered as follows: 
Button 1 ON : Button 2 ON : 1
Button 1 ON : Button 2 OFF : 2
Button 1 OFF : Button 2 ON : 3
Button 1 OFF : Button 2 OFF : 4
 
Each LED is lit based on it's number and the button state combination
Green    1       2
                3       4 
 
The arduino code is as follows : 
 
const int button_1 = 1;     // the number of the pushbutton pin
const int button_2 = 2;
const int led_1 = 8;        // the number of the LED pin
const int led_2 = 9;
const int led_3 = 10;
const int led_4 = 11;
int buttonState_1, buttonState_2;

// variables will change:
//int buttonState = 0;         // variable for reading the pushbutton status
void setup() {
  // initialize the LED pin as an output:
  pinMode(led_1, OUTPUT);   
  pinMode(led_2, OUTPUT); 
  pinMode(led_3, OUTPUT); 
  pinMode(led_4, OUTPUT); 
  
  // initialize the pushbutton pin as an input:
  pinMode(button_1, INPUT);    
  pinMode(button_2, INPUT); 
    
}
void loop(){
  // read the state of the pushbutton value:
  buttonState_1 = digitalRead(button_1);
  buttonState_2 = digitalRead(button_2);
  // check if the pushbutton is pressed.
  // if it is, the buttonState is HIGH:
  
  //ON,ON
  
  if (buttonState_1 == HIGH && buttonState_2 == HIGH ) 
  {     
    // turn LED on:    
    digitalWrite(led_1, HIGH);
    digitalWrite(led_2, LOW);
    digitalWrite(led_3, LOW);
    digitalWrite(led_4, LOW);  
  } 
  else {
    // turn LED off:
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, LOW);
    digitalWrite(led_3, LOW);
    digitalWrite(led_4, LOW);   
  }
  
  
  // ON,OFF
  if (buttonState_1 == HIGH && buttonState_2 == LOW ) 
  {     
    // turn LED on:    
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, HIGH);
    digitalWrite(led_3, LOW);
    digitalWrite(led_4, LOW);  
  } 
  else {
    // turn LED off:
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, LOW);
    digitalWrite(led_3, LOW);
    digitalWrite(led_4, LOW);   
  }
  
  
  
  // OFF,ON  
  if (buttonState_1 == LOW && buttonState_2 == HIGH ) 
  {     
    // turn LED on:    
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, LOW);
    digitalWrite(led_3, HIGH);
    digitalWrite(led_4, LOW);  
  } 
  else {
    // turn LED off:
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, LOW);
    digitalWrite(led_3, LOW);
    digitalWrite(led_4, LOW);   
  }
  
  
  
  
  //OFF,OFF  
  if (buttonState_1 == LOW && buttonState_2 == LOW  ) 
  {     
    // turn LED on:    
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, LOW);
    digitalWrite(led_3, LOW);
    digitalWrite(led_4, HIGH);  
  } 
  else {
    // turn LED off:
    digitalWrite(led_1, LOW);
    digitalWrite(led_2, LOW);
    digitalWrite(led_3, LOW);
    digitalWrite(led_4, LOW);   
  }
  
}
Arduino Project
Published:

Arduino Project

Simple LEDs with Arduino

Published:

Creative Fields