Arduino Controlled Pinewood Derby

by moores1 in Circuits > Arduino

268 Views, 0 Favorites, 0 Comments

Arduino Controlled Pinewood Derby

WIN_20221206_13_27_38_Pro.jpg

I was asked by a science teacher at my school for help with a problem of his. He needed a way to automatically start a pinewood derby race set-up for a lesson and easily indicate who won. I was happy to help and came up with a circuit system that does all of that using an Arduino. This is only the system that automates the process. Pinewood derby track and cars are still required.

Supplies

Screenshot_20221211_080515.png
Screenshot_20221211_080638.png
Screenshot_20221211_080720.png
Screenshot_20221211_080807.png
Screenshot_20221211_080853.png
Screenshot_20221211_080935.png
Screenshot_20221211_081009.png
Screenshot_20221211_081056.png
Screenshot_20221211_081139.png
Screenshot_20221211_081241.png

1 Arduino

1 Breadboard

10 M-M Wires

6 F-M Wires

8 Resistors

3 Red LEDs

1 Yellow LED

1 Green LED

1 Pushbutton

1 Piezo Speaker

1 DC Motor

2 PIR Motion Sensors

Building- Gather Supplies

Screenshot_20221211_081433.png

Most of this stuff could be found on Amazon or at your local hardware store.

Building- the Breadboard and the Arduino

Screenshot_20221207_020127.png

Connect the positive column to the 5V pin on the Arduino with an M-M wire. This will power the system.

Connect the negative column to the GND pin on the Arduino with an M-M wire. This is the system's ground.

You also need to connect both sides of the Arduino with M-M wires so each side can be powered, positive to positive and negative to negative.

Building- the First 3 LEDs

Screenshot_20221207_022055.png

Take a red, yellow, and green LED and insert them into the breadboard in succession.

Place one end of a resistor into the rows below each LED's shorter side, ensuring that the other end is connected to the negative column.

Use 3 M-M wires and connect the longer side of the red, yellow, and green LEDs to the digital pins 10, 9, and 8 on the Arduino respectively.

Building- the Pushbutton

Screenshot_20221208_022752.png

Place the push button next to the 3 LEDs with each side of the pushbutton on a different side of the breadboard.

Take an M-M wire and connect the row where the upper left corner of the pushbutton sits to the positive column on that same side.

Then use another M-M wire to connect the row below the bottom right corner of the pushbutton to the digital pin 7.

In that same row put a resistor so that it connects to the negative column.

Building- the Piezo Speaker

Screenshot_20221211_065855.png

Connect the speaker's two terminals to the breadboard.

Connect the row of the negative terminal to the negative column with a resistor and use an M-M wire to connect the row of the positive terminal to digital pin 6.

Building- the DC Motor

Screenshot_20221211_072319.png

The DC Motor should already come with wires attached, so the negative or black wire connects to the negative column and the positive or red wire connects to digital pin 5.

Building- the PIR Motion Sensors

Screenshot_20221211_073521.png

Take the first PIR Motion Sensor and, using F-M wires, connect the positive terminal to the positive column, the negative terminal to the negative column, and the signal terminal to digital pin 4.

Take the second PIR Motion Sensor and use F-M wires to connect positive to positive, negative to negative, and signal to digital pin 1.

Building- the Indicator Lights

Screenshot_20221211_074928.png

Take the two remaining LEDs and add them to the breadboard. Under the shorter terminal of each LED, place a resistor in that same row, making sure to connect each to the negative column.

Use 2 M-M wires to connect the other terminal of the left and right LED to digital pins 3 and 2 respectively.

Code the Arduino

Screenshot_20221211_080036.png

Open the Arduino IDE software on your computer and copy this code into a new blank document:

// C++ code

//

int buttonState = 0;


int sensorState = 0;


int sensorState2 = 0;


void setup()

{

 pinMode(7, INPUT);

 pinMode(10, OUTPUT);

 pinMode(6, OUTPUT);

 pinMode(9, OUTPUT);

 pinMode(8, OUTPUT);

 pinMode(5, OUTPUT);

 pinMode(4, INPUT);

 pinMode(1, INPUT);

 pinMode(3, OUTPUT);

 pinMode(2, OUTPUT);

}


void loop()

{

 // read the state of the pushbutton

 buttonState = digitalRead(7);

 // check if pushbutton is pressed. if it is, the

 // button state is HIGH

 if (buttonState == HIGH) {

  digitalWrite(10, HIGH);

  tone(6, 523, 500); // play tone 60 (C5 = 523 Hz)

  delay(1000); // Wait for 1000 millisecond(s)

  digitalWrite(9, HIGH);

  digitalWrite(10, LOW);

  tone(6, 523, 500); // play tone 60 (C5 = 523 Hz)

  delay(1000); // Wait for 1000 millisecond(s)

  digitalWrite(9, LOW);

  digitalWrite(8, HIGH);

  digitalWrite(5, HIGH);

  tone(6, 698, 2000); // play tone 65 (F5 = 698 Hz)

  delay(2000); // Wait for 2000 millisecond(s)

 } else {

  digitalWrite(10, LOW);

  digitalWrite(9, LOW);

  digitalWrite(8, LOW);

  digitalWrite(5, LOW);

 }


 // read the state of the sensor/digital input

 sensorState = digitalRead(4);

 sensorState2 = digitalRead(1);

 // check if sensor pin is HIGH. if it is, light the

 // corresponding LED

 if (sensorState == sensorState2) {

  digitalWrite(3, LOW);

  digitalWrite(2, LOW);

 }

 if (sensorState > sensorState2) {

  digitalWrite(3, HIGH);

  digitalWrite(2, LOW);

 }

 if (sensorState < sensorState2) {

  digitalWrite(3, LOW);

  digitalWrite(2, HIGH);

 }

}


Then upload the code to your Arduino.

A picture of the block code is also included if you would rather copy that and build it yourself.