Components and supplies
DS3231MPMB1 Peripheral Module
Wire, Hook Up
Rubber feet
85C1-V 5 volt panel meter
Jumper wires (generic)
Arduino UNO
Tools and machines
Solder Wire, Lead Free
3D Printer (generic)
Laser cutter (generic)
Soldering iron (generic)
Apps and platforms
Arduino IDE
Project description
Code
Code
arduino
1// Volt Meter Clock 2// by Mark Bennett 2020 3 4#include "Wire.h" 5#define DS3231_I2C_ADDRESS 0x68 6 7// clock module connections 8// pin A5 => SCL 9// pin A4 => SDA 10// VCC and GND connected to 5V and GND 11 12int mode = 0; // 0 = run, 1 = set, 2 = show minimum, 3 = show maximum 13 14int hoursPin = 5; // pin for hours meter 15int minutesPin = 6; // pin for minutes pin 16int secondsPin = 9; // pin for seconds meter 17 18float hoursValue = 0; // variable to store current hours 19float minutesValue = 0; // variable to store current minutes 20float secondsValue = 0; // variable to store current seconds 21 22float hoursMinimum = 14; // 0-255 value to set zero position of meter 23float minutesMinimum = 14; // 0-255 value to set zero position of meter 24float secondsMinimum = 22; // 0-255 value to set zero position of meter 25 26float hoursMaximum = 230; // 0-255 value to set maximum position of meter 27float minutesMaximum = 230; // 0-255 value to set maximum position of meter 28float secondsMaximum = 236; // 0-255 value to set maximum position of meter 29 30void setup() { 31 pinMode(hoursPin, OUTPUT); 32 pinMode(minutesPin, OUTPUT); 33 pinMode(secondsPin, OUTPUT); 34 35 Wire.begin(); 36 Serial.begin(9600); 37 38 if(mode == 1){ 39 // do not use leading zero on the numbers, they will be read as octal numbers 40 // s m h day d m y 41 setDS3231time(30, 46, 16, 7, 12, 9, 20); 42 } 43} 44 45void loop() { 46 byte second, minute, hour, weekday, day, month, year; 47 48 switch(mode){ 49 case 0: 50 case 1: 51 readDS3231time(&second, &minute, &hour, &weekday, &day, &month, &year); 52 secondsValue = second; 53 minutesValue = minute; 54 hoursValue = hour; 55 56 if(hoursValue > 11){ 57 hoursValue -= 12; 58 } 59 60 analogWrite(secondsPin, secondsMinimum + (((secondsMaximum - secondsMinimum) / 60) * secondsValue)); 61 analogWrite(minutesPin, minutesMinimum + (((minutesMaximum - minutesMinimum) / 60) * minutesValue)); 62 analogWrite(hoursPin, hoursMinimum + (((hoursMaximum - hoursMinimum) / 12) * hoursValue)); 63 break; 64 case 2: 65 // these lines are for setting the maximum and minimum level for the meters when you first set up your clock 66 analogWrite(secondsPin, secondsMinimum); 67 analogWrite(minutesPin, minutesMinimum); 68 analogWrite(hoursPin, hoursMinimum); 69 break; 70 case 3: 71 analogWrite(secondsPin, secondsMaximum); 72 analogWrite(minutesPin, minutesMaximum); 73 analogWrite(hoursPin, hoursMaximum); 74 break; 75 } 76 77 delay(100); 78} 79 80byte decToBcd(byte val){ 81 return((val / 10 * 16) + (val % 10)); 82} 83 84byte bcdToDec(byte val){ 85 return ((val / 16 * 10) + (val % 16)); 86} 87 88void setDS3231time(byte second, byte minute, byte hour, byte weekday, byte day, byte month, byte year){ 89 Wire.beginTransmission(DS3231_I2C_ADDRESS); 90 Wire.write(0); 91 Wire.write(decToBcd(second)); 92 Wire.write(decToBcd(minute)); 93 Wire.write(decToBcd(hour)); 94 Wire.write(decToBcd(weekday)); 95 Wire.write(decToBcd(day)); 96 Wire.write(decToBcd(month)); 97 Wire.write(decToBcd(year)); 98 Wire.endTransmission(); 99} 100 101void readDS3231time(byte *second, byte *minute, byte *hour, byte *weekday, byte *day, byte *month, byte *year){ 102 Wire.beginTransmission(DS3231_I2C_ADDRESS); 103 Wire.write(0); 104 Wire.endTransmission(); 105 Wire.requestFrom(DS3231_I2C_ADDRESS, 7); 106 *second = bcdToDec(Wire.read() & 0x7f); 107 *minute = bcdToDec(Wire.read()); 108 *hour = bcdToDec(Wire.read() & 0x3f); 109 *weekday = bcdToDec(Wire.read()); 110 *day = bcdToDec(Wire.read()); 111 *month = bcdToDec(Wire.read()); 112 *year = bcdToDec(Wire.read()); 113} 114
Code
arduino
1// Volt Meter Clock 2// by Mark Bennett 2020 3 4#include "Wire.h" 5#define 6 DS3231_I2C_ADDRESS 0x68 7 8// clock module connections 9// pin A5 => SCL 10// 11 pin A4 => SDA 12// VCC and GND connected to 5V and GND 13 14int mode = 0; // 15 0 = run, 1 = set, 2 = show minimum, 3 = show maximum 16 17int hoursPin = 5; // 18 pin for hours meter 19int minutesPin = 6; // pin for minutes pin 20int secondsPin 21 = 9; // pin for seconds meter 22 23float hoursValue = 0; // variable to store 24 current hours 25float minutesValue = 0; // variable to store current minutes 26float 27 secondsValue = 0; // variable to store current seconds 28 29float hoursMinimum 30 = 14; // 0-255 value to set zero position of meter 31float minutesMinimum = 14; 32 // 0-255 value to set zero position of meter 33float secondsMinimum = 22; // 0-255 34 value to set zero position of meter 35 36float hoursMaximum = 230; // 0-255 37 value to set maximum position of meter 38float minutesMaximum = 230; // 0-255 value 39 to set maximum position of meter 40float secondsMaximum = 236; // 0-255 value to 41 set maximum position of meter 42 43void setup() { 44 pinMode(hoursPin, OUTPUT); 45 46 pinMode(minutesPin, OUTPUT); 47 pinMode(secondsPin, OUTPUT); 48 49 Wire.begin(); 50 51 Serial.begin(9600); 52 53 if(mode == 1){ 54 // do not use leading zero 55 on the numbers, they will be read as octal numbers 56 // s m h 57 day d m y 58 setDS3231time(30, 46, 16, 7, 12, 9, 20); 59 } 60} 61 62void 63 loop() { 64 byte second, minute, hour, weekday, day, month, year; 65 66 switch(mode){ 67 68 case 0: 69 case 1: 70 readDS3231time(&second, &minute, &hour, &weekday, 71 &day, &month, &year); 72 secondsValue = second; 73 minutesValue = minute; 74 75 hoursValue = hour; 76 77 if(hoursValue > 11){ 78 hoursValue 79 -= 12; 80 } 81 82 analogWrite(secondsPin, secondsMinimum + (((secondsMaximum 83 - secondsMinimum) / 60) * secondsValue)); 84 analogWrite(minutesPin, minutesMinimum 85 + (((minutesMaximum - minutesMinimum) / 60) * minutesValue)); 86 analogWrite(hoursPin, 87 hoursMinimum + (((hoursMaximum - hoursMinimum) / 12) * hoursValue)); 88 break; 89 90 case 2: 91 // these lines are for setting the maximum and minimum level 92 for the meters when you first set up your clock 93 analogWrite(secondsPin, 94 secondsMinimum); 95 analogWrite(minutesPin, minutesMinimum); 96 analogWrite(hoursPin, 97 hoursMinimum); 98 break; 99 case 3: 100 analogWrite(secondsPin, secondsMaximum); 101 102 analogWrite(minutesPin, minutesMaximum); 103 analogWrite(hoursPin, hoursMaximum); 104 105 break; 106 } 107 108 delay(100); 109} 110 111byte decToBcd(byte val){ 112 113 return((val / 10 * 16) + (val % 10)); 114} 115 116byte bcdToDec(byte val){ 117 118 return ((val / 16 * 10) + (val % 16)); 119} 120 121void setDS3231time(byte second, 122 byte minute, byte hour, byte weekday, byte day, byte month, byte year){ 123 Wire.beginTransmission(DS3231_I2C_ADDRESS); 124 125 Wire.write(0); 126 Wire.write(decToBcd(second)); 127 Wire.write(decToBcd(minute)); 128 129 Wire.write(decToBcd(hour)); 130 Wire.write(decToBcd(weekday)); 131 Wire.write(decToBcd(day)); 132 133 Wire.write(decToBcd(month)); 134 Wire.write(decToBcd(year)); 135 Wire.endTransmission(); 136} 137 138void 139 readDS3231time(byte *second, byte *minute, byte *hour, byte *weekday, byte *day, 140 byte *month, byte *year){ 141 Wire.beginTransmission(DS3231_I2C_ADDRESS); 142 Wire.write(0); 143 144 Wire.endTransmission(); 145 Wire.requestFrom(DS3231_I2C_ADDRESS, 7); 146 *second 147 = bcdToDec(Wire.read() & 0x7f); 148 *minute = bcdToDec(Wire.read()); 149 *hour 150 = bcdToDec(Wire.read() & 0x3f); 151 *weekday = bcdToDec(Wire.read()); 152 *day 153 = bcdToDec(Wire.read()); 154 *month = bcdToDec(Wire.read()); 155 *year = bcdToDec(Wire.read()); 156} 157
Downloadable files
Volt Meter Clock circuit
Volt Meter Clock circuit
Dial overlays
Dial overlays
Volt Meter Clock circuit
Volt Meter Clock circuit
Dial overlays
Dial overlays
Documentation
Arduino Holder
Arduino Holder
End Bracket
End Bracket
Arduino Holder
Arduino Holder
Clock board holder
Clock board holder
Front face
Front face
Front face
Front face
Base plate
Base plate
Clock board holder
Clock board holder
End Bracket
End Bracket
Comments
Only logged in users can leave comments