We all know when we were in school, a person was waiting near school bell to make bell ring. He had to come and rang bell in every period. But what about if it can be automated. Yes it is very simple and we can do that with Arduino. So in this tutorial we are going to make automatic school bell system using Arduino. So lets get started.

Components Required:

For making automatic school bell system using Arduino project you will need,

  1. Arduino,
  2. Real time clock (DS1302),
  3. LCD display 16X2,
  4. I2C,
  5. Cycle or Bike Bell,
  6. Toy DC Motor,
  7. L298N Motor Driver,
  8. 4 AAA 1.5V Battery Case,
  9. AAA 1.5V Battery,
  10. Jumper Wires,
  11. Breadboard.
DC Motor:

If you have geared motor, remove gear part as we don’t need this. We are going to attach cycle bell mechanism with Motor.

Removing motor from gear

Removing motor from gear

Toy DC motor

Make a Bell System:

For this tutorial, I am using cycle bell and opened it. Remove its mechanism, so that we can fit it with DC motor.

Cycle or Bike Bell

Cycle or Bike Bell

Removing Bell Mechanism

Removing Bell Mechanism

Attaching cycle bell mechanism on motor

Attaching cycle bell mechanism on motor

L298N Motor Driver:

For this tutorial I am running my DC motor at full speed or you can say I am not controlling motor speed. So I am keeping my Enable A jumper cap in place.

L298N Motor Driver- Enable A Jumper should be connected

L298N Motor Driver- Enable A Jumper should be connected

If you want to control speed you need to remove enable jumper cap. Connect first end of jumper wire on enable A and second end to PWM pin in Arduino board. You have to also change some part of code for controlling speed. Which I am not doing in this tutorial.

Power supply for DC Motor:

I am using 6V (1.5V four Battery) for DC motor, but you can use 6V to 12V.

4 AAA 1.5V Battery Case

4 AAA 1.5V Battery Case

Automatic school bell system using Arduino Circuit Diagram:

Automatic School Bell System Circuit Diagram

connect all the components together as shown in diagram.

Necessary Libraries:

Download library for I2C and Real Time Clock library from Github  OR you can download it from here because github library may change by the time or it may not work.

Download l2C library Arduino-LiquidCrystal-I2C-library-master.zip

Download Real time clock library DS1302.zip

Automatic school bell system using Arduino Code:
#include <Wire.h>
#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);
}
Code Explanation:

First you have to install LCD I2C and DS1302 Library. If you don’t know how to install library you can read my previous tutorial for how to install library.

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <DS1302.h>

You will also need to find LCD address. You can watch my previous tutorial for connecting LCD to I2C.

LiquidCrystal_I2C lcd(0x3F, 16, 2);

Step1: You need to first set Day, Time and Date. Then upload the code.

Step 2: comment out following lines and again upload the code.

Note: If you don’t do this, every time you press reset button on Arduino or restart arduino. Time will start from where you have set. Not from current time.

rtc.setDOW(SATURDAY); // Set Day-of-Week to FRIDAY
rtc.setTime(06, 59, 30); // Set the time to 12:00:00 (24hr format)
rtc.setDate(22, 03, 2020); // Set the date to August 6th, 2010

It will ring 10 times and I have divided code into three section. First, 8 times for period. Second, 1 time for Recess Break. Third, 1 time for school time over.

First, it will ring for 8 times and count number of period. If you want you can add more number of period. And you can also change the time. It will ring for 5 second. If you want you can increase or decrease that time. When it matches with condition, motor start rotating and we hear bell sound. At the same time it counts number of period and print that number to LCD screen.

Note: Write timing in single digit for example you want to 7:00:05 AM, You should write (Hour== 7 && Min== 0 && Sec<= 5), Hour is “7” not “07”, minute is “0” not “00” but it doesn’t mean you can’t write double digit 10,11, 12. if you want timing 10:30:05AM then (Hour== 10 && Min== 30 && Sec<= 5). If you write single digit “7” as in double digit “07”. You will surely get an error while uploading.

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");

This part is for restricting the counter to count only once. When time get matches with condition it will continuously count for 5 second and we don’t want that. So this part will make sure it will count only once per time.

if (activate == 0){
period = period +1;
activate =1;
}

Second bell section will be for recess break. You can change the time if you want and it will also print on LCD “Break”.

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();
}

Third will be for school time over and Make period equal to zero. so next morning counter again start from zero.

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();
}

If time doesn’t match with any of condition. Motor will be remain off.

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

I hope you will like my tutorial, please subscribe me on YouTube.

Till then Keep Learning Keep Making.