Automatic Bell System not working

So I am making an automatic bell system which will make a motor spin to ring the bell at certain times of day without any human input needed. I followed a YouTube video to make it however when I finished making it, I found it could not work no matter all I tried and I have almost given up, so this is really my last call for help

https://youtu.be/IXZoSdbT4Dw?si=Buo0EKpN55FgWPyW

This is the YouTube video which I used as a guide to build this

#include (Wire.h) //instead of parenthesis () put angle bracket as YouTube description does not allow angle bracket
#include (LiquidCrystal_I2C.h)
#include (DS1302.h)
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x3F, 16, 2);

int Hour;
int Min;
int Sec;
int period;
int in1 = 8; 
int in2 = 9;
int activate=0;
Time t;

// Init the DS1302
DS1302 rtc(2, 3, 4);

void setup()
{
pinMode(8, OUTPUT);
pinMode(9, OUTPUT); 
// Set the clock to run-mode, and disable the write protection
rtc.halt(false);
rtc.writeProtect(false);

// Setup LCD to 16x2 characters
lcd.begin();
Serial.begin(9600);

// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW(SUNDAY); // Set Day-of-Week to FRIDAY
// rtc.setTime(10, 30, 30); // Set the time to 12:00:00 (24hr format)
// rtc.setDate(23, 03, 2020); // Set the date to August 6th, 2010

}

