Ingo Lohs
Published © LGPL

Analog Voltmeter Clock with Particle Photon

With little code, a chic watch can be created with an analog voltmeter

IntermediateFull instructions provided10 hours17

Things used in this project

Hardware components

Photon
Particle Photon
×1
Jumper wires (generic)
Jumper wires (generic)
×1
Voltmeter, DC Voltage
Voltmeter, DC Voltage
but not the digital version: in my case I use 3x "DH-670 DC 0-3V", because the Particle Photon output max. 3.3V PWM.
×1
Mains Power Cord, 2.1mm Barrel Plug
Mains Power Cord, 2.1mm Barrel Plug
×1
SparkFun Breadboard Power Supply 5V/3.3V
SparkFun Breadboard Power Supply 5V/3.3V
Standard Wall Power Supply with 5V
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Story

Read more

Schematics

Skala Adobe PDF

Skala MS Visio

Volts PWM MS Excel

Skala Adobe PDF german

Code

Particle Photon Code for analog Voltmeter Clock

C/C++
// Volt Clock v1.0
// Postler, tested with Photon, firmware v1.5.2
// 3x HUA DH-670 - https://www.amazon.de/gp/product/B06Y2SSP6P
// https://community.particle.io/t/re-energy-saving-while-analogoutput/56600

// https://docs.particle.io/reference/device-os/firmware/photon/#system-modes
// SYSTEM_MODE(SEMI_AUTOMATIC);
SYSTEM_MODE(AUTOMATIC);
/* The semi-automatic mode is therefore much like the automatic mode, except:
   When the device boots up, setup() and loop() will begin running immediately.
   Once the user calls Particle.connect(), the user code will be blocked while the device attempts to negotiate a connection. This connection will block execution of loop() or setup() until either the device connects to the Cloud or an interrupt is fired that calls Particle.disconnect().
*/

int pinStunde = A4;
int pinMinute = A5;
int pinSekunde = WKP;

// https://docs.particle.io/reference/device-os/firmware/argon/#particle-synctime-
#define ONE_DAY_MILLIS (24 * 60 * 60 * 1000)  // one day = 86.400.000 ms
// https://docs.particle.io/reference/device-os/firmware/photon/#enabling-backup-ram-sram-
STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));
retained unsigned long lastSync = millis();  // behält den Var-Wert auch nach Restart bei

void setup() {
    pinMode(pinStunde, OUTPUT);
    pinMode(pinMinute, OUTPUT);
    pinMode(pinSekunde, OUTPUT);
    Time.zone(+2.00); // setup a time zone, which is part of the ISO6801 format 
}

void loop() {
  if (millis() - lastSync > ONE_DAY_MILLIS) {
    // Request time synchronization from the Particle Device Cloud
    Particle.syncTime();
    waitUntil(Particle.syncTimeDone); // https://docs.particle.io/reference/device-os/firmware/photon/#particle-synctimedone-
    lastSync = millis();
  }

  int now = Time.now(); // take snapshot of time for consistent readings
  // https://docs.particle.io/reference/device-os/firmware/photon/#map-
  float h = map((float)Time.hourFormat12(now), 1.0, 12.0, 19.32, 231.82);  // 3V = 231.82 instead of 255.0
  float m = map((float)Time.minute(now), 0.0, 59.0, 0.0, 231.82);
  float s = map((float)Time.second(now), 0.0, 59.0, 0.0, 231.82); 
  analogWrite(pinStunde, h);
  analogWrite(pinMinute, m);
  analogWrite(pinSekunde, s);
    
}

Arduino Code for analog Voltmeter Clock

C/C++
// Volt Clock v1.0
// Postler, tested with Arduino 

#include <Wire.h>
#include <ds3231.h> // https://github.com/rodan/ds3231
 
struct ts t; 

int pinStunde = 5;
int pinMinute = 6;

int h; // Stunde
int m; // Minute

const float pwm_h =  21.25; // 8-bit PWM max. 255 / 12 Stunden
const float pwm_m =   4.25; // 8-bit PWM max. 255 / 60 Minuten

