Arduino-powered traffic light toy for kids diecast car.
It's not perfect for publishing here, but I upload this since someone may be think it's useful.
This is an initial version and many things need to be improved.
But, what's important, it's working!
Below is the latch power circuit for the button.
Personally, I added a piezo speaker's positive end to pin 2 so that it makes sounds.
3, 4, 5 are for red, orange, and green positive LED leeds located oppose direction.
6, 7, 8 are red, orange, and green of orthogonal direction to the above ones.
I used SeeduinoXiao RP 2040, but any small Arduino fits inside the case should work with appropriate pin mapping.
It works with two AAA battries.
I purchased these springs for batteries.
https://www.amazon.com/dp/B08Y5HVKLH?ref=ppx_yo2ov_dt_b_product_details&th=1
and these red, orange, green leds.
https://www.amazon.com/dp/B09MWJ7SGF?ref=ppx_yo2ov_dt_b_product_details&th=1
https://www.amazon.com/dp/B09MWGTBW6?ref=ppx_yo2ov_dt_b_product_details&th=1
https://www.amazon.com/dp/B09MWGRRTP?ref=ppx_yo2ov_dt_b_product_details&th=1
Below is the source code for running the light.
void setup() {
pinMode(D0, OUTPUT);
digitalWrite(D0, HIGH);
pinMode(D2, OUTPUT);
pinMode(D3, OUTPUT);
pinMode(D4, OUTPUT);
pinMode(D5, OUTPUT);
pinMode(D6, OUTPUT);
pinMode(D7, OUTPUT);
}
void loop() {
for (int i = 0; i < 20; i++) {
change(0, 0);
change(1, 2);
alarm(250, 0);
change(1, 1);
delay(2000);
change(1, 0);
delay(2000);
change(0, 2);
alarm(150, 175);
change(0, 1);
delay(2000);
change(0, 0);
delay(2000);
}
digitalWrite(D0, LOW);
}
void change(int group, int color) {
if (group == 0) {
digitalWrite(D2, color == 0 ? HIGH : LOW);
digitalWrite(D3, color == 1 ? HIGH : LOW);
digitalWrite(D4, color == 2 ? HIGH : LOW);
} else if (group == 1) {
digitalWrite(D5, color == 0 ? HIGH : LOW);
digitalWrite(D6, color == 1 ? HIGH : LOW);
digitalWrite(D7, color == 2 ? HIGH : LOW);
}
}
void alarm(int duration, int gap) {
for (int i = 0; i < 5; i++) {
tone(D1, 4000, duration);
delay(gap);
tone(D1, 4000, duration);
delay(1000);
}
for (int i = 0; i < 5; i++) {
tone(D1, 4000, 250);
delay(500);
}
}
I'll try to update so that everyone not familiar to this can enjoy it.