top of page
Search

Controlling multiple LEDs with Switch - Arduino

"This is Blog log of what work has been done during the isolation period of the Covid-19 virus, leading to the need to document work online of Interactive Media Workshop"


Throughout the course, we were introduced to the concepts of various technologies that play a major role in our daily life. One such technology was the open-source microcontroller of Ardunio which are mainly used for building digital devices. This Arduino plays a major role in the internet of things that controls the current world.


Over here I tried to explore the basics of electronic circuits by making some interesting stuff.

It was not only fun learning but it was a way for sharpening minds. Through exploring the programming it also helped in brushing the basic C programming skills. The lockdown of the university and lack of pieces of equipment for working on the microcontroller became a key for learning new opensource modelling platform called Tinkercad. Tinkercad provides a platform for virtually developing circuits and perform simulations. With the help of this platform, I created a virtual circuit which controls 6 LEDs simultaneously with a single push button.



The components that were used were Arduinouno, (7) Resistors, (6)LEDs, Breadboard and Push-button. I added 6 LEDs to 8 to 13 pins of the Arduino and a push-button to the 2nd pin. On each press of the push, button each of the LED’s light up. For keeping track of the LED inactive a variable called state is added and are controlled by series of if statements. The overall program is kept in simple logic. This development helped me in understanding the fundamentals of electronics. The exploration of this switch controlled basic experiment motivated me in learning further about the microcontrollers and the IOTS. I believe that this exploration would play a major role in supporting my final thesis prototyping. Below is the recording of the circuit simulation in Tinkercad.



Below is the code for the arduino:

int LEDgreen = 13;
int LEDyellow = 12;
int LEDred = 11;
int LEDgrey = 10;
int LEDorange = 9;
int LEDblue = 8;


int pushButton = 2;

// variables to hold the new and old switch states
boolean oldButtonState = LOW;
boolean newButtonState1 = LOW;
boolean newButtonState2 = LOW;
boolean newButtonState3 = LOW;
boolean newButtonState4 = LOW;
boolean newButtonState5 = LOW;
boolean newButtonState6 = LOW;
 
int state = 0;

// the setup routine runs once when you press reset:
void setup() {

  Serial.begin(9600);
  
  pinMode(LEDgreen, OUTPUT);  
  digitalWrite(LEDgreen,LOW); 
  pinMode(LEDyellow, OUTPUT);  
  digitalWrite(LEDyellow,LOW); 
  pinMode(LEDred, OUTPUT);    
  digitalWrite(LEDred,LOW);

  pinMode(LEDgrey, OUTPUT);  
  digitalWrite(LEDgrey,LOW); 
  pinMode(LEDorange, OUTPUT);  
  digitalWrite(LEDorange,LOW); 
  pinMode(LEDblue, OUTPUT);    
  digitalWrite(LEDblue,LOW);
    
  pinMode(pushButton, INPUT);
   
}

// the loop routine runs over and over again forever:
void loop() {
  
  	newButtonState1 = digitalRead(pushButton);
    delay(1);
    newButtonState2 = digitalRead(pushButton);
    delay(1);
    newButtonState3 = digitalRead(pushButton);
    delay(1);
    newButtonState4 = digitalRead(pushButton);
    delay(1);
    newButtonState5 = digitalRead(pushButton);
    delay(1);
    newButtonState6 = digitalRead(pushButton);
    
   if (  (newButtonState1==newButtonState2) && (newButtonState1==newButtonState3) && (newButtonState1==newButtonState4) && (newButtonState1==newButtonState5) && (newButtonState1==newButtonState5)  )
   {
  
  		if(newButtonState1 != oldButtonState)
 		 {
           if(newButtonState1 == HIGH )
           {
             state++;
  			  if (state > 3)
  			  {
  				  state =0;
  			  }
   			digitalWrite(LEDgreen, LOW);
   			digitalWrite(LEDyellow, LOW);
   			digitalWrite(LEDred, LOW);
        digitalWrite(LEDgrey, LOW);
        digitalWrite(LEDorange, LOW);
        digitalWrite(LEDblue, LOW);
             
            if (state==1) { digitalWrite(LEDgreen, HIGH);  }
            if (state==2) { digitalWrite(LEDyellow, HIGH);  }
            if (state==3) { digitalWrite(LEDred, HIGH);  }
            if (state==4) { digitalWrite(LEDgrey, HIGH);  }
            if (state==5) { digitalWrite(LEDorange, HIGH);  }
            if (state==6) { digitalWrite(LEDblue, HIGH);  }
   
           }
          oldButtonState = newButtonState1;
        }
   }
  
}
6 views0 comments

Recent Posts

See All
bottom of page