void setup() {
    pinMode(pinStunde, OUTPUT);
    pinMode(pinMinute, OUTPUT);
    
    // Test meters on startup
    digitalWrite(pinStunde, HIGH); 
    digitalWrite(pinMinute, HIGH);
    delay (1000);
    digitalWrite(pinStunde, LOW); 
    digitalWrite(pinMinute, LOW);
    delay (1000);

    Serial.begin(9600);
    Wire.begin();
    DS3231_init(DS3231_INTCN);
    /*----------------------------------------------------------------------------
    In order to synchronise your clock module, insert timetable values below!
    ----------------------------------------------------------------------------*/
    t.hour=18; 
    t.min=02;
    t.sec=0;
    t.mday=06;
    t.mon=06;
    t.year=2020;
 
    DS3231_set(t); 
}

void loop() {
    DS3231_get(&t);
    /*
    Serial.print("Date : ");
    Serial.print(t.mday);
    Serial.print("/");
    Serial.print(t.mon);
    Serial.print("/");
    Serial.print(t.year);
    Serial.print("\t Hour : ");
    Serial.print(t.hour);
    Serial.print(":");
    Serial.print(t.min);
    Serial.print(".");
    Serial.println(t.sec);
    */
    
    h = t.hour;
    m = t.min;

    if (h == 1 || h == 13) {
     analogWrite(pinStunde, pwm_h); // adjust 21,25 pwm (hour) meter level
      } else
    if (h == 2 || h == 14) {
     analogWrite(pinStunde, pwm_h*2); // adjust 42,50 pwm (hour) meter level
      } else
    if (h == 3 || h == 15) {
     analogWrite(pinStunde, pwm_h*3); // adjust 63,75 pwm (hour) meter level
      } else
    if (h == 4 || h == 16) {
     analogWrite(pinStunde, pwm_h*4); // adjust 85,00 pwm (hour) meter level
      } else
    if (h == 5 || h == 17) {
     analogWrite(pinStunde, pwm_h*5); // adjust 106,25 pwm (hour) meter level
      } else
    if (h == 6 || h == 18) {
     analogWrite(pinStunde, pwm_h*6); // adjust 127,50 pwm (hour) meter level
      } else
    if (h == 7 || h == 19) {
     analogWrite(pinStunde, pwm_h*7); // adjust 148,75 pwm (hour) meter level
      } else
    if (h == 8 || h == 20) {
     analogWrite(pinStunde, pwm_h*8); // adjust 170,00 pwm (hour) meter level
      } else
    if (h == 9 || h == 21) {
     analogWrite(pinStunde, pwm_h*9); // adjust 191,25 pwm (hour) meter level
      } else
    if (h == 10 || h == 22) {
     analogWrite(pinStunde, pwm_h*10); // adjust 212,50 pwm (hour) meter level
      } else
    if (h == 11 || h == 23) {
     analogWrite(pinStunde, pwm_h*11); // adjust 233,75 pwm (hour) meter level
      } else
    if (h == 0 || h == 12) {
     analogWrite(pinStunde, 255); // adjust 255 pwm (hour) meter level
      } 
      
    if (pwm_m*m < 255) {                 // increase PWM value by 4.25 each minute
      analogWrite(pinMinute, pwm_m*m);   // perfect would be 4.25 because 4.25 * 60 = 255
      } else {                           
      analogWrite(pinMinute, 255);
    }

delay(1000);
}

/*
h  pwm       v       %
12  255,00  3,300 100,0
11  233,75  3,025 91,7
10  212,50  2,750 83,3
9 191,25  2,475 75,0
8 170,00  2,200 66,7
7 148,75  1,925 58,3
6 127,50  1,650 50,0
5 106,25  1,375 41,7
4 85,00 1,100 33,3
3 63,75 0,825 25,0
2 42,50 0,550 16,7
1 21,25 0,275 8,3

*/

