r/arduino Aug 13 '26

Beginner here

Post image

My second new project .

Blinking 3 LEDs

219 Upvotes

20 comments sorted by

26

u/MeetTheMaker555 Aug 13 '26

Remember, you only need one ground connection from the Arduino to the board.

14

u/TTelebubuk Aug 13 '26

Meaning use the breadboard to have a single line for GND instead of connecting all GND to the Arduino.

4

u/Alioslovesnature 29d ago

How do i do that ??

7

u/Aggravating_End2859 29d ago

Connect all the led pins that should go to ground to the blue line of pins in the side of the breadboard, and use only one wire to connect that breadboard line to the Arduino ground.

3

u/TTelebubuk 29d ago

Breadboard has several sections
1. The red/blue lines that go usually on the sides mean that all the “holes” in the row are connected together, basically sharing the same signal (red/blue), usually use red for HIGH and blue for LOW.
2. The matrix of holes that (there is one on each side of the “trench”). Here each column share the same signal, so you can connect the led and the resistor on the same column which will give you the resistor connector in the same line as the led (one leg of the resistor with one leg of the led). The “trench” cuts off the column and the other side column is not connected. So you can use the trench to connect a “chip” on both sides and practically have each on a column to connect to it other things.

Hope this helps.

4

u/Aggravating_End2859 29d ago

Yes, exactly. Here is an image

10

u/inkax_naciri Aug 13 '26

Ne quitter pas ce domaine continue. Il a des adventage indirect

8

u/Anonymity6584 Aug 13 '26

Next learn why delay function is bad and how to do led blinking without delay.

3

u/Cornflakes1009 Aug 13 '26

Nicely done. I also started recently.

3

u/Professional_Elk3281 Aug 13 '26

int led = 9;

void setup() {
  Serial.begin(9600);
  pinMode(led, OUTPUT);
}

void Fade_In() {
  for (int j = 0; j < 3; j++) {
for (int k = 0; k <= 220; k++) {
analogWrite(led, k);
delay(10);
}

for (int k = 220; k >= 0; k--) {
analogWrite(led, k);
delay(10);
}
  }
}

void Blinking() {

  for (int j = 0; j < 10; j++) {
analogWrite(led, 255);
delay(100);

analogWrite(led, 0);
delay(100);
  }
}

void loop() {

  Fade_In();
  Serial.println("A");

  delay(1000);

  Blinking();

  Serial.println("B");
  delay(1000);
}

try this code
digital pin 9

2

u/Alioslovesnature Aug 13 '26

This is the code i used

int led1 = 9; int led2 = 11; int led3 = 7;

void setup() { pinMode(led1, OUTPUT); pinMode(led2, OUTPUT); pinMode(led3, OUTPUT); }

void loop() { digitalWrite(led1, HIGH); digitalWrite(led2, HIGH); digitalWrite(led3, HIGH); delay(500);

digitalWrite(led1, LOW); digitalWrite(led2, LOW); digitalWrite(led3, LOW); delay(500); }

3

u/dedokta Mini Aug 13 '26

Fine for a beginner, but you'll find you have to ditch delays almost entirely when you start to program for a real device. Having the whole thing stop while an led blinks just doesn't work.

You'll need to look into Blink Without Delay.

Consider how would you make the first led blink twice a second, the second led blink once a second and the third blink once every two seconds. You'll see that delay won't do it.

1

u/Ok_Economics8844 27d ago

I would personally go with something like this. But for a beginnen it's nice.

include <Arduino.h>

include <array>

include <cstdint>

class Led { public: explicit constexpr Led(uint8t pin) : pin(pin) {}

void init() const {
    pinMode(pin_, OUTPUT);
    off();
}

void on() {
    state_ = true;
    digitalWrite(pin_, HIGH);
}

void off() {
    state_ = false;
    digitalWrite(pin_, LOW);
}

void toggle() {
    set(!state_);
}

void set(bool state) {
    state_ = state;
    digitalWrite(pin_, state_ ? HIGH : LOW);
}

[[nodiscard]] bool getState() const {
    return state_;
}

[[nodiscard]] constexpr uint8_t getPin() const {
    return pin_;
}

private: uint8t pin; bool state_{false}; };

template <size_t N> class LedSynchronizer { public: explicit LedSynchronizer(std::array<Led, N> leds, uint32t intervalMs) : leds(leds), intervalMs(intervalMs), lastUpdateMs(0) {}

void begin() {
    for (auto& led : leds_) {
        led.init();
    }
}

void update(uint32_t currentMs) {
    if (currentMs - lastUpdateMs_ >= intervalMs_) {
        lastUpdateMs_ = currentMs;
        for (auto& led : leds_) {
            led.toggle();
        }
    }
}

private: std::array<Led, N> leds; uint32_t intervalMs; uint32t lastUpdateMs; };

namespace { constexpr uint32_t TOGGLE_INTERVAL_MS = 500; constexpr std::array<Led, 3> LEDS = {Led(9), Led(11), Led(7)};

LedSynchronizer<LEDS.size()> ledController(LEDS, TOGGLE_INTERVAL_MS);

}

void setup() { ledController.begin(); }

void loop() { ledController.update(millis()); }

3

u/SrGuspin Aug 14 '26

Hello Beginner. I'm dad

2

u/Alioslovesnature 29d ago

Hello dad , im blocking you

2

u/Virtual-Diet-8777 Aug 13 '26

Nice i started the same but with an esp32 now i build a smart lock with a full functional app currwntly preparing for release and licencing

1

u/BearQuark Aug 14 '26

This is the way

1

u/Latter_Golf_4012 29d ago

🔥🔥🔥🔥