Μετάβαση στο κύριο περιεχόμενο

Σχολικό κουδούνι

Η κατασκευή έχει γίνει αρχικά με τη χρήση ενός buzzer συνδεδεμένου στη ψηφιακή θύρα 2. Μπορεί να διευρυνθεί αν χρησιμοποιήσουμε relay και δίοδο ώστε να ενεργοποιείται και κουδούνι που είναι σε υψηλότερη τροφοδοσία. Χρειάζονται οι παρακάτω βιβλιοθήκες

TIME

https://drive.google.com/file/d/16c-_37eyNs939HosgXGWt9_gO1FCFxGW/view?usp=drive_link

DS1307RTC

https://drive.google.com/file/d/1kJWMbuPm3loCry7qzBBbhwpxvVy_iM94/view?usp=drive_link

Για την οθόνη LCD I2C χρειάζεται 

https://drive.google.com/file/d/1OPMAmsVRVzX4PpuPRF2CxV5Eiw2gs5Jy/view?usp=drive_link

Ακολουθεί ο κώδικας αρχικοποίησης του ρολογιού RTC 

#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>
int P=A3; //Assign power pins for RTC
int N=A2;
const char *monthName[12] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
tmElements_t tm;
void setup() {
pinMode(P,OUTPUT);
pinMode(N,OUTPUT);
digitalWrite(P,HIGH);
digitalWrite(N,LOW);
bool parse=false;
bool config=false;
// get the date and time the compiler was run
if (getDate(__DATE__) && getTime(__TIME__)) {
parse = true;
// and configure the RTC with this info
if (RTC.write(tm)) {
config = true;
}
}
Serial.begin(9600);
while (!Serial) ; // wait for Arduino Serial Monitor
delay(200);
if (parse && config) {
Serial.print("DS1307 configured Time=");
Serial.print(__TIME__);
Serial.print(", Date=");
Serial.println(__DATE__);
} else if (parse) {
Serial.println("DS1307 Communication Error :-{");
Serial.println("Please check your circuitry");
} else {
Serial.print("Could not parse info from the compiler, Time=\"");
Serial.print(__TIME__);
Serial.print("\", Date=\"");
Serial.print(__DATE__);
Serial.println("\"");
}
}
void loop() {
}
bool getTime(const char *str)
{
int Hour, Min, Sec;
if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
tm.Hour = Hour;
tm.Minute = Min;
tm.Second = Sec;
return true;
}
bool getDate(const char *str)
{
char Month[12];
int Day, Year;
uint8_t monthIndex;
if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
for (monthIndex = 0; monthIndex < 12; monthIndex++) {
if (strcmp(Month, monthName[monthIndex]) == 0) break;
}
if (monthIndex >= 12) return false;
tm.Day = Day;
tm.Month = monthIndex + 1;
tm.Year = CalendarYrToTm(Year);
return true;
}

Στη συνέχεια ο κώδικας για τον προγραμματισμό του σχολικού κουδουνιού

   /*
Modified on Nov 24, 2020
Modified by MehranMaleki from Arduino Examples
Modified by Panagiotis Toumpaniaris on March 3,2024
*/



#include <Wire.h>
#include <DS1307RTC.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);  // I2C address 0x27, 16 column and 2 rows

const char *monthName[12] = {
  "Jan", "Feb", "Mar", "Apr", "May", "Jun",
  "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
tmElements_t tm;


void setup() {
  Serial.begin(9600);
  pinMode(2,OUTPUT);
  digitalWrite(2,LOW);
  lcd.init();         // initialize the lcd
  lcd.backlight();    // open the backlight
  while (!Serial) ; // wait for serial
  delay(200);


  bool parse=false;
  bool config=false;

  // get the date and time the compiler was run
  if (getDate(__DATE__) && getTime(__TIME__)) {
    parse = true;
    // and configure the RTC with this info
    if (RTC.write(tm)) {
      config = true;
    }
  }

  if (parse && config) {
    Serial.print("DS1307 configured Time=");
    Serial.print(__TIME__);
    Serial.print(", Date=");
    Serial.println(__DATE__);
  } else if (parse) {
    Serial.println("DS1307 Communication Error :-{");
    Serial.println("Please check your circuitry");
  } else {
    Serial.print("Could not parse info from the compiler, Time=\"");
    Serial.print(__TIME__);
    Serial.print("\", Date=\"");
    Serial.print(__DATE__);
    Serial.println("\"");
  }
}


void loop() {
// Set time1
 settimes(8,15);

// set time2
 settimes(9,0);
  settimes(9,5);

  // set time3
  settimes(9,50);
   settimes(10,0);
  // set time4
  settimes(10,45);
 settimes(10,55);
 // set time 5
  settimes(11,40);
   settimes(11,50);
   // set time 6
    settimes(12,35);
     settimes(12,40);
     // set time 7
      settimes(13,25);
       settimes(13,35);
     //set time 8
     settimes(14,10);  
  if (RTC.read(tm)) {
    Serial.print("Ok, Time = ");
    print2digits(tm.Hour);
    Serial.write(':');
    print2digits(tm.Minute);
    Serial.write(':');
    print2digits(tm.Second);
    Serial.print(", Date (D/M/Y) = ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();
     lcd.clear();
  lcd.setCursor(0, 0);       // start to print at the first row
   print2digits1(tm.Hour);
    lcd.print(':');
    print2digits1(tm.Minute);
    lcd.print(':');
    print2digits1(tm.Second);
 
  lcd.setCursor(0, 1);       // start to print at the second row
  lcd.print(tm.Day);
    lcd.write('/');
    lcd.print(tm.Month);
    lcd.write('/');
    lcd.print(tmYearToCalendar(tm.Year));

  // delay(500);
 
  } else {
    if (RTC.chipPresent()) {
      Serial.println("The DS1307 is stopped.  Please run the SetTime");
      Serial.println("example to initialize the time and begin running.");
      Serial.println();
    } else {
      Serial.println("DS1307 read error!  Please check the circuitry.");
      Serial.println();
    }
    delay(9000);
  }
  delay(1000);
}



void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}

void print2digits1(int number) {
  if (number >= 0 && number < 10) {
    lcd.print('0');
  }
  lcd.print(number);
}


bool getTime(const char *str)
{
  int Hour, Min, Sec;

  if (sscanf(str, "%d:%d:%d", &Hour, &Min, &Sec) != 3) return false;
  tm.Hour = Hour;
  tm.Minute = Min;
  tm.Second = Sec;
  return true;
}


bool getDate(const char *str)
{
  char Month[12];
  int Day, Year;
  uint8_t monthIndex;

  if (sscanf(str, "%s %d %d", Month, &Day, &Year) != 3) return false;
  for (monthIndex = 0; monthIndex < 12; monthIndex++) {
    if (strcmp(Month, monthName[monthIndex]) == 0) break;
  }
  if (monthIndex >= 12) return false;
  tm.Day = Day;
  tm.Month = monthIndex + 1;
  tm.Year = CalendarYrToTm(Year);
  return true;
}

void settimes(int h1,int m1) {
   if(tm.Hour==h1 and tm.Minute==m1) {
      if (tm.Second > 0 & tm.Second<5) {
         digitalWrite(2,HIGH);
          // delay(1000);
                                       }
    else if(tm.Second < 2 or tm.Second >4){
      digitalWrite(2,LOW);
      delay(100);
    }
}
}


Σχόλια

Δημοφιλείς αναρτήσεις από αυτό το ιστολόγιο

PWM στο Arduino

  PWM στο Arduino Εισαγωγή στο PWM Η διαμόρφωση πλάτους παλμού (PWM)   είναι μια τεχνική με την οποία το πλάτος ενός παλμού μεταβάλλεται διατηρώντας τη συχνότητα του κύματος σταθερή. Είναι μια μέθοδος παραγωγής αναλογικού σήματος με χρήση ψηφιακής πηγής. Γενιά PWM   Ένα σήμα PWM αποτελείται από δύο κύρια στοιχεία που καθορίζουν τη συμπεριφορά του: έναν  κύκλο λειτουργίας  και μια  συχνότητα  .   Τι είναι ο κύκλος λειτουργίας του σήματος Η περίοδος ενός παλμού αποτελείται από έναν  κύκλο  ON   (5V) και έναν    κύκλο  OFF  (0V). Το κλάσμα για το οποίο το σήμα είναι ενεργοποιημένο για μια περίοδο είναι γνωστό ως   κύκλος λειτουργίας  . Π.χ.  Ένας παλμός με περίοδο 10 ms θα παραμείνει ενεργός (υψηλό) για 2 ms. Επομένως, ο κύκλος λειτουργίας θα είναι D = 2ms / 10ms = 20%   Μέσω της τεχνικής PWM, μπορούμε να ελέγξουμε την ισχύ που παρέχεται στο φορτίο χρησιμοποιώντας το σήμα ON-O...

Tmp36GZ θερμόμετρο με LCD οθόνη

 Tmp36GZ με LCD οθόνη // Define to which pin of the Arduino the output of the TMP36 is connected: #include <LiquidCrystal_I2C.h> // Look for LiquidCrystal I2C library by Marco Schwartz LiquidCrystal_I2C lcd ( 0x 27 , 16 , 2 ) ;  // set the LCD address to 0x3F for a 16 chars and 2 line display #define sensorPin A0 void setup () {   // Begin serial communication at a baud rate of 9600:   Serial . begin ( 9600 ) ;   lcd . init () ;   lcd . clear () ;           lcd . backlight () ;      // Make sure backlight is on     // Print a message on both lines of the LCD.   lcd . setCursor ( 2 , 0 ) ;   //Set cursor to character 2 on line 0   lcd . print ( "Hello world!" ) ;     lcd . setCursor ( 2 , 1 ) ;   //Move cursor to character 2 on line 1   lcd . print ( "LCD Tutorial" ) ; } void loop () {   // Get a reading from the temperature sensor:   int reading ...

Πώς να χρησιμοποιήσετε ένα Breadboard

  Πώς να χρησιμοποιήσετε ένα Breadboard Το breadboard έχει εσωτερικές συνδέσεις μεταξύ των οπών του. Μερικές κάθετες συνδέσεις και μερικές οριζόντιες συνδέσεις. Κανονικά, χρησιμοποιείτε τις κολώνες στα πλάγια για να συνδέσετε το τροφοδοτικό σας. Και χρησιμοποιείτε τις σειρές στη μέση για να συνδέσετε τα στοιχεία σας. Στήλες Τροφοδοτικού Είναι σύνηθες να χρησιμοποιείτε τις στήλες στα αριστερά και δεξιά για τη σύνδεση του τροφοδοτικού. Αυτές οι στήλες συνδέονται κάθετα. Έτσι, εάν συνδέσετε 5 βολτ στην επάνω οπή μιας από τις πλευρικές κολώνες, θα έχετε 5 βολτ σε όλες τις οπές αυτής της στήλης. Χρησιμοποιήστε τις στήλες που επισημαίνονται με κόκκινη γραμμή για το συν και τη στήλη με μπλε γραμμή για το μείον. Τέλος φόρμας Σημείωση: Μερικές μεγαλύτερες πλάκες   breadboard χωρίζονται στα δύο έτσι ώστε το πάνω μισό να αποσυνδεθεί από το κάτω μισό. Αυτό υποδεικνύεται από τις κατακόρυφες μπλε και κόκκινες γραμμές που χωρίζονται στα δύο.   Περιοχή Συστατικού Σ...