Electronics Microcontroller (PICAXE) Project

Authors Avatar

Jake Beazley L6Ea                Page  of

  1. Microcontroller Project

Aim: To program a PICAXE microcontroller to mimic a traffic light sequence, complete with pedestrian crossing lights (and trigger switch). This could be used to control a set of pedestrian lights.

Output Ports

Key: “Tr.” represents traffic, “Pe.” represents pedestrian.

For example, the denary number “31” would translate to the byte “00011101” and would then transfer to the eight outputs, so all connected outputs would be high (and therefore lit) apart from the amber light for traffic. The binary number represents one of two logic states – 0 or 1. The three most significant bits of these bytes can be ignored for this program as they are not used.


Circuit Operation

This circuit emulates a traffic light sequence.

  • The “let pins = 9” command transfers the byte “00001001” to the 8 output pins, which lights the LEDs traffic green, and pedestrian red.
  • The “wait 60” command makes the program wait 60 seconds before moving on to the next instruction. This is so after the program has run through, the pedestrians cannot cross again in quick succession, thus avoiding too much interruption to traffic flow.
  • “pin0=1” decision has two outputs: “no” loops back to the top of the decision diamond, “yes” links to the rest of program. This checks if an input switch (a button for pedestrians) has been pressed.
  • “wait 12” lets 12 seconds elapse until the next command, this means that the lights do not change the instant the pedestrian presses the switch.
  • “let pins = 10” transfers the byte “00001010” to the outputs, which keeps the pedestrian red light on, but changes the traffic lights from red to amber.
  • “wait 3” waits 3 seconds before executing the next instruction.
  • “let pins = 12” transfers the byte “00001100” to the output pins, which again keeps the pedestrian red on, but changes the traffic light to red.
  • “wait 1” waits one second before executing “let pins = 20”, this is for safety as the traffic lights should be red before the pedestrian light turns green. 20 is the denary number that represents “00010100”, which assigns the appropriate logic level to each of the 8 output pins – in this case traffic red and pedestrian green.
  • “wait 8” allows 8 seconds for any pedestrians waiting to cross safely.
  • “let b0 = 5” assigns the value of 5 to the variable b0 (one of thirteen variable spaces in the PICAXE's RAM, each capable of storing one byte).
  • The “b0 = 0” decision diamond checks if the value stored in the register b0 is 0. If it is, then it carries on with the rest of the program, if not then the following occurs:
Join now!
  1. “let pins = 4” transfers the byte “00000100” to the outputs, i.e. all are off         bar the traffic red.
  2. “pause 600” waits 600 milliseconds before continuing.
  3. “let pins = 20” transfers the byte “00010100” to the outputs again, turning         the pedestrian green back on.
  4. “pause 600” then waits another 600 milliseconds before continuing.
  5. “let b0 = b0 - 1” subtracts one from the value stored in the register b0         each time it is executed. This then loops back up to the above decision         diamond, and the loop is executed until b0 = 0, i.e. when the ...

This is a preview of the whole essay