Fast Led Traffic Light Project

Hope everyone is doing well. I am very new to arduino, but am fascinated by its many uses. I'm currently working on a school project where i have to build logic gate circuits. I have managed to get the street lights to work via AND and OR gates. Now i want to represent vehicles in roads with two different color leds one car will be Yellow the other will be blue. Doing research i have started building the code , but i don't know if its efficient and it's not working like i wish it would. i want the leds to start in different positions on the strip and adjust the speed they travel. At all times only two leds will be on (one yellow, one blue) while changing positions hence representing cars in an intersection. Additionally i was wondering if their is a way to make the leds stop at a red light (make it comunicate with the OR circuit when its HIGH to stop). Thanks in Advance!

I am Currently using WS2812B RGB Led Strip

code:

#define NUM_LEDS 14
#define COLOR_ORDER GRB
#define ledpin 7

#include <FastLED.h>
struct CRGB leds[NUM_LEDS];

void setup() {
 // put your setup code here, to run once:
delay(1000);  
FastLED.addLeds<WS2812B, ledpin, GRB>(leds, NUM_LEDS);
}

void loop() {
 // put your main code here, to run repeatedly:


for(int i=0;i<NUM_LEDS;i++){
 leds[i-2].setRGB( 0, 0, 0);
 leds[i].setRGB( 255, 255, 0);
 FastLED.show();
 delay(200);
} 
FastLED.clear();
}

Hi and welcome to the forum.

If you look closely at the code you posted, you can see that it has been corrupted by the forum and does not match the code in your ide. Can you see how the text suddenly becomes italicized? At that point, a piece of your code is missing. This happened because you didn't read the forum guide in the sticky post, which would have told you how to post code so that this does not happen. So please read the guide, then click modify on your post above and correct it so that the code is not corrupted.

Thanks!

Thank You Paul! Yes my Fault I did not read carefully. I have fixed it Thank you!

Thanks for fixing that, +1 karma.

Reading your code, I can't see how it matches your description of what is supposed to do. I don't see how it can produce 2 dots of blue and yellow. It only seems to make one dot, yellow I guess.

Additionally i was wondering if their is a way to make the leds stop at a red light (make it comunicate with the OR circuit when its HIGH to stop).

The short answer is yes, that will be possible. But the Arduino will need a connection with this "OR" circuit. You should post a schematic showing how that is wired.

Just so you know, it is not usual to mix logic circuits with Arduino in this way. Microcontrollers were invented to replace logic circuits, because a microcontroller can replace many complex logic circuits with a few lines of code. But I guess this project is an opportunity to learn about both logic circuits and microcontrollers. The logic circuits you have made could easily be removed and replaced by a few more lines of code in the Arduino sketch.

Correct i have gotten this far, but can only manage to get the code that far. I really want it to do what i described but am having trouble doing so (Still learning arduino). Would you have any suggestions on how to improve the code or structure it differently to get the results i described?

Yes, it would be easier to make everything work with the arduino. In this project the goal is to create a circuit with AND, OR gates. The arduino and Leds implementation is me going above and beyond. I want to represent the vehicles in traffic with the led lights.

please make a drawing of your project.
How many lines of traffic do you have?
how many departure pointes, how many destinations will your traffic have?
if you are doing your traffic lights with and/or gatters, what is your plan to feed the information into your Arduino, so that your cars know if the have to stop or can go? What's your interface between the traffic lights and your Arduino?

example:

Of course here is the drawing.

I don't plan on having destination i have pointed out the initial points for both vehicles.

Im still trying to figure out how to send a high signal to the arduino from the circuit and it be translated as green light therefore the car will go.


This is useful, but we also need the electrical schematic.

I don't plan on having destination i have pointed out the initial points for both vehicles.

based on your drawing your cars are only going clockwise or counterclockwise. they will never reach your center crossing. So please explain how your traffic is running or adopt the picture.

Additional: define, how many LEDs will be used per street, and add a drawing, how you would like to lay your line

Im still trying to figure out how to send a high signal to the arduino from the circuit and it be translated as green light therefore the car will go.

that depends on your circuit. Under the assumption that you are driving the LEDs high side, you could check the status with
if(digitalRead(yourArduinoPin))

you have to connect the GND of your cirucuit and the Arduino also.

noiasca:
Under the assumption that you are driving the LEDs high side, you could check the status with
if(digitalRead(yourArduinoPin))

How does that work with his WS2812 LEDs? :roll_eyes:

Paul__B:
How does that work with his WS2812 LEDs? :roll_eyes:

I got the impression that the traffic light leds are not ws2812, since they are driven by some logic chips. Only the vehicles are represented by ws2812 leds.

We are still waiting for a schematic from the OP to confirm this, of course...

Yes the gate circuit will control the traffic lights. Depending on which car (ws2812b led lights)comes to the stop light first it will trip the logic gate and the lights will change to green and the perpendicular direction lights will turn red.

What I’m wanting the Arduino to do is to represent the vehicles in the led strip and somehow communicate with the circuit gates. At the point the vehicle approach the stop lights. Additionally I have also been reminded that it may turn more complex if I want the vehicle to turn(with the drawing it only makes sense that it does). The point of communication of the circuit and the arduino would be at the stop light.

I apologize I been meaning to post the schematic which I’m working on and will post as soon as it’s complete and it seems viable.

I thought about it, how I would start.

Let's assume a basic grid of 14 x 14 WS2812.
I don't use the refuge islands / house blocks.
So I end up with 160 LEDs.

I would start with the upper part only.
One car in the green line, clockwise
(15,16,17,18,19,30,38,46,57,56,55,54,53,45,37,29, back to 15)

another blue car running clockwise (15-26, 34,42,50,64-53,45,37,29, back to 15)

A traffic light / stop at pixel 46 and vice versa one traffic light at pixel 61.

traffic_grid1.png

if this works, I would expand the grid to the lower part and introduce the next car

traffic_grid2.png

and finally if all works, I would define the counter clockwise streets + cars.

If you are a beginner with Arduino ... good luck :wink:

traffic_grid1.png

traffic_grid2.png