/*
m pwm       v       %
60  255,00  3,300 100,0
59  250,75  3,245 98,3
58  246,50  3,190 96,7
57  242,25  3,135 95,0
56  238,00  3,080 93,3
55  233,75  3,025 91,7
54  229,50  2,970 90,0
53  225,25  2,915 88,3
52  221,00  2,860 86,7
51  216,75  2,805 85,0
50  212,50  2,750 83,3
49  208,25  2,695 81,7
48  204,00  2,640 80,0
47  199,75  2,585 78,3
46  195,50  2,530 76,7
45  191,25  2,475 75,0
44  187,00  2,420 73,3
43  182,75  2,365 71,7
42  178,50  2,310 70,0
41  174,25  2,255 68,3
40  170,00  2,200 66,7
39  165,75  2,145 65,0
38  161,50  2,090 63,3
37  157,25  2,035 61,7
36  153,00  1,980 60,0
35  148,75  1,925 58,3
34  144,50  1,870 56,7
33  140,25  1,815 55,0
32  136,00  1,760 53,3
31  131,75  1,705 51,7
30  127,50  1,650 50,0
29  123,25  1,595 48,3
28  119,00  1,540 46,7
27  114,75  1,485 45,0
26  110,50  1,430 43,3
25  106,25  1,375 41,7
24  102,00  1,320 40,0
23  97,75 1,265 38,3
22  93,50 1,210 36,7
21  89,25 1,155 35,0
20  85,00 1,100 33,3
19  80,75 1,045 31,7
18  76,50 0,990 30,0
17  72,25 0,935 28,3
16  68,00 0,880 26,7
15  63,75 0,825 25,0
14  59,50 0,770 23,3
13  55,25 0,715 21,7
12  51,00 0,660 20,0
11  46,75 0,605 18,3
10  42,50 0,550 16,7
9 38,25 0,495 15,0
8 34,00 0,440 13,3
7 29,75 0,385 11,7
6 25,50 0,330 10,0
5 21,25 0,275 8,3
4 17,00 0,220 6,7
3 12,75 0,165 5,0
2 8,50  0,110 3,3
1 4,25  0,055 1,7
0 0,00  0,000 0,0

*/

/*
h pwm       v       %
12  255,00  5,000 100,0
11  233,75  4,583 91,7
10  212,50  4,167 83,3
9 191,25  3,750 75,0
8 170,00  3,333 66,7
7 148,75  2,917 58,3
6 127,50  2,500 50,0
5 106,25  2,083 41,7
4 85,00 1,667 33,3
3 63,75 1,250 25,0
2 42,50 0,833 16,7
1 21,25 0,417 8,3

*/

/*
m pwm       v       %
60  255,00  5,000 100,0
59  250,75  4,917 98,3
58  246,50  4,833 96,7
57  242,25  4,750 95,0
56  238,00  4,667 93,3
55  233,75  4,583 91,7
54  229,50  4,500 90,0
53  225,25  4,417 88,3
52  221,00  4,333 86,7
51  216,75  4,250 85,0
50  212,50  4,167 83,3
49  208,25  4,083 81,7
48  204,00  4,000 80,0
47  199,75  3,917 78,3
46  195,50  3,833 76,7
45  191,25  3,750 75,0
44  187,00  3,667 73,3
43  182,75  3,583 71,7
42  178,50  3,500 70,0
41  174,25  3,417 68,3
40  170,00  3,333 66,7
39  165,75  3,250 65,0
38  161,50  3,167 63,3
37  157,25  3,083 61,7
36  153,00  3,000 60,0
35  148,75  2,917 58,3
34  144,50  2,833 56,7
33  140,25  2,750 55,0
32  136,00  2,667 53,3
31  131,75  2,583 51,7
30  127,50  2,500 50,0
29  123,25  2,417 48,3
28  119,00  2,333 46,7
27  114,75  2,250 45,0
26  110,50  2,167 43,3
25  106,25  2,083 41,7
24  102,00  2,000 40,0
23  97,75 1,917 38,3
22  93,50 1,833 36,7
21  89,25 1,750 35,0
20  85,00 1,667 33,3
19  80,75 1,583 31,7
18  76,50 1,500 30,0
17  72,25 1,417 28,3
16  68,00 1,333 26,7
15  63,75 1,250 25,0
14  59,50 1,167 23,3
13  55,25 1,083 21,7
12  51,00 1,000 20,0
11  46,75 0,917 18,3
10  42,50 0,833 16,7
9 38,25 0,750 15,0
8 34,00 0,667 13,3
7 29,75 0,583 11,7
6 25,50 0,500 10,0
5 21,25 0,417 8,3
4 17,00 0,333 6,7
3 12,75 0,250 5,0
2 8,50  0,167 3,3
1 4,25  0,083 1,7
0 0,00  0,000 0,0

*/

Credits

Ingo Lohs

Ingo Lohs

174 projects • 156 followers
I am well over 40 years and come from the middle of Germany.

Comments

Add projectSign up / Login