void loop()
{
// Display time on the right conrner upper line

lcd.setCursor(0, 0);
lcd.print("Time: ");
lcd.setCursor(6, 0);
lcd.print(rtc.getTimeStr());
t = rtc.getTime();
Hour = t.hour;
Min = t.min;
Sec = t.sec;

//Display Period Number
lcd.setCursor(0, 1);
lcd.print("Period No: ");
lcd.setCursor(11, 1);
lcd.print(period);

//Period timing, when bell will ring, you can add more period if you want
if ((Hour== 7 && Min== 0 && Sec(= 5)||(Hour== 7 && Min== 30 && Sec(= 5)||(Hour== 8 && Min== 0 && Sec(= 5)||(Hour== 8 && Min== 30 && Sec(= 5)||(Hour== 9 && Min== 30 && Sec(= 5)||(Hour== 10 && Min== 0 && Sec(= 5)||(Hour== 10 && Min== 30 && Sec(= 5)||(Hour== 11 && Min== 0 && Sec(= 5)) {
digitalWrite(in1, HIGH); 
digitalWrite(in2, LOW);

Serial.println("motor is running");
if (activate == 0){
period = period +1;
activate =1;
}
}
else if (Hour== 9 && Min== 0 && Sec(= 7) { // Recess break time (Long ring bell)
digitalWrite(in1, HIGH); 
digitalWrite(in2, LOW);
lcd.setCursor(11, 1);
lcd.print("Break");
delay(500);
lcd.clear();
}
else if (Hour== 11 && Min== 30 && Sec(= 7) { // School time over (Long Ring bell)
digitalWrite(in1, HIGH); 
digitalWrite(in2, LOW);
lcd.setCursor(11, 1);
lcd.print("Over");
period =0;
delay(500);
lcd.clear();
}

else { // stop motor
digitalWrite(in1, LOW); 
digitalWrite(in2, LOW);
activate =0;
}

delay (500);
}

That is the unedited code and below is the edited version of it

#include <Wire.h> //instead of parenthesis <> put angle bracket as YouTube description does not allow angle bracket
#include <LiquidCrystal_I2C.h>
#include <DS1302.h>
// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd<0x3F, 16, 2>;

int Hour;
int Min;
int Sec;
int period;
int in1 = 8; 
int in2 = 9;
int activate=0;
Time t;

// Init the DS1302
DS1302 rtc<2, 3, 4>;

void setup<>
{
pinMode<8, OUTPUT>;
pinMode<9, OUTPUT>; 
// Set the clock to run-mode, and disable the write protection
rtc.halt<false>;
rtc.writeProtect<false>;

// Setup LCD to 16x2 characters
lcd.begin<>;
Serial.begin<9600>;

// The following lines can be commented out to use the values already stored in the DS1302
// rtc.setDOW<SUNDAY>; // Set Day-of-Week to FRIDAY
// rtc.setTime<10, 30, 30>; // Set the time to 12:00:00 <24hr format>
// rtc.setDate<23, 03, 2020>; // Set the date to August 6th, 2010

}

void loop<>
{
// Display time on the right corner upper line

lcd.setCursor<0, 0>;
lcd.print<"Time: ">;
lcd.setCursor<6, 0>;
lcd.print<rtc.getTimeStr<>>;
t = rtc.getTime<>;
Hour = t.hour;
Min = t.min;
Sec = t.sec;

//Display Period Number
lcd.setCursor<0, 1>;
lcd.print<"Period No: ">;
lcd.setCursor<11, 1>;
lcd.print<period>;

//Period timing, when bell will ring, you can add more period if you want
if <<Hour== 7 && Min== 0 && Sec<= 5>||<Hour== 7 && Min== 30 && Sec<= 5>||<Hour== 8 && Min== 0 && Sec<= 5>||<Hour== 8 && Min== 30 && Sec<= 5>||<Hour== 9 && Min== 30 && Sec<= 5>||<Hour== 10 && Min== 0 && Sec<= 5>||<Hour== 10 && Min== 30 && Sec<= 5>||<Hour== 11 && Min== 0 && Sec<= 5>> {
digitalWrite<in1, HIGH>; 
digitalWrite<in2, LOW>;

Serial.println<"motor is running">;
if <activate == 0>{
period = period +1;
activate =1;
}
}
else if <Hour== 9 && Min== 0 && Sec<= 7> { // Recess break time <Long ring bell>
digitalWrite<in1, HIGH>; 
digitalWrite<in2, LOW>;
lcd.setCursor<11, 1>;
lcd.print<"Break">;
delay<500>;
lcd.clear<>;
}
else if <Hour== 11 && Min== 30 && Sec<= 7> { // School time over <Long Ring bell>
digitalWrite<in1, HIGH>; 
digitalWrite<in2, LOW>;
lcd.setCursor<11, 1>;
lcd.print<"Over">;
period =0;
delay<500>;
lcd.clear<>;
}

else { // stop motor
digitalWrite<in1, LOW>; 
digitalWrite<in2, LOW>;
activate =0;
}

delay <500>;
}

Could anyone explain what I am doing wrong?

I apologize for any mistakes I have made as I am quite new to this

pinMode<8, OUTPUT>;
pinMode<9, OUTPUT>; 

It looks like you overdid the replacement of () with <>

These, and many others, should be parentheses

1 Like

Oh really? I thought they had meant to replace every parenthesis with the angled bracket. Which ones should be normal brackets and which ones should be angled brackets?

The parameters of the #includes need to be in angle brackets but all of the function calls and function definitions need have their parameters enclosed in parentheses

If you look carefully at the video from around 5 min. 22 sec. onwards, then you can see which are normal and which are angled.

Have a look at this still from 5:24, I've arrowed the three lines that need to be < >.
All the rest are ( ).

Surely there is power to your project and something happens when you turn the power on. So just writing the it doesn’t work is not very helpful nor is it correct. What does work and what does not work is important if you are explaining something to strangers.

Few forum members will spend time looking at a video, so make a drawing of your project and post it and tell us what components you are using.

If you find the LCD display doesn't work go back to 0x27, as in the comment. The 0x3F value is for the A version of the chip which is much less common.

Or run the i2c scanner sketch to detect the correct address. There are many versions floating around the internet. here’s one: A I2C Scanner for Arduino · GitHub

You can also switch to the HD44780 library which auto detects your LCD address.

Or you could just use the one in the Wire library installed with the IDE

1 Like

Hi, @regalornit
Welcome to the forum.

Does your motor spin?
If not then leave your code for the moment and write code JUST to get the motor running.

Starting with a mass of code that doesn't work is not the best way to begin.

Write your simple code to prove you can control the motor , then code to run the clock.

Can you please post a copy of YOUR circuit, a picture of a hand drawn circuit in jpg, png?
Hand drawn and photographed is perfectly acceptable.
Please include ALL hardware, power supplies, component names and pin labels.

Thanks.. Tom.... :smiley: :+1: :coffee: :australia:

I would agree with @TomGeorge

By all means use YouTube as a bit of a guide, but you need to understand how each part works and get them working.

It's relatively easy to do what you want to do. The motor spinning bit is trivial. You just need to concentrate on the timing. Just get an LED to go on and off at certain times.

Then substitute the LED with the motor, taking into account the likely higher power required and precautions for driving inductive loads.

Sorry for not replying

To answer your questions:
The motor does work by itself
My friend has tested a normal clock code and it worked


This is the circuit and connections i am using, hopefully it is readable

Yes, there is power however for some reason it wouldn't run exactly as the video. When me and mt friends had tested it out either it wouldn't display the time correctly, it wouldn't spin the motor during the alarm time, or it would just display an error. Sorry for not being very clear.


this is the circuit diagram of all my connections, hopefully it is readable

Hi, @regalornit

I think its time we saw some images of your project, so we can see your component layout.

Tom.... :smiley: :+1: :coffee: :australia:

Here is the photo of all my components connected

however i have found a new problem which is only the L298N Motor Driver will turn on and yet the other won't

And my current solution to the problem is adding another connection

I have changed the battery source instead of 2 AA Batteries, i am using 4 AAA Batteries which seems to be enough power the LCD


But now i have found a new problem in which both me and my friend's laptops can no longer detect the Arduino and the port