Skip to main content

How To Make Simple Digital Clock Using Arduino UNO Very Easy Step By Step


Digital clock using Arduino UNO , TM1637 4-digit 7 segment display and DS1307 RTC module. Here I show you how to make a simple digital clock using Arduino UNO very easily.
 TM1637 4-digit 7 segment display :-  https://amzn.to/3R3KC3p
DS1307 RTC module:-    https://amzn.to/3dPDfyc  
Jumper Wire:-   https://amzn.to/3KcBIyH       

Digital clock using Arduino UNO Circuit Diagram

   
Digital clock using Arduino UNO

Project Code :- 


const int clock = 11;
const int data = 10;
uint8_t digits[] = { 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x07, 0x7f, 0x6f };
void setup()
{
setupInterrupt();
pinMode(clock, OUTPUT);
pinMode(data, OUTPUT);
start();
writeValue(0x8c);
stop();
write(0x00, 0x00, 0x00, 0x00);
}
byte tcnt2;
// set current time by editing the values at line 16 and 17
unsigned long int setMinutes = 9; // set minutes
unsigned long int setHours = 9; // set hours
unsigned long time = (setMinutes * 60 * 1000) + (setHours * 3600 *1000);
void setupInterrupt()
{
TIMSK2 &= ~(1<<TOIE2);
TCCR2A &= ~((1<<WGM21) | (1<<WGM20));
TCCR2B &= ~(1<<WGM22);
ASSR &= ~(1<<AS2);
TIMSK2 &= ~(1<<OCIE2A);
TCCR2B |= (1<<CS22) | (1<<CS20);
TCCR2B &= ~(1<<CS21);
tcnt2 = 131;
TCNT2 = tcnt2;
TIMSK2 |= (1<<TOIE2);
}
ISR(TIMER2_OVF_vect) {
TCNT2 = tcnt2;
time++;
time = time % 86400000;
}
void loop()
{
unsigned long t = (unsigned long)(time/1000);
uint8_t minutes = (byte)((t / 60) % 60);
uint8_t hours = (byte)((t / 3600) % 24);
uint8_t seconds = (byte)(t % 60);
write(digits[hours / 10], digits[hours % 10] | ((seconds & 0x01) << 7), digits[minutes / 10], digits[minutes % 10]);
}
void write(uint8_t first, uint8_t second, uint8_t third, uint8_t fourth)
{
start();
writeValue(0x40);
stop();
start();
writeValue(0xc0);
writeValue(first);
writeValue(second);
writeValue(third);
writeValue(fourth);
stop();
}
void start(void)
{
digitalWrite(clock,HIGH);
digitalWrite(data,HIGH);
delayMicroseconds(5);
digitalWrite(data,LOW);
digitalWrite(clock,LOW);
delayMicroseconds(5);
}
void stop(void)
{
digitalWrite(clock,LOW);
digitalWrite(data,LOW);
delayMicroseconds(5);


digitalWrite(clock,HIGH);
digitalWrite(data,HIGH);
delayMicroseconds(5);
}
bool writeValue(uint8_t value)
{
for(uint8_t i = 0; i < 8; i++)
{
digitalWrite(clock, LOW);
delayMicroseconds(5);
digitalWrite(data, (value & (1 << i)) >> i);
delayMicroseconds(5);
digitalWrite(clock, HIGH);
delayMicroseconds(5);
}
digitalWrite(clock,LOW);
delayMicroseconds(5);
pinMode(data,INPUT);
digitalWrite(clock,HIGH);
delayMicroseconds(5);
bool ack = digitalRead(data) == 0;
pinMode(data,OUTPUT);
return ack;
}

Comments

Popular posts from this blog

Obstacle Avoiding Robot Car Using Arduino - How To Make a Smart Car

How To Make Smart Robot Car With Arduino Obstacle avoiding robot car using Arduino, how to make a smart car with ultrasonic sensor, servo motor, and L298N motor driver module. Arduino UNO :- https://amzn.to/3MF9jky SG90 Servo Motor And HC-SR04 Ultrasonic Sensor :- https://amzn.to/3EX03pu LM298N motor driver module :- https://amzn.to/3y2tx3Y BO Motor with Wheel Pair :- https://amzn.to/38zFMu6 arduino smart car kit :- https://amzn.to/3kmtZlk Project Code :-  #include <Servo.h>          //Servo motor library. This is standard library #include <NewPing.h>        //Ultrasonic sensor function library. You must install this library //our L298N control pins const int LeftMotorForward = 7; const int LeftMotorBackward = 6; const int RightMotorForward = 4; const int RightMotorBackward = 5; //sensor pins #define trig_pin A1 //analog input 1 #define echo_pin A2 //analog input 2 #define maximum_distance 200 boolean goesForward = false; int distance = 100; NewPing sonar(trig_pin

How To Make Radar With Arduino UNO Using Ultrasonic Sensor

  Creating a radar system with an Arduino UNO and an ultrasonic sensor involves a few straight forward steps. First, you'll need to connect the ultrasonic sensor's trigger pin to one of the Arduino’s digital output pins and the echo pin to a digital input pin. Then, write a simple Arduino sketch to send a pulse from the trigger pin and measure the duration of the pulse received on the echo pin. This duration, proportional to the distance of an object from the sensor, can be calculated using the speed of sound. By continuously taking readings and mapping them to distances, you can plot these measurements to visualize objects in your environment, effectively creating a basic radar system. To display the results, you could use a serial monitor or even integrate an LCD display for real-time feedback. Here is the code below ,- //radar.ino #include <Servo.h>  const int trigPin = 9; const int echoPin = 8; long duration; int distance; Servo myServo;  void setup() {   pinMode(trig