Stopwatch Using Arduino | Arduino Project

by | May 25, 2022 | Arduino, Basic Coding, Coding

Introduction

This tutorial teaches you how to make a Stopwatch using Arduino. To make this Arduino project, we will use an LCD screen to display the time of the stopwatch. Watch this video to have a better understanding of how this project works.

 

Supplies

To make a Stopwatch using Arduino, we will require the following components:

Components

Circuit Diagram

Steps To Make A Stopwatch Using Arduino

Step 1: Gather all the components on the Digital Board or Physical Table.

LCD:

Step 2: Connect the Power & the LED anode terminal of it to the 5V pin of the Arduino.

Step 3: Connect the Ground, Contrast, Read/Write & LED cathode terminals of it to the GND pin of the Arduino, as shown in the circuit.

Step 4: Connect the Register Select, Enable, & DB4 to DB7 pins of it to the 2 to 7 number pins of the Arduino, as shown in the figure.

PushButton:

Step 5: Connect the 1st terminal of it to the 5V pin of the Arduino.

Step 6: Connect the 2nd terminal of it to the GND pin of the Arduino.

Step 7: Connect the 3rd pin of it to the 9 number pin of the Arduino.

Source Code

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7);


int input = 0;
int count = 0;
void setup()
{
lcd.begin(16, 2);


pinMode(9, INPUT);
}
void loop()
{
input = digitalRead(9);


if(input == HIGH)
{
if(count % 2 == 1)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time : 00:00");
delay(2000);
}
if(count % 2 == 0)
{
for(int m = 0; count % 2 == 0; m++)
{
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Time :");
lcd.setCursor(9, 0);
lcd.print(m);
delay(1000);
}
}
count = count + 1;
}
}

Explanation of the Code

1. In the beginning, we have included the LiquidCrystal library for LCD display purposes.

2. Then, we have created its object with the name “lcd”, in which we have initialized it with the number of pins to which it is connected to the Arduino starting from Register select pin.

3. After that, we have initialized two variables input and count to 0.

4. In the setup function, we have configured pin number 9 for input purpose, and LCD will have 16 columns and 2 rows in which each cell can have one character.

5. In the loop function, we are reading the value from input pin 9 and storing it in the input variable.

6. After this, we use the if statement, in which if the value of the input is High, we increase the count variable by one and print the time in the LCD display using a for loop.

7. In the end, the delay function used here will take time in milliseconds.

Output

We will get the following output on the successful completion of the project.

Stop Watch Using Arduino - Arduino Project

On starting the simulation, after pressing the button, the time in seconds will be displayed on the LCD screen.

 

You May Also Like To Create…

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *