Hi guys, was little bored last week, so I wanted to make something fast with Arduino just for fun. So I decided to make a Clock with some nice red display. After small research I got these parts:
Connection the OpenSegment shield was easy - I just soldered some pins on it. Arduino examples on the page worked grate. After this one I wanted to add the RTC module. So I hooked it up as descibed on the example page too. I used Analog 4 and 5 pins - seems they don’t interfere with the OpenSegment Shield. Finally I had to add the RHT03 sensor , which was easiest since it uses only one digital pin. I chosed pin5 for this - it looked unused on 7-Segment.
Alfter the wirering I set and started to work with Arduino examples with these modules. The 7-Segment Shield has several ways to communicate with arduino (Serial/SPI/I2c), but I chosed Serial because only there I found example to use dots.
Thanks to all good people who wrote these wiring diagrams and code examples , I have now nice and working clock which shows time + temperature and humidity :dance: The only thing left is to find some nice box for the project and to thing on the power. It seems that whole thing drains power a lot. I tried to power it with 850 mAh / 2S LiPo battery but it dried it for about 8 hours. So maybe external power will be needed.
Here is the page that was very helpfull:
https://github.com/sparkfun/Serial7SegmentDisplay/
RHT03 examples by Tihomir Trifonov (page is in Bulgarian so you can use google translator)
http://playground.arduino.cc/Bulgarian/Dht22
RTC1307 module examples by John Vaughters
http://combustory.com/wiki/index.php/RT … Time_Clock
Here is some pictures of the parts and final project:
http://airguns.bg/files/cdman/arduino_clock/arduino.jpg
http://airguns.bg/files/cdman/arduino_c … splay1.jpg
http://airguns.bg/files/cdman/arduino_clock/rtc.jpg
http://airguns.bg/files/cdman/arduino_c … hookup.jpg
http://airguns.bg/files/cdman/arduino_clock/rht03.jpg
http://airguns.bg/files/cdman/arduino_clock/clock.JPG
And Finally here is the Arduino Code
/*
* Arduino Clock with RTC Module + OpenSegment Shield - Red and RHT03 Sensor
* can give time, and every 20 seconds show humidity and then temperature.
*
* Code is just combination of examples I found for these nice modules.
*
* OpenSegment Shield Examples
* https://github.com/sparkfun/Serial7SegmentDisplay/
*
* RHT03 examples by Tihomir Trifonov
* http://playground.arduino.cc/Bulgarian/Dht22
*
* RTC1307 module examples by John Vaughters
* http://combustory.com/wiki/index.php/RTC1307_-_Real_Time_Clock
*
* Version 1.0 , 31 July 2014 by Svetlin Simeonov
*/
#include <SoftwareSerial.h>
#include "Wire.h"
#define DS1307_I2C_ADDRESS 0x68 // This is the I2C address
#define I2C_WRITE Wire.write
#define I2C_READ Wire.read
#define APOSTROPHE 5
#define COLON 4
#define DECIMAL4 3
#define DECIMAL3 2
#define DECIMAL2 1
#define DECIMAL1 0
SoftwareSerial Serial7Segment(7, 8); //RX pin, TX pin
int cycles = 0;
int i;
byte second, minute, hour, dayOfWeek, dayOfMonth, month, year,mm,hh;
byte test;
byte zero;
boolean colonOn = false;
char curtime[100];
int count=0;
int maxcount=20; // how many seconds to wayt until show humidity/temp
byte brightnessLevel = 30; // 0 to 100 %
// RTH03
byte dht_dpin = 5; // pin for RTH03 temperature sensor
byte dht_dat[5]; // temperature data array
// Convert binary coded decimal to normal decimal numbers
byte bcdToDec(byte val) { return ( (val/16*10) + (val%16) ); }
int getMM()
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
I2C_WRITE(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
second = bcdToDec(I2C_READ() & 0x7f);
minute = bcdToDec(I2C_READ());
hour = bcdToDec(I2C_READ() & 0x3f); // Need to change this if 12 hour am/pm
dayOfWeek = bcdToDec(I2C_READ());
dayOfMonth = bcdToDec(I2C_READ());
month = bcdToDec(I2C_READ());
year = bcdToDec(I2C_READ());
return minute;
}
int getHH()
{
// Reset the register pointer
Wire.beginTransmission(DS1307_I2C_ADDRESS);
I2C_WRITE(zero);
Wire.endTransmission();
Wire.requestFrom(DS1307_I2C_ADDRESS, 7);
// A few of these need masks because certain bits are control bits
second = bcdToDec(I2C_READ() & 0x7f);
minute = bcdToDec(I2C_READ());
hour = bcdToDec(I2C_READ() & 0x3f); // Need to change this if 12 hour am/pm
dayOfWeek = bcdToDec(I2C_READ());
dayOfMonth = bcdToDec(I2C_READ());
month = bcdToDec(I2C_READ());
year = bcdToDec(I2C_READ());
return hour;
}
// RTH03 functions
void InitDHT(){
pinMode(dht_dpin,OUTPUT);
digitalWrite(dht_dpin,HIGH);
}
void StartDHT22(){
// start signal
pinMode(dht_dpin,OUTPUT);
digitalWrite(dht_dpin,LOW);
delay(1);
digitalWrite(dht_dpin,HIGH);
delayMicroseconds(40);
// wait for answer
pinMode(dht_dpin,INPUT); // now pin goes INPUT
while(digitalRead(dht_dpin) == LOW);
while(digitalRead(dht_dpin) == HIGH);
}
byte readByte(){
byte result = 0;
for(byte i=0; i< 8; i++){ // read 8 bytes
while(digitalRead(dht_dpin) == LOW);
delayMicroseconds(45);
if (digitalRead(dht_dpin) == HIGH)
result |= (1 << (7 - i)); // counts byt for 1 and add to possition
while (digitalRead(dht_dpin)==HIGH); // waits for new byte signal
}
return result;
}
// Main program
void setup() {
Wire.begin();
zero=0x00;
Serial.begin(9600);
Serial7Segment.begin(9600); //Talk to the Serial7Segment at 9600 bps
Serial7Segment.write('v'); //Reset the display - this forces the cursor to return to the beginning of the display
Serial7Segment.print("0822"); //Send the hour and minutes to the display
Serial7Segment.write(0x7A); // Brightness control command
Serial7Segment.write((byte) brightnessLevel); // 0 is dimmest, 255 is brightest
sprintf(curtime, "b%03d", brightnessLevel); //Convert deciSecond into a string that is right adjusted
Serial7Segment.print(curtime);
InitDHT();
//delay(1000);
}
void loop()
{
//Blink the colon every other second
if(colonOn == true)
{
colonOn = false;
Serial7Segment.write(0x77); // Decimal, colon, apostrophe control command
Serial7Segment.write((byte) 0); // Turns off colon, apostrophoe, and all decimals
}
else
{
colonOn = true;
Serial7Segment.write(0x77); // Decimal, colon, apostrophe control command
Serial7Segment.write( (1<<APOSTROPHE) | (1<<COLON) | (1<<DECIMAL2) ); // Turns on colon, apostrophoe, and far-right decimal
}
if((count>maxcount) && (colonOn == true)) {
// display other
StartDHT22();
for (byte i=0; i<5; i++) { dht_dat[i] = readByte(); }
byte checksum = dht_dat[0] + dht_dat[1] + dht_dat[2 ] + dht_dat[3];
if(dht_dat[4] == checksum) { // if data is correct
//// finds whole and fract part for humidity
int HighByte = dht_dat[0]; // first byte
int LowByte = dht_dat[1]; // second byte
int TReading = (HighByte << 8) + LowByte;
int Whole = TReading / 10; // whole part
int Fract = TReading % 10; // fract part
// print in serial monitor
Serial.print("humdity = ");
Serial.print(Whole);
Serial.print(".");
Serial.print(Fract);
Serial.print("% ");
// display fix to display temperature and humidity as 26.10 instead of 26.01
// since sensor has 0.1 accuracy
if(Fract<10) Fract = Fract * 10;
sprintf(curtime, "%02d%02d", Whole, Fract);
Serial7Segment.print(curtime);
delay(2000);
// same procedure now for temperature
HighByte = dht_dat[2]; // third byte
LowByte = dht_dat[3]; // fourth byte
TReading = (HighByte << 8) + LowByte;
Whole = TReading / 10;
Fract = TReading % 10;
// display fix
if(Fract<10) Fract = Fract * 10;
// prints in serial monitor
Serial.print("temperature = ");
int SignBit = TReading & 0x8000; // check sign of temperature
if (SignBit) // if it's bellow zero
Serial.print("-"); // we set dash
Serial.print(Whole);
Serial.print(".");
Serial.print(Fract);
Serial.println("C ");
sprintf(curtime, "%02d%02d", Whole, Fract);
Serial7Segment.print(curtime);
delay(2000);
}
// we zero counter again - so it waits another
// maxcount cycles before display this
count=0;
} else {
// display time
hh=getHH();
mm=getMM();
sprintf(curtime, "Time: %02d:%02d", hh, mm);
Serial.println(curtime);
sprintf(curtime, "%02d%02d", hh, mm);
Serial7Segment.print(curtime); //Send serial string out the soft serial port to the S7S
}
delay(1000);
count++;
}
](Humidity and Temperature Sensor - DHT20 - SEN-18364 - SparkFun Electronics)](https://www.sparkfun.com/products/12708)](https://www.sparkfun.com/products/11849)](https://www.sparkfun.com/products/11021)