I have seen and done the micro:bit project to make a simple traffic light. What I would like to do with my students is take it up notch. I am trying to figure out how to setup 4 micro:bit traffic lights that can talk to each other. What I want is to make it so they cycle around all 4 traffic lights properly as if it were a 4-way intersection.
Ooh! Interesting!
I think you could do this with the blocks in the Radio
category. One of the micro:bits would act as the controller, sending messages to the others (maybe using group codes so that you can talk to a specific micro:bit directly).
I only have one micro:bit at the moment, but I’m looking forward to giving this one a try!
Thanks AlexK. I was figuring I would use the Radio category but your comment about using one as the controller was helpful. As usual, I was making things more complicated and your idea of using one as the controller is a good start. Thanks again
Just to clarify, I don’t think you have to use a separate micro:bit as a controller, although it may make the logic of the program more clear. One of the micro:bits could serve double-duty as both a traffic light and as a controller. Having a separate controller, though, may make implementation more straightforward.
Definitely share your project(s) with us when you have something! If you’re stuck on something, we’re all happy to help, too.
P.S. Welcome to the forums!
I’m making traffic light for 4-way intersection with one microbit and using RGB LED (with ws2812b chip) for all traffic lights. This make wiring more easier, only 1 pin is used to control all the lights.
If the length of wiring is ok, I plan to use one microbit to control more than 1 intersection.
Did this work & finalise? If so I’d love to look at it!
@IIby Welcome to the Forum!
I’m not sure about @mike 's work, but here’s an example of the idea: https://www.tinkercad.com/things/diPZ3rFXPXE?sharecode=hvaCbwe_7NJztPuc83-eceR4kXavNRGDXDqfzkBuyQo
A few notes:
- I used TinkerCad rather than MakeCode to show three micro:bits. The same thing can be done in MakeCode, but some blocks are a little different.
- I used a smiley for Go, a frown for Yield, and an X for stop.
- The red micro:bit at the top is the controller and would control north/south going traffic. It controls its light and radios command to the other micro:bits. They will respond to the command based on where they are. For example, if north/south traffic has “Go”, the east/west traffic should have the “Stop”.
- All other micro:bits just listen for a radio message and turn on the right light.
- It isn’t too hard to expand it to do something like a crosswalk light, etc.
The “controller” is using the concept of a state machine. Here’s a brief intro to the idea of using state machines for traffic lights: https://www.youtube.com/watch?v=RSz70d_VH3o .