LED Combination control using Arduino

Thread Starter

Nikhil_M

Joined Jan 24, 2022
8
Hello!

I am a beginner at Arduino. I need to implement a simple circuit to control various LED glow scenarios and their reset using tact switches.
I request to please help me with this project.
I am attaching the image of the assembly done on bread board.
LEDs and Switch.jpg

The circuit is intended to function as below:

System must take the input from the user.

User selects Scenario 1.
LEDs L1, L2 and L4 should turn ON.

User presses S1 which will turn off L1, similarly S2 will turn off L2 and S4 will turn off L4.
All LEDs are now turned OFF.

System waits for next input from user.


User selects Scenario 2.
LEDs L1, L3 and L5 should turn ON.

User presses S1 which will turn off L1, similarly S3 will turn off L3 and S5 will turn off L5.
All LEDs are now turned OFF.

System waits for next input from user.


User selects Scenario 3.
LEDs L2, L3 and L5 should turn ON.

User presses S2 which will turn off L2, similarly S3 will turn off L3 and S5 will turn off L5.
All LEDs are now turned OFF.

System waits for next input from user.


User selects Scenario 4.
LEDs L1, L3 and L4 should turn ON.

User presses S1 which will turn off L1, similarly S3 will turn off L3 and S4 will turn off L4.
All LEDs are now turned OFF.

Please help me with the logic and the code to make this work.

Thank you in advance!
 

KeithWalker

Joined Jul 10, 2017
2,872
Is this a school project?
We are here to answer your technical questions but we will not design the project for you. We need to know what you have done so far and what you are having a problem with. Have you done any projects using an Arduino?
 

dl324

Joined Mar 30, 2015
15,831
User selects Scenario 1.
LEDs L1, L2 and L4 should turn ON.

User presses S1 which will turn off L1, similarly S2 will turn off L2 and S4 will turn off L4.
All LEDs are now turned OFF.
Read your scenarios and make sure the text is correct.

In Scenario 1, does "should" actually mean that they're already turned on (somehow)? If the switches only turn LEDs off, how do they get turned on?
 

Thread Starter

Nikhil_M

Joined Jan 24, 2022
8
Is this a school project?
We are here to answer your technical questions but we will not design the project for you. We need to know what you have done so far and what you are having a problem with. Have you done any projects using an Arduino?
Hello Keith
Thank you for your response.
I have not done many projects using Arduino and I am new to the same.
I am currently able to turn the LEDs ON using a Arduino code for each scenario.
But unable to turn them OFF by pressing corresponding switches.
 

Thread Starter

Nikhil_M

Joined Jan 24, 2022
8
Read your scenarios and make sure the text is correct.

In Scenario 1, does "should" actually mean that they're already turned on (somehow)? If the switches only turn LEDs off, how do they get turned on?
Hello Dennis,
Thank you for your reply.
I am currently able to turn the LEDs ON using a Arduino code for each scenario.
But unable to turn them OFF by pressing corresponding switches.
 

dl324

Joined Mar 30, 2015
15,831
I am currently able to turn the LEDs ON using a Arduino code for each scenario.
But unable to turn them OFF by pressing corresponding switches.
Is this schoolwork?

Is your code supposed to turn an LED on if it's off when a switch is pressed and turn it off if the LED is already on?

Post your code, and please use code tags so it'll be readable. Like this:
Code:
// outputs
#define ABITS 8  // D6-13
#define RAS 5    // D5
#define CAS 4    // D4
#define WE 3     // D3
#define DIN 2    // D2
#define PBIT 14  // A0, used as digital
#define PASS 15  // A1, used as digital
// inputs
#define DOUT 16  // A2
#define MAXREFRESH 6
 

Thread Starter

Nikhil_M

Joined Jan 24, 2022
8
Hello All,

Thank you everyone who responded to my post.

With some help I was able to achieve the desired results of the LED combinations using an Arduino Uno.

The code that worked is as below:

#include <EventButton.h>
EventButton firstButton(9);
EventButton secondButton(2);
EventButton thirdButton(3);
EventButton fourthButton(10);
EventButton fifthButton(11);
int a1 = 12;
int a2 = 8;
int a3 = 4;
int a4 = 5;
int a5 = 6;


void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(a1, OUTPUT);
pinMode(a2, OUTPUT);
pinMode(a3, OUTPUT);
pinMode(a4, OUTPUT);
pinMode(a5, OUTPUT);

firstButton.setClickHandler(onFirstButtonClicked);
secondButton.setClickHandler(onSecondButtonClicked);
thirdButton.setClickHandler(onThirdButtonClicked);
fourthButton.setClickHandler(onFourthButtonClicked);
fifthButton.setClickHandler(onFifthButtonClicked);
}

void loop()
{

char data = Serial.read();
switch (data) //Selection Control Statement
{
case '1':
digitalWrite(a1, HIGH);
digitalWrite(a2, HIGH);
digitalWrite(a4, HIGH);
break;
case '2':
digitalWrite(a1, HIGH);
digitalWrite(a3, HIGH);
digitalWrite(a5, HIGH);
break;
case '3':
digitalWrite(a1, HIGH);
digitalWrite(a2, HIGH);
digitalWrite(a3, HIGH);
break;
case '4':
digitalWrite(a1, HIGH);
digitalWrite(a3, HIGH);
digitalWrite(a4, HIGH);
break;

}

firstButton.update();
secondButton.update();
thirdButton.update();
fourthButton.update();
fifthButton.update();
}

void onFirstButtonClicked(EventButton& eb) {
Serial.print("First button clicked ");
digitalWrite(a1,LOW);
}

void onSecondButtonClicked(EventButton& eb) {
Serial.print("Second button clicked: ");
digitalWrite(a2,LOW);
}

void onThirdButtonClicked(EventButton& eb) {
Serial.print("Third button clicked: ");
digitalWrite(a3,LOW);
}

void onFourthButtonClicked(EventButton& eb) {
Serial.print("Fourth button clicked ");
digitalWrite(a4,LOW);
}

void onFifthButtonClicked(EventButton& eb) {
Serial.print("Fifth button clicked ");
digitalWrite(a5,LOW);
}
 

Thread Starter

Nikhil_M

Joined Jan 24, 2022
8
Now I need to scale the same combination to control around 60 LEDs.
I need guidance from this forum on how can that be done.
Thanking you in advance!
 

Ya’akov

Joined Jan 27, 2019
8,164
It would be extremely helpful if you would explain what you are building. You ae already on the second revision and the question was answered as if it was the final problem. If you keep building up vague cases there is a very good chance people are providing less than optimal answers because the real goal is hidden.
 

BobTPH

Joined Jun 5, 2013
7,548
60 is an entirely different problem because you will not have a pin for each light and one for each switch.

Do you have a hardware design for 60 lights and switches?

Bob
 
Top