element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Arduino programming HELP NEEDED!!!
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Not Answered
  • Replies 44 replies
  • Subscribers 393 subscribers
  • Views 2878 views
  • Users 0 members are here
  • programming
  • rtc
  • code
  • arduino
  • relay
Related

Arduino programming HELP NEEDED!!!

Former Member
Former Member over 11 years ago

Hello! I am currently working on a project that requires a relay to be switched on at a certain time using a TinyRTC module. I understand that this should be fairly simple... but I can't get the code to play out correctly. Could someone PLEASE help me?

  • Sign in to reply
  • Cancel
  • kidiccurus
    0 kidiccurus over 11 years ago in reply to Former Member

    Great. Now make sure you update the code according to instructions. It would be embarrassing for my code to annoy the large amount of people who will be within range of the bell when it goes off. Any other requests for the code please don't hesitate to post here.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to kidiccurus

    Thank you for the code! I have one more request. I don't want to mess up the formatting in the code, so could you post it again with 10 bell timing modules? (10 different times to ring the bell)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • kidiccurus
    0 kidiccurus over 11 years ago in reply to Former Member

    Here you go. One little request from me. I you put this in a case, please could you write the number 42 on the inside, Just as a fun little hitchhikers reference.

    //Bellclock v1.0 Created by kidiccurus I alow you to use this program on the condition that no more than 1 (one) Great British Pound (GB£) of revenue will be generated as a result of its use or sale. Just put that in there to stop you selling this to anyone
    //Conect your relay to digital pin 4
    //requires the libary you just installed
     
    #include <Wire.h>
    #include "RTClib.h"
    //Please est the lenght of time (in seconds) you would like the bell to ring for here in place of the number 2. Please do not set a decimal.
    int belltime = 2;
    int relay = 4;
    RTC_DS1307 RTC;
    void setup() {
      Wire.begin();
       RTC.begin();
       pinMode(relay,OUTPUT);
    }
    void loop() {
      
     //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
      
     //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
      
     //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
      
     //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
      
      
     //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
      
      
     //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
      
     //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
     
      //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
      
      //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
      
      //This module rings the bell. In the top row, the number 12 can be changed for the hour in 24 hour format and the number 0 can be changed for the minute (0-59).
     //Please copy and paste this module as many times as required 
      if (now.hour() == 12 && now.minute() == 0){
        digitalWrite(relay,HIGH);
        delay(belltime*1000);
        digitalWrite(relay,LOW);
        delay(59000);
         };
     //This is the end of the module if you are going to copy and paste
         
      
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to kidiccurus

    Yes I can do that image Thank you again!

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • kidiccurus
    0 kidiccurus over 11 years ago in reply to Former Member

    Your welcome. Please make sure you test it. It is simple code but I don't want to make any large mistakes. Also, could you please mark my answer as correct so people know that you don't need any more help. Where is this going to be installed? It would be nice to know who I have helped plus it could could be good for a resume in the future.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to kidiccurus

    I thought I got the time set, but it isn't wanting to work. It isnt setting the time from my computer.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • kidiccurus
    0 kidiccurus over 11 years ago in reply to Former Member

    // Date and time functions using a DS1307 RTC connected via I2C and Wire lib
    
    #include <Wire.h>
    #include "RTClib.h"
    
    RTC_DS1307 RTC;
    
    void setup () {
        Serial.begin(57600);
        Wire.begin();
        RTC.begin();
    
    rtc.adjust(DateTime(2014,MONTH,DAY,HOUR,MINUTE,0));
      }
    
    }
    
    void loop () {
    
    }

    Right, try this. Line 13, replace the month day hour and minute with the correct numerical values.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to kidiccurus

    Im getting these errors when I try to upload


    Untitled_Project.ino:13:1: error: use of undeclared identifier 'rtc'

    rtc.adjust(DateTime(2014,8,23,21,18,0));

    ^
    Untitled_Project.ino:16:1: error: extraneous closing brace ('}')

    }

    ^

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • kidiccurus
    0 kidiccurus over 11 years ago in reply to Former Member

    Change rtc to RTC (block capitals)
    and delete the curly brace directly underneath it. It is quite late where I am at the moment so I am making a few silly mistakes.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Former Member
    0 Former Member over 11 years ago in reply to kidiccurus

    I got the time set, but when I upload the bellring sketch I get this


    BellRing.ino:19:7: error: use of undeclared identifier 'now'

      if (now.hour() == 21 && now.minute() == 26){

      ^
    BellRing.ino:19:27: error: use of undeclared identifier 'now'

      if (now.hour() == 21 && now.minute() == 26){

      ^
    2 errors generated.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
<>
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube