Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

LED Combination control using Arduino

Status
Not open for further replies.

Nikhil_M

New Member
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.





The circuit is intended to function as below:

LEDs and Switch.jpg




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!
 

Attachments

  • 001158.jpg
    001158.jpg
    28.4 KB · Views: 346
Last edited:
When you say "selects scenario 1" do you mean button 1 is pressed?

Mike.
 
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:
C:
#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);
}
[\code]
 
Last edited by a moderator:
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!
 
Well, an Uno doesn't have 60 pins to control 60 LEDs so I suggest a multiplexed 8 by 8 LED matrix and an array of 8 bytes to hold the current value. Or consider using a MAX7219 - many examples available. I'd (personally) try to get rid of the event handler and read the keys directly - don't think you even need debounce.

Mike.
Edit, do you also need 60 pushbuttons?
 
Last edited:
Well, an Uno doesn't have 60 pins to control 60 LEDs so I suggest a multiplexed 8 by 8 LED matrix and an array of 8 bytes to hold the current value. Or consider using a MAX7219 - many examples available. I'd (personally) try to get rid of the event handler and read the keys directly - don't think you even need debounce.

Mike.
Edit, do you also need 60 pushbuttons?
Hello Mike,

I need 60 push buttons that will feedback to the controller about a manual event and the respective LED should turn off.

Also, I will search more about MAX7219.
 
WS2812 ? To cascade a lot of LEDs ?




Regards, Dana.
Hello Dana,

Thank you for the reply. I will check more about WS2812.
 
Alternative is a 64 bit SIPO shift register -


1649420401345.png


This solution has to take into account current thru leds and total current thru each 8 bit port.

That limit is 100 mA per port.



Regards, Dana.
 
Last edited:
Google this, lots of hits -

"arduino ws2812"



Regards, Dana.

I came across a large WS2812 flexible panel for sale the other day, current consumption was listed as 75A with all LEDs lit :D

Needless to say, it had multiple power feeds, rather than just feeding through the WS2812's.
 

Nikhil_M


This does not look like you are doing high current LEDs, more like 10 - 20 mA
types of LEDs. Can you confirm how much LD current you need ?

1649420817418.png



Regards, Dana.
 
Status
Not open for further replies.

Latest threads

Back
Top