Go Down

Topic: clock (second and minutes) (Read 910 times) previous topic - next topic

MostafaHamdy

i need make clock display second and minutes using arduino UNO R3

Boffin1

do a search in the box at the top of this page  for "clock display "  or similar, there have been many projects to give you ideas

MostafaHamdy

how i can set timer in arduino

Boffin1

You can either go through the examples and learn gradually,  or you can post on the " gigs and collaborations " and see if someone will design it for you for money.

PaulS

Quote
how i can set timer in arduino

Why do you think you need to?

kuhntucker

Does this help?

/*
** Arduino sketch to display date, time temperature and humidity.
** Uses LCD2004 display, Tiny RTC and DHT11 temperature and humidity sensor.
** All parts are readily found on eBay
**
** NOTES:
**    I2C pins are A4 SDA, A5 SCL on UNO, 20 SDA and 21 SCL on MEGA 2560.
**    DHT11 data connects to Pin 12. 
**    Displays time in 12 hour format.
**    Only reads DHT11 sensor every x seconds for smooth time updating
**     
**
**
** Written by Kuhntucker
** LICENSE: GNU General Public License, version 3 (GPL-3.0)
*/
unsigned long readint=15; //Read DHT11 every readint seconds.
unsigned long lasttemptime; //Used to restrict reading DHT11 to every readint seconds.
#include <LiquidCrystal_I2C.h>
#include <Wire.h>
#include <RTClib.h>
#include "DHT.h"

#define I2C_ADDR    0x3F  // Define I2C Address where the SainSmart LCD is
#define BACKLIGHT_PIN     3
#define En_pin  2
#define Rw_pin  1
#define Rs_pin  0
#define D4_pin  4
#define D5_pin  5
#define D6_pin  6
#define D7_pin  7
LiquidCrystal_I2C   lcd(I2C_ADDR,En_pin,Rw_pin,Rs_pin,D4_pin,D5_pin,D6_pin,D7_pin);

#define DHTPIN 12     // DHT11 Data Pin
#define DHTTYPE DHT11   // For DHT 11 sensor
 
DHT dht(DHTPIN, DHTTYPE);
RTC_DS1307 RTC;

void setup()
{
  lcd.begin (20,4);
  Wire.begin();
  RTC.begin();
 
  //Set the clock to the date & time this sketch was compiled.
  if (! RTC.isrunning()) {
     RTC.adjust(DateTime(__DATE__, __TIME__));
  }
 
  // Switch on the backlight and prep the LCD
  lcd.setBacklightPin(BACKLIGHT_PIN,POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.clear();
  lcd.home ();
 
  writetemphumid(0,2);  //wwrites initial temp and humidity
  lasttemptime=millis(); 
} //End setup

void loop()
{
  writedate(0,0);
  writetime(0,1);
  if(millis()-lasttemptime>1000*readint) //Reads DHT11 every readint seconds
  {
    writetemphumid(0,2);
    lasttemptime=millis();
  }
  if(millis()<lasttemptime) //Resets lasttemptime and reads DHT11 on millis() rollover, ~every 49 days.
  {
    writetemphumid(0,2);
    lasttemptime=millis();
    lcd.print("did it");
  } 
}  //End Loop

//function to write the time
void writetime(int col, int row)
{
  byte timehour;
  DateTime now = RTC.now(); //read the clock
  timehour = byte(now.hour());
  lcd.setCursor (col, row);
  if (timehour>12) timehour=(timehour-12);
  if (timehour==0) timehour=12; 
  lcd.print(timehour, DEC);
  lcd.print(':');
  if (now.minute()<=9) lcd.print("0");
  lcd.print(now.minute(), DEC);
  lcd.print(':');
  if (now.second()<=9) lcd.print("0");
  lcd.print(now.second(), DEC);
  lcd.print(" ");
  if (now.hour()>12) lcd.print("PM  "); else lcd.print("AM  ");
}  //End writetime

//function to write the date
void writedate(int col, int row)
{
  int daynumber;
  char* weekday[]={"Sunday=0 ", "Monday ", "Tuesday ", "Wednesday ",
                  "Thursday ", "Friday ", "Saturday ", "Sunday=1 "};
  DateTime now = RTC.now(); //read the clock
  if (now.hour()==0 && now.minute()==0 && now.second()<2)
  {
    lcd.setCursor(col, row);
    lcd.print("                    ");
  } 
  lcd.setCursor(col, row);
  daynumber = now.dayOfWeek();
  lcd.print(weekday[daynumber]);
  if (now.month()<=9) lcd.print("0");
  lcd.print(now.month(), DEC);
  lcd.print('/');
  if (now.day()<=9) lcd.print("0");
  lcd.print(now.day(), DEC);
  lcd.print('/');
  lcd.print(now.year(), DEC);
}  //End writedate

//function to write temperature and humidity
void writetemphumid (int col, int row)
{
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  // check if returns are valid, if they are NaN (not a number) then something went wrong!
  if (isnan(t) || isnan(h))
  {
    lcd.setCursor(col,row);
    lcd.print("Failed to read from DHT");
  }
   else {
    t=(9.0*t/5.0)+32.0;
    lcd.setCursor (col, row);
    lcd.print("Temp: ");
    lcd.print(int(t));
    lcd.print(" F");
    lcd.setCursor ( 0, (row+1));
    lcd.print("Humidity: ");
    lcd.print(int(h));
    lcd.print("%");
  }   
}  //Endwritetemphumid

Boffin1


Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy