LED traffic light issues

HI, I have an LED traffic light model that has been wired completeley backward in my oppinion, is there any way of converting the GND pin to a + and 3 other pins to a -?
the LED is a sealed unit with the red, yellow and green LEDs all having a common positive but 3 seperate - (GND) connections.
I have run the below code, but obviously it needs 3 + and one -, can this be reversed?

// Arduino Trafic Lights - www.101computing.net/arduino-traffic-lights
void setup()
{
  pinMode(13, OUTPUT); // Red LED
  pinMode(12, OUTPUT); // Amber LED
  pinMode(11, OUTPUT); // Green LED
}
void loop()
{
  // Green
  digitalWrite(13, LOW);
  digitalWrite(12, LOW);
  digitalWrite(11, HIGH);
  delay(3000); // Wait for 3000 millisecond(s)
  
  // Amber
  digitalWrite(12, HIGH);
  digitalWrite(11, LOW);
  delay(1000); // Wait for 1000 millisecond(s)
  // Red
  digitalWrite(13, HIGH);
  digitalWrite(12, LOW);
  delay(3000); // Wait for 3000 millisecond(s)
  // Red + Blinking Amber
  digitalWrite(13, HIGH);
  digitalWrite(11, LOW);
  for (int i = 0; i < 3; i++) {
      digitalWrite(12, HIGH);
    delay(500); // Wait for 500 millisecond(s)
      digitalWrite(12, LOW);
    delay(500); // Wait for 500 millisecond(s)
  }
}

Thank you in advance

Michael

If an LED and resistor are wired between an output pin and ground, it illuminates when you write HIGH to the pin.

If an LED and resistor are wired between Vcc (5 volts) and the pin, it illuminates when you write LOW to the pin.

So depending on how you must wires the three LEDs and three series current limiting resistor, you just adjust the code to write HIGH or LOW as appropriate for that wiring for the LED to go on or off as you desire.

a7

Do you have a part number you can reference for the LED sealed unit?
How did you wire up your circuit if the sealed LED is questionable?
You mentioned that you ran the code, with what circuit layout, and what was observed?

Hi alto777,
sorry I am new to this, so on the code just swap the HIGH for LOW and vice versa, and leave the wiring as it is? I would re wire the units but they are sealed and looks like SMD so no way will I be able to solder those with my kit.

Thank you
Michael

If they are lighting up now exactly backwards to what you are hoping to achieve then

Yes!

just say HIGH instead of LOW and vice versa.

Ppl sometimes write

const int ON = LOW;
const int OFF = HIGH;

at the top of the program, then use ON And OFF everywhere else, makes the code read better and you can change it back and forth in one place, if, say, you ever had the other kind of three LED LED.

HTH

a7

HI mr_ngineer,
the sealed unit was purchased from aliexpress (my own fault) link: https://www.aliexpress.com/item/1005005117669736.html already soldered and put together.

red LED - to pin 13
yellow Led to pin 12
Green LED to pin 11
then Black to ground
the problem is the black wire is common + and the RYG wires are all -

Thank you
Michael

show

Thanks Alto,
I will give that a go and see what happens.

Seemed like I was confused by your first comment. But looking at the link, they do have a common ground wire.

I thought they did, but the black wire is actually + and the red, yellow and green wires are all -

You have described an LED as "common anode", so this willwork.

I just want to be sure you include a series current limiting resistor in each of the the paths between Vcc and an output pin.

If you plan to have more than one illuminated at a time, each LED needs its own.

You will find the trick of fixing something "upside down" in software very handy, and it will be useful when you are dealing with push buttons, which often are wired to read LOW when pressed.

a7

I was gonna draw a schematic with my finger, this article is prettier:

RGB LED article

a7

Connect the black wire to +5V NOT ground.
A LOW will turn the light ON

1 Like

изображение
marked is the place where you solder wires from LED unit. upper three are negative.
right on the board are control pins with common anode, just like a RGB LED strip.

Hi Jim-p,

that works!
Ha

Thank you

Thank you all for your help here.

I had no idea how to solve this! other than build a new LED set and wired them as needed.

Thank you all!

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.