garysat
Published © GPL3+

Servo clock with digital display

This project uses and Arduino Nano, a DS1307 RTC, a 5V power supply, and three servos to display the time in a digital format.

BeginnerFull instructions provided4,178
Servo clock with digital display

Things used in this project

Hardware components

Arduino Nano R3
Arduino Nano R3
×1
Real Time Clock (RTC)
Real Time Clock (RTC)
×1
Breadboard (generic)
Breadboard (generic)
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Misc parts for assembly.
×1
5 V DC power supply
×1
SG90 Micro-servo motor
SG90 Micro-servo motor
×3

Story

Read more

Schematics

servodigit

diagram

Code

Servodigit

Arduino
Arduino code file
#include <SPI.h>

#include <Wire.h>
#include "RTClib.h"
#include <Servo.h> 

Servo myservo1;  // single minute servo connects to arduino pin 9          
Servo myservo2;  // tem minute servo connects to arduino pin 8
Servo myservo3;  // hour servo connects to arduino pin 7

int pos1 = 0;    
int pos2 = 0;
int pos3 = 0;

RTC_DS1307 rtc;





void setup() {
  // put your setup code here, to run once:
  myservo1.attach(9);
  myservo2.attach(8);
  myservo3.attach(7);

  Serial.begin(9600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  }
}

void loop() {
  DateTime now = rtc.now();

  int h=now.hour();
  int m=now.minute();
  int nm;  // variable used to convert to minute single digit

  // following line converts from 24 hour to 12 hour
  if (h>12) {
    h=h-12;
  }

  Serial.print(h);
  // following lines position the hour disc
  if(h==1){
    pos3=132;
  }
  if (h==2){
    pos3=120;
  }
  if (h==3){
    pos3=108;
  }
  if (h==4){
    pos3=96;
  }
  if (h==5){
    pos3=84;
  }
  if (h==6){
    pos3=72;
  }
  if (h==7){
    pos3=60;
  }
  if (h==8){
    pos3=48;
  }
  if (h==9){
    pos3=36;
  }
  if (h==10){
    pos3=24;
  }
  if (h==11){
    pos3=12;
  }
  if (h==12){
    pos3=0;
  }





  Serial.print(":");
  Serial.print(m);
  //following lines position the minutes discs
  if (m<10){
    nm=(m);
    pos2=120;
  }
  if (m>9){
    nm=(m-10);
    pos2=108;
  }
  if (m>19){
    nm=(m-20);
    pos2=96;
  }
  if (m>29){
    nm=(m-30);
    pos2=84;
  }
  if (m>39){
    nm=(m-40);
    pos2=72;
  }
  if (m>49){
    nm=(m-50);
    pos2=60;
  }


  Serial.println();
  Serial.print(nm);
  pos1=(nm * 12); // this line determines the servo 1 movement
  myservo1.write(pos1);
  myservo2.write(pos2);
  myservo3.write(pos3);

  Serial.println();
  Serial.println();
  Serial.print(pos1);
  Serial.println();
  delay (1000);

}

Credits

garysat
4 projects • 36 followers
Contact

Comments

Please log in or sign up to comment.