taha_vs
Published © GPL3+

On Table Clock & Temp

Checking out time and room's temperature by one hand shake.

IntermediateShowcase (no instructions)5,196
On Table Clock & Temp

Things used in this project

Hardware components

lcd 20*4
×1
tcrt 5000
×1
lcm 1602
×1
tiny rtc i2c module
×1
lm 35
×1
Resistor 10k ohm
Resistor 10k ohm
×1
Resistor 1k ohm
Resistor 1k ohm
×1
Resistor 47.5k ohm
Resistor 47.5k ohm
×1
Arduino UNO
Arduino UNO
×1

Software apps and online services

Arduino IDE
Arduino IDE
DXP Altium Designer
Fritzing

Hand tools and fabrication machines

Soldering iron (generic)
Soldering iron (generic)

Story

Read more

Custom parts and enclosures

clk-temp-shield

PCB pic, Altium Designer

final_pcb

clk-temp-pcb

Schematics

clk&temp_schematic

Code

clk-temp-code

Arduino
// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
//rtc-lcm(sweach led ghat' beshe va 16 lcd be 6 va 15 lcd be 7 vasl beshe)-lm35(A0)-ir(57K ohm,1K ohm , be halat interrupt be paye 2 khroji mide)-lcd

#include <Wire.h>
#include<avr/sleep.h>
#include "RTClib.h"                  
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x3f or 0x27 (depends on your chip) for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3f, 20, 4);
RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"   Sunday", "   Monday", "  Tuesday", "Wednesday", " Thursday", "   Friday", " Saturday"};

void setup () {
    lcd.begin();
    rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));// to set rtc init value by your pc time
    pinMode(6,OUTPUT);  
    digitalWrite(6,0);
    pinMode(7,OUTPUT);  
    digitalWrite(7,1);
    delay(300);
    attachInterrupt(0, wakeUpNow, LOW);
    lcd.backlight();
}

void loop () {
    pinMode(7,OUTPUT);
    digitalWrite(7,1);
    pinMode(6,OUTPUT);  
    for(int i=255;i>0; i=i-4){  
     analogWrite(6,i);
     delay(20);
    }
    finFunc();
    pinMode(6,INPUT);  //to put it to HiZ to low power using
    digitalWrite(6,0);
    pinMode(7,INPUT);  //to put it to HiZ to low power using
    digitalWrite(7,0);
    lcd.clear();
    lcd.setCursor(0,1);
    lcd.print("      stand by      ");
    lcd.setCursor(0,2);
    lcd.print("  hover your hand!  ");
    sleepNow();
    lcd.clear();
}
void finFunc(){
  for(int i=0; i<25; i++){
    mainFunc();
    delay(200);
  }
}
void mainFunc(){
    int temp = (5.0 * analogRead(A0) * 100.0) / 1024;
    DateTime now = rtc.now();
    lcd.setCursor(6,0);
    if(now.hour()<10)
      lcd.print("0");
    lcd.print(now.hour(), DEC);
              Serial.print("time:  ");
              Serial.println(now.hour(), DEC);
    lcd.print(':');
    if(now.minute()<10)
      lcd.print("0");
    lcd.print(now.minute(), DEC);
    lcd.print(':');
    if(now.second()<10)
      lcd.print("0");
    lcd.print(now.second(), DEC);
    lcd.print(" ");
    lcd.setCursor(0,1);
    lcd.print(now.year(), DEC);
    lcd.print('/');
    if(now.month()<10)
      lcd.print("0");
    lcd.print(now.month(), DEC);
    lcd.print('/');
    if(now.day()<10)
      lcd.print("0");
    lcd.print(now.day(), DEC);
    lcd.setCursor(11,1);
    lcd.print(daysOfTheWeek[now.dayOfTheWeek()]);
    lcd.setCursor(8,2);
    if(temp<10)
      lcd.print("0");
    lcd.print(temp);
                  Serial.print("temp:  ");
                  Serial.println(temp);
    lcd.print((char)223);
    lcd.print("C");
    lcd.setCursor(2,3);
    if     (temp>=43)
       lcd.print("High Temp Alert!"); 
    else if(temp>=31)
       lcd.print("    Too Hot!    "); 
    else if(temp>=28)
       lcd.print("      Hot!      "); 
    else if(temp>=23)
       lcd.print("      Norm      "); 
    else if(temp>=19)
       lcd.print("      Cold      "); 
    else if(temp>=15)
       lcd.print("    Too Cold    "); 
    else
       lcd.print(" Low Temp Alert "); 
    Serial.print("dipi:  "); 
    Serial.println(digitalRead(2));
    Serial.print("");
  }
  
  void sleepNow()      
{
    set_sleep_mode(SLEEP_MODE_PWR_DOWN);   // sleep mode is set here

    sleep_enable();          // enables the sleep bit in the mcucr register
                             // so sleep is possible. just a safety pin 
    attachInterrupt(0,wakeUpNow, LOW); // use interrupt 0 (pin 2) and run function
                                       // wakeUpNow when pin 2 gets LOW 
    sleep_mode();            // here the device is actually put to sleep!!
                             // THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
    sleep_disable();         // first thing after waking from sleep:
                             // disable sleep...
    detachInterrupt(0);      // disables interrupt 0 on pin 2 so the 
                             // wakeUpNow code will not be executed 
                             // during normal running time.
}

void wakeUpNow(){}

Credits

taha_vs
3 projects • 5 followers
Contact

Comments

Please log in or sign up to comment.