Puffin Crossing

Hi,

I am looking for help writing software for a puffin crossing (Puffin Crossings use traffic lights to stop vehicle traffic, allowing pedestrians to cross . Pedestrians push a button at the side of the road, and wait for a signal to cross - this is from a standing red man to a walking green man. A beeping sound is usually heard when the walking green man is shown)

I would be massively grateful if someone could help me on this!

Lots here that can help.

Show us your attempt.


Always show us a good schematic of your proposed circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.


In the Arduino IDE, use Ctrl T or CMD T to format your code then copy the complete sketch.
Use the </> icon from the ‘reply menu’ to attach the copied sketch.

Hi Larry,

Thanks for responding. I haven't got an attempt. I had a short amount of experience about 4 months ago but have since had to prioritise other things so I am at a huge brick wall at the moment!

You might start with a Google search for "arduino traffic lights walk button" to see what others have done.

Thank you :slightly_smiling_face:

What have you done with the Arduino in the past ?


int red = 10;
int yellow = 9;
int green = 8;
int button = 12; // switch is on pin 12

void setup() {
  pinMode(red, OUTPUT);
  pinMode(yellow, OUTPUT);
  pinMode(green, OUTPUT);
  pinMode(button, INPUT);
  digitalWrite(green, HIGH);
}

void loop() {
  if (digitalRead(button) == HIGH) {
    delay(15); // software debounce
    if (digitalRead(button) == HIGH) {
      // if the switch is HIGH, ie. pushed down - change the lights
      changeLights();
      delay(15000); // wait for 15 seconds
    }
  }
}

void changeLights() {
  // green off, yellow on for 3 seconds
  digitalWrite(green, LOW);
  digitalWrite(yellow, HIGH);
  delay(3000);
  // turn off yellow, then turn red on for 5 seconds
  digitalWrite(yellow, LOW);
  digitalWrite(red, HIGH);
  delay(5000);
  // red and yellow on for 2 seconds (red is already on though)
  digitalWrite(yellow, HIGH);
  delay(2000);
  // turn off red and yellow, then turn on green
  digitalWrite(yellow, LOW);
  digitalWrite(red.LOW);
  digitalWrite(green, HIGH);
  delay(3000);
}

Arduino: 1.8.19 (Mac OS X), Board: "Arduino Uno"

In file included from sketch/Arrays.ino.cpp:1:0:
/Users/Will/Desktop/Arrays/Arrays.ino: In function 'void changeLights()':
/private/var/folders/k1/jhy9d4r95m1c84q92wt_g40c0000gn/T/AppTranslocation/591A07E0-FEB3-43C1-A99F-8B90A643AC20/d/Arduino.app/Contents/Java/hardware/arduino/avr/cores/arduino/Arduino.h:41:14: error: expected unqualified-id before numeric constant
#define LOW 0x0
^
/Users/Will/Desktop/Arrays/Arrays.ino:41:20: note: in expansion of macro 'LOW'
digitalWrite(red.LOW);
^~~
exit status 1
Error compiling for board Arduino Uno.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

I have this error code, any ideas???

Simple typing error, look at the other digitalWrite statements.

Hi David,
I must be missing it, it all looks correct to me :face_with_raised_eyebrow:

Wait, I think i see it

I placed a full stop instead of a comma

What, if anything, is wrong with the sketch you posted? You only mentioned some, "huge brick wall". But we can't imagine what it is.

Please re-read reply #2 carefully.

Screenshot 2022-08-14 at 15.02.43

The red rail is for Positive (5V) stuff; the blue rail is for Negative (GND) stuff.

You haven't yet told us what the problem is, if any.

I can't get anything to happen on the breadboard. I am presuming with the code I have written, when I press the button I expect the lights to work

What color bands are on your resistances?
I cannot see it from your picture.

You might also add a Serial.print(button); in your loop to see the status of the button (pressed and unpressed). Maybe your switch needs to be turned by 90 degrees.

Also your LED's may be the wrong way around.
The flat side should point to - (the bunch of black wires).

Also it is 'rule' to connect blue to blue and red to red on the long side of your breadboard as already indicated by @runaway_pancake .

1 Like