Stopwatch Buzzer

by 897348 in Circuits > Arduino

78 Views, 0 Favorites, 0 Comments

Stopwatch Buzzer

IMG_2915.jpeg

This a stopwatch buzzer, so holding the button keeps track of time, and buzzes after you let go. This can be particularly useful to keep track of time and assist in time management.

Supplies

IMG_2483.jpeg
  • 4 7 segment displays 
  • 1 push button
  • to reset your stopwatch
  • 2 yellow leds
  • 2 green leds
  • 8 330 resistors 
  • 1 buzzer
  • Breadboard 
  • Arduino Uno
  • wires

Placing Components on the Breadboard

IMG_2834.jpeg
IMG_2831.jpeg

Place your push button, buzzer and 4 digit 7 segment display onto your breadboard. Wire your push button to the power rail and connect it to ground through a 10k resistor. Identify your pins on the 7 segment display and connect 330 ohm resistors where appropriate(all the letter pins must have resistance before connecting to the arduino). Place ground and power rails. The green wires represent the digit pins. In the image, the buzzer is not included but wire one leg to ground and the other to an arduino pin in the next step, and don't include another push button.

Wiring to Arduino

IMG_2929.jpg

The first step is to identify the pins of the 4 digit 7 segment display and their purpose to figure out the placement on the arduino. As shown in the image, the pins with a letter control each segment on the display, while the others are for the digits. There are 14 digital pins and 5 analog pins on the arduino, and there are 12 legs on the 4 digit 7 segment display, which need to be connected to the digital pins, along with one pin of the buzzer. The push button can be wired to an analog pin. Referring to the chart above, start wiring your components to the arduino.

Completed Wiring

IMG_2931.jpg

Here is the completed wiring of the stopwatch buzzer. The purple wires represent the letter pins, the yellow(and one green) represent the digit pins and the orange present miscellaneous components.

Initialising the Code

For this step, declare all your variables like follows:

int a = 2;

int b = 3;

int c = 4;

int d = 5;

int e = 6;

int f = 7;

int g = 8;

int p = 9;

int d1 = 13;

int d2 = 12;

int d4 = 10;

int push = A2;

int buzz= 1;

int num= 0;

State if each pin is an input or an output .

void setup() {

  Serial.begin(9600);

  pinMode(a, OUTPUT);

  pinMode(b, OUTPUT);

  pinMode(c, OUTPUT);

  pinMode(d, OUTPUT);

  pinMode(e, OUTPUT);

  pinMode(f, OUTPUT);

  pinMode(g, OUTPUT);

  pinMode(d1, OUTPUT);

  pinMode(d2, OUTPUT);

  pinMode(d3, OUTPUT);

  pinMode(d4, OUTPUT);

  pinMode(buzz, OUTPUT);

Create functions that display each number, since this shares a common anode, the pins have to be set at LOW to be illuminated.

This is because all the anode connections are joined together as '1' so the opposite of that is '0' which would be LOW.

Example:

void zero()

{

 digitalWrite(a, LOW);

 digitalWrite(b, LOW);

 digitalWrite(c, LOW);

 digitalWrite(d, LOW);

 digitalWrite(e, LOW);

 digitalWrite(f, LOW);

 digitalWrite(g, HIGH);

}

Then, create functions to light up each digit going from 0-9 with one second intervals to call it in the loop.

Here is an example:

void digit1

{

one();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

two();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

three();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

four();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

five();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

six();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

seven();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

eight();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

nine();

digitalWrite(d4, HIGH);

digitalWrite(d3, HIGH);

digitalWrite(d2, HIGH);

digitalWrite(d1, LOW);

digitalWrite(p, HIGH);

delay(1000);

}

Repeat this step for the others, then call it in void loop() using a for loop.

Set it to the parameters you want and call the buzzer at the end of the loop so it buzzes every time it loops.