Go Down

Topic: Traffic light code (beginner level coding) (Read 51043 times) previous topic - next topic

kingjayjay14

void setup() {
  // initialize digital pin 13 as an output.
  pinMode(13, OUTPUT);
  pinMode(12, OUTPUT);
  pinMode(11, OUTPUT);
}

// the loop function runs over and over again forever
void loop() {
  digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(10000);                       // wait for ....
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delay(250);                       // wait for...

   digitalWrite(12, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(10000);                       // wait for .....
  digitalWrite(12, LOW);    // turn the LED off by making the voltage LOW
  delay(250);                       // wait for .....

   digitalWrite(11, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(10000);                       // wait for...
  digitalWrite(11, LOW);    // turn the LED off by making the voltage LOW
  delay(250);                       // wait for...
}

MarkoDerdic

Hi guys
I am a student and i dont understand Arduino. Can someone tell me is this program okey for traffic scoreboard?


int crvena = 7;
int zuta = 6;
int zelena = 5;
void setup()
{
  pinMode(crvena,OUTPUT);
  pinMode(zuta,OUTPUT);
  pinMode(zelena,OUTPUT);
}
void loop()
{
  digitalWrite(crvena,HIGH);
  delay(10000);
  digitalWrite(crvena,HIGH);
  digitalWrite(zuta,HIGH);
  delay(2000);
  digitalWrite(crvena,LOW);
  digitalWrite(zuta,LOW);
  digitalWrite(zelena,HIGH);
  delay(200000);
  digitalWrite(zelena,LOW);
  digitalWrite(zuta,HIGH);
  delay(1000);
}

mp_147

Hi guys,
Im new to arduino forum. Im going to create a density based traffic signal control system. I used 12 IR sensor. 3 sensor per road is converted into analog input using R-2R network. Red and green signal leds are multiplexed using not gate to reduce arduino pins. Lcd display is connected to display timings of roads. So can anyone help me for program...

dlsmith57918

Hello there!
I realize that this thread has been inactive for a while, but I am new to the Arduino environment, and am trying to learn to write code for a few projects I have in mind for the future.
The last real coding I did was over 30 years ago in compiled MS Basic. While I have seen a lot of programs written in C++, it is so different, I am having a little problem grasping some of the concepts of the language. But I will learn as I go along.

So, I found this project, and since it was something I had had in mind to do, I copied the code into the IDE and set up a breadboad with my Uno, red, yellow and green LEDs and dropping resistors.
The code ran, but needed some tweaking, and a lot of unnecessary code discarded.
It works great now, with a lot better timing on the signals.

See what you think.

 
Code: [Select]


// Traffic light code designed by Marquez Santos! (on facebook)
// Code simplified 10/17/17 by Dennis Smith
// Assigned vars to LED pin numbers.
// Assigned vars for duration of yellow lights and red light overlap.
// Connect green LED to pin 13 and 7
// Connect yellow LED to pin 12 and 6
// Connect red LED to pin 11 and 5

int var = 0;

//Assign duration for each color
int redgrnDuration = 5000;
int yelDuration = 2000;

//Assign pins for each LED
int ewRed = 11;
int nsRed = 5;
int ewYellow = 12;
int nsYellow = 6;
int ewGreen = 13;
int nsGreen = 7;


void setup()  {
// declare pins 11,12,13,5,6,7 to be outputs:
  pinMode(ewRed, OUTPUT);
  pinMode(ewYellow, OUTPUT);
  pinMode(ewGreen, OUTPUT);
  pinMode(nsRed, OUTPUT);
  pinMode(nsYellow, OUTPUT);
  pinMode(nsGreen, OUTPUT);
}

void loop(){
{
    digitalWrite(nsRed, HIGH);
    digitalWrite(ewGreen, HIGH);
    delay(redgrnDuration);
}
   
{
    digitalWrite(ewGreen, LOW);
    digitalWrite(ewYellow, HIGH);
    delay(yelDuration);
}
   
{   
    digitalWrite(ewYellow, LOW);
    digitalWrite(ewRed, HIGH);
    delay(yelDuration);   
}
   

    digitalWrite(nsRed, LOW);   
    digitalWrite(nsGreen, HIGH);
    delay(redgrnDuration);
}

{
    digitalWrite(nsGreen, LOW);
    digitalWrite(nsYellow, HIGH);
    delay(yelDuration);
}

{
    digitalWrite(nsYellow, LOW);
    digitalWrite(nsRed, HIGH);
    delay(yelDuration);
}   

    digitalWrite(ewRed, LOW);
} }
 







Go Up