Repurposing an Old Voltmeter
How to build an humidity and temperature meter with time display from an old voltage meter casing.
Components and supplies
1
0.96 Inch I2C OLED (blue)
1
Arduino Nano R3
1
Pmod RTCC
1
DHT22 Temperature Sensor
Tools and machines
1
Hot glue gun (generic)
1
Soldering iron (generic)
Project description
Code
The code to this small project
arduino
Software for a temp, hum, time and date display.
1// Using a DHT 22 on pin 7 and a 0.96 inch OLED display 2 3#include <DHT.h> 4#include <U8g2lib.h> 5#include "RTClib.h" 6 7U8G2_SH1106_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, U8X8_PIN_NONE); 8 9RTC_DS1307 RTC; 10 11//Constants 12#define DHTPIN 7 // PIN for DHT 22 13#define DHTTYPE DHT22 //DHT 22 (AM2302) 14DHT dht(DHTPIN, DHTTYPE); 15 16//Variabler 17int count; 18int chk; //counter for cursor 19float hum; //Stores humidity value 20float temp; //Stores temperature value 21 22void setup(void) 23{ 24 u8g2.begin(); 25 RTC.begin(); 26 27 if (! RTC.isrunning()) { 28 // following line sets the RTC to the date & time this sketch was compiled 29 RTC.adjust(DateTime(__DATE__, __TIME__)); 30 } 31} 32 33void TempHum() { // write temp and hum on OLED 34 u8g2.clearBuffer(); 35 u8g2.setContrast(255); 36 u8g2.drawRFrame(0 - chk, 0, 128, 64, 7); 37 u8g2.setFont( u8g2_font_helvB24_tf); // Font 38 u8g2.setCursor( 17 - chk, 28); // Kursor 39 u8g2.print(temp, 1); // Write temp 40 u8g2.drawCircle(80 - chk, 5, 2, U8G2_DRAW_ALL); // Make a ° 41 u8g2.print(" C"); // Celsius 42 u8g2.setCursor( 17 - chk, 60); // Cursor 43 u8g2.print(hum, 1); // write hum 44 u8g2.print(" %"); // Write % 45 u8g2.sendBuffer(); 46} 47 48void dateTime() { //Write date and time on OLED 49 DateTime now = RTC.now(); 50 u8g2.clearBuffer(); 51 u8g2.drawRFrame(0 - chk, 0, 128, 64, 7); 52 u8g2.setFont( u8g2_font_timB24_tn); // Font 53 u8g2.setCursor(5 - chk, 27); // Kursor 54 if (now.hour() < 10) 55 u8g2.print("0"); 56 u8g2.print(now.hour(), DEC); // Write hour 57 u8g2.print(":"); 58 if (now.minute() < 10) 59 u8g2.print("0"); 60 u8g2.print(now.minute(), DEC); // Write hour 61 u8g2.print(":"); 62 if (now.second() < 10) 63 u8g2.print("0"); 64 u8g2.print(now.second(), DEC); 65 u8g2.setCursor( 7 - chk, 60); // Cursor 66 u8g2.setFont( u8g2_font_timB18_tn); // Font 67 u8g2.print(now.year(), DEC); // Write year 68 u8g2.print("-"); 69 if (now.month() < 10) 70 u8g2.print("0"); 71 u8g2.print(now.month(), DEC); // Write month 72 u8g2.print("-"); 73 if (now.day() < 10) 74 u8g2.print("0"); 75 u8g2.print(now.day(), DEC); // write day 76 u8g2.sendBuffer(); 77} 78 79void loop(void) 80{ 81 chk = -128; 82 do { // let Temp and hum slide in 83 TempHum(); 84 chk = chk + 1; 85 delay(1); 86 } while (chk < 1); 87 88 delay(3000); 89 90 hum = dht.readHumidity(); // read hum 91 temp = dht.readTemperature(); // read temp 92 93 chk = 0; 94 do { // let Temp and hum slide out 95 TempHum(); 96 delay(1); 97 chk = chk + 1; 98 } while (chk < 129); 99 100 chk = -128; 101 do { // let time and date slide in 102 dateTime(); 103 chk = chk + 1; 104 delay(1); 105 } while (chk < 0); 106 107 count = 0; 108 do { // split the delay of 3000 into six 500 delays to have a smoother sec display 109 dateTime(); 110 delay(10); 111 count = count + 1; 112 } while (count < 30); 113 114 chk = 0; 115 do { // let Temp and hum slide out 116 dateTime(); 117 delay(1); 118 chk = chk + 1; 119 } while (chk < 129); 120 chk = 0; 121} 122 123
Downloadable files
Fritzing Schematics
Fritzing Schematics
Fritzing Schematics
Fritzing Schematics
Comments
Only logged in users can leave comments