A stopwatch is a timer device that can be used to measure the amount of time that has elapsed between the start and stop of the timer. Stopwatches can be mechanical, electronic, or software-based.
A simple stopwatch with Arduino can be created by using the millis() function, which returns the number of milliseconds since the Arduino board began running the current sketch. By taking the difference between the start time and the current time, the elapsed time can be calculated and displayed.
The basic steps to build a stopwatch with Arduino are:
The stopwatch can be controlled by using buttons, so that it can be started, stopped, and reset as per the requirement. The stopwatch can be further enhanced by adding features like lap timing, multiple stopwatch and more.
It’s also possible to create a digital stopwatch using a software based approach, where the time can be displayed on a computer screen and can be controlled through a keyboard or mouse.
In this tutorial we will see how to create a stopwatch with the Arduino board and an LCD display:
Arduino UNO
The Arduino UNO is a microcontroller board based on the ATmega328P. It has 14 digital input/output pins, 6 analog inputs, a 16 MHz quartz crystal, a USB connection, a power jack, an ICSP header, and a reset button. It is the most popular and widely used board among the Arduino boards.
The Arduino UNO can be programmed using the Arduino programming language, which is based on C++. It uses a simple and intuitive programming environment, making it easy for beginners to get started with microcontroller programming.
The Arduino UNO can be connected to various sensors and actuators to control different devices and perform different tasks. For example, it can be used to control motors, read data from sensors, display information on an LCD screen, and communicate with other devices via serial communication protocols such as I2C and SPI.
The Arduino UNO can also be powered by a USB cable or an external power supply, making it easy to use in a wide range of projects and applications. It’s compatible with a wide range of shields (expansion boards) that adds functionality to the board, such as Ethernet, WiFi, and Bluetooth, and it’s widely supported by a strong and active community, which provides a lot of tutorials, examples and libraries to help users to get the most of the board.
LDC I2C 16×2 display
The LDC I2C 16×2 display is a type of LCD display that can display 16 characters in each of its two rows. It is controlled using the I2C protocol, which allows for easy communication with microcontrollers such as the Arduino.
The LDC I2C 16×2 display has a built-in controller called the HD44780, which handles the low-level details of controlling the display. To use the display, you need to send commands and data to the controller over the I2C bus.
To get started with using the LDC I2C 16×2 display, you’ll need to connect it to your microcontroller using the I2C pins. You’ll also need to download a library or write your own code to control the display.
Once you have the display connected and your code running, you can display text on the screen by sending commands and data to the HD44780 controller. For example, you might send a command to move the cursor to a specific location on the screen, and then send data to display text at that location.
push button
A push button is a type of switch that is activated by pressing it. It is commonly used in electronic devices, control panels, and other applications where a user needs to initiate an action or give a command. Push buttons come in different sizes, shapes, and colors, and can be designed to be momentary (meaning they only stay in the on position as long as they are being pressed) or latching (meaning they stay in the on position after being pressed until they are pressed again to turn off). They can also be illuminated or non-illuminated. They can be used to control the relay which can then control the 5V DC motor as well as other electronic devices.
connecting wires
Connecting wires are used to connect various components in an electronic circuit. They allow for the transfer of electricity, data, or signals between different devices and components.
When connecting wires to an Arduino or other microcontroller, it is important to pay attention to the correct pinout. The pinout refers to the arrangement of pins on the microcontroller and the corresponding function of each pin. The Arduino pinout can be found in the documentation provided by the manufacturer, or in various resources available online.
test plate
A test plate, also known as a test jig, is a device used to test electronic circuits and components. It is a board or plate that has been designed to hold and connect various components and devices in a specific configuration, allowing for the easy testing and measurement of their performance.
A test plate can be used to test various types of electronic circuits and components, such as microcontrollers, sensors, and actuators. It typically includes connectors and sockets for connecting wires, power supply and measurement devices such as multimeters, oscilloscopes, and power supplies.
To make the assembly, we can connect :
Here is the program to create a stopwatch and display it on an LCD display. Note: you must import the library I2c_LCD1602.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
#include <LiquidCrystal_I2C.h> // Module connection pins (Digital Pins) const int bouton = 1; int etatBouton,cp,test; LiquidCrystal_I2C lcd(0x27, 20, 4); void setup() { lcd.init(); pinMode(bouton, INPUT); etatBouton = 1; } void loop() { lcd.backlight(); etatBouton = digitalRead(bouton); if (etatBouton == 0) //if the button is pressed { test=1; cp=0; // initialize the timer to 0 while(test==1) { lcd.clear(); lcd.setCursor(0, 0); cp++; // increment the counter lcd.print(cp); delay(1000); etatBouton = digitalRead(bouton); if (etatBouton == 0) { //if the button is pressed a second time test=0; // stop the clock etatBouton = digitalRead(bouton); delay(1000); } } } } |
Mat 09-11-2323
you're not reading a duration, you're reading the number of loops of the microcontroler. you could use millis instead.