program for a t-intersection traffic light set up with 4 PNP inductive sensors

Hello I am very new to programming and I am doing this for a project. I was wondering if anyone could help or provide me with a program for traffic light set up of a t-intersection and using two roads they will have to PNP inductive sensors. Also, if there is no program for this I was wondering if there is a program anyone could provide like it.

thank you so much

The way that it usually works here is that help is provided when people have problems with code that they have written.

The first thing for you to do is to write down what you want the system to do. What states can it be in and under what circumstances ? What causes it to change state and what state will it move to ? Which traffic lights are on in each state ?

So far I have created this program but I am not sure if it is the same as the flowchart I have wrote

int green1 = 11;
int yellow1 = 10;
int red1 = 9;

int green2 = 8;
int yellow2 = 7;
int red2 = 6;

float metalDetected;
int monitoring;
int MetalDetection = 1;

int s1 = 5;
int s2 = 4;
int s3 = 3;
int s4 = 2;

void setup() {
// put your setup code here, to run once:
pinMode(red, OUTPUT);
pinMode(yellow, OUTPUT);
pinMode(green, OUTPUT);
pinMode(s1, INPUT);
pinMode(s2, INPUT);
pinMode(s3, INPUT);
pinMode(s4, INPUT);


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


void changeLights(){
//all reds are on the rest are off
digitalWrite(red1, HIGH);
digitalWrite(yellow1, LOW);
digitalWrite(green1, LOW);
digitalWrite(red2, HIGH);
digitalWrite(yellow2, LOW);
digitalWrite(egreen2, LOW);



I am not sure if it is the same as the flowchart I have wrote

Have you posted the correct code because nowhere in it do you read any sensors. Also, it doesn’t compile.

It would make more sense to give each of the lights a meaningful name. If the junction is a T then maybe name the LED pins for their cardinal direction such as eastRed, westRed and southRed. You could go further and use a struct for the LED pins, but my advice would be to keep it simple.

Similarly give the sensor pins meaningful names.

I just noticed that the thread title mentions 4 sensors. Where are they positioned in the T junction which only has 3 roads approaching it ?