Skip to main content

Automatic College Bell with Raspberry Pi and PHP

Introduction
#

In today’s digital age, automation has become a cornerstone of efficient institutional management. One area where automation can significantly improve operations is in educational institutions’ bell systems. Traditional manual bell systems are prone to human error, timing inconsistencies, and require constant attention. This project presents a complete solution for an Automatic College Bell Management System built using Raspberry Pi, PHP, and MySQL.

What is This Project?
#

The Automatic College Bell System is an open-source solution designed to replace manual bell operations in educational institutions. It provides:

  • Automated bell scheduling for different days of the week
  • Multiple bell types: Long bells, short bells, and prayer announcements
  • Web-based management interface for easy configuration
  • Reliable timing using system cron jobs
  • Scalable architecture that can be deployed on Raspberry Pi or any Linux machine

System Architecture
#

The system follows a simple yet effective flow:

Raspberry Pi/Linux → Application → Mixer → Amplifier → PA System

Core Components
#

  1. Hardware Layer: Raspberry Pi or Linux machine with audio output
  2. Application Layer: PHP-based web application with MySQL database
  3. Audio Layer: Audio files (WAV format) for different bell sounds
  4. Control Layer: Cron jobs and system services for automation

Technical Implementation
#

Database Schema
#

The system uses two main database tables:

BELL_TIME Table
#

  • BT_BELL_ID: Unique identifier for each bell configuration
  • BT_DAY: Day of the week (Mon, Tue, Wed, etc.)
  • BT_TIME: Comma-separated time slots with bell types
  • BT_PRAYER_SONG: Path to prayer audio file

USERS Table
#

  • U_USER_ID: User identifier
  • U_NAME: User’s full name
  • U_USER_NAME: Login username
  • U_PASSWORD: Encrypted password

Bell Time Format
#

The system uses a character-based encoding for different bell types:

  • “L”: Long bell (typically for class start/end)
  • “S”: Short bell (for period transitions)
  • “P”: Prayer announcement

Example time format: 08:50L,08:54S,08:55P,09:00S

Core PHP Scripts
#

bell.php
#

The main automation script that:

  • Checks current time and day
  • Queries the database for scheduled bells
  • Copies appropriate audio files to the play directory
  • Runs every minute via cron job

run.sh
#

A bash script that:

  • Monitors the play directory for new audio files
  • Plays audio using aplay command
  • Cleans up played files
  • Runs continuously as a system service

Installation Guide
#

Prerequisites
#

Before installing the system, ensure you have the following installed on your Raspberry Pi or Linux machine:

# Update system packages
sudo apt update && sudo apt upgrade -y

# Install Apache web server
sudo apt install apache2 -y

# Install PHP and required extensions
sudo apt install php php-cli php-mysql php-mbstring -y

# Install MySQL server
sudo apt install mysql-server -y

# Install phpMyAdmin for database management
sudo apt install phpmyadmin -y

Installation Steps
#

  1. Clone or Download the Project

    cd /var/www/html
    sudo git clone https://github.com/iam-vivekus/automatic_college_bell.git bell
    sudo chown -R www-data:www-data bell
    sudo chmod -R 755 bell
    
  2. Set Up Database

    Note: This setup creates the database manually instead of importing an SQL file, giving you full control over the database structure and initial data.

    # Access MySQL
    sudo mysql -u root -p
    
    # Create database
    CREATE DATABASE BELL;
    USE BELL;
    
    # Create BELL_TIME table
    CREATE TABLE BELL_TIME (
      BT_BELL_ID int(20) NOT NULL,
      BT_DAY varchar(50) NOT NULL,
      BT_TIME varchar(800) NOT NULL,
      BT_PRAYER_SONG varchar(500) NOT NULL,
      PRIMARY KEY (BT_DAY)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    
    # Create USERS table
    CREATE TABLE USERS (
      U_USER_ID int(10) NOT NULL,
      U_NAME varchar(50) NOT NULL,
      U_USER_NAME varchar(50) NOT NULL,
      U_PASSWORD varchar(50) NOT NULL,
      PRIMARY KEY (U_USER_ID)
    ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
    
    # Create admin user
    INSERT INTO USERS (U_USER_ID, U_NAME, U_USER_NAME, U_PASSWORD) 
    VALUES (1, 'BELL', 'admin', '1234');
    
    # Insert sample bell schedules (optional)
    INSERT INTO BELL_TIME VALUES 
    (1,'Mon','08:50L,08:54S,08:55P,09:00S,09:50S,10:40S,10:55S,11:45S,12:35S,13:25S,14:15S,15:10S,15:20S,16:00L','/var/www/html/bell/song1.wav'),
    (2,'Tue','08:50L,08:54S,08:55P,09:00S,09:50S,10:40S,10:55S,11:45S,12:35S,13:25S,14:15S,15:10S,15:20S,16:00L','/var/www/html/bell/song2.wav'),
    (3,'Wed','08:50L,08:54S,08:55P,09:00S,09:50S,10:40S,10:55S,11:45S,12:35S,13:25S,14:15S,15:10S,15:20S,16:10N','/var/www/html/bell/song3.wav'),
    (4,'Thu','08:50L,08:54S,08:55P,09:00S,09:50S,10:40S,10:55S,11:45S,12:35S,13:25S,14:15S,15:10S,15:20S,16:10N','/var/www/html/bell/song4.wav'),
    (5,'Fri','08:50L,08:54S,08:55P,09:00S,09:55S,10:50S,11:05S,12:00S,12:55S,14:00S,15:00S,15:20S,16:10N','/var/www/html/bell/song1.wav'),
    (6,'Sat','08:50L,08:54S,08:55P,09:00S,09:50S,10:40S,10:55S,11:45S,12:35S,13:25S,14:15S,15:10S,15:20S,16:10N','/var/www/html/bell/song2.wav'),
    (7,'Sun','','/var/www/html/bell/song3.wav');
    
  3. Configure Database Connection Edit config.php with your database credentials:

    <?php
    $conn = mysqli_connect("localhost", "your_username", "your_password", "BELL");
    ?>
    
  4. Set Up System Service Create a systemd service for the audio player:

    sudo nano /etc/systemd/system/bell-player.service
    

    Add the following content:

    [Unit]
    Description=Bell System Audio Player
    After=network.target
    
    [Service]
    Type=simple
    User=www-data
    WorkingDirectory=/var/www/html/bell
    ExecStart=/var/www/html/bell/run.sh
    Restart=always
    
    [Install]
    WantedBy=multi-user.target
    

    Enable and start the service:

    sudo systemctl enable bell-player
    sudo systemctl start bell-player
    
  5. Configure Cron Job Set up automatic bell checking:

    sudo crontab -e
    

    Add this line:

    * * * * * php /var/www/html/bell/bell.php
    
  6. Audio Setup Ensure your audio files are in the correct location:

    • /var/www/html/bell/bell/short_bell.wav
    • /var/www/html/bell/bell/long_bell.wav
    • /var/www/html/bell/song1.wav (prayer song1)
    • /var/www/html/bell/song2.wav (prayer song2)
    • /var/www/html/bell/song3.wav (prayer song3)
    • /var/www/html/bell/song4.wav (prayer song4)

Usage Guide
#

Accessing the Web Interface
#

  1. Open your web browser and navigate to: http://your-raspberry-pi-ip/bell
  2. Login with the default credentials:
    • Username: admin
    • Password: 1234

Main Features
#

Home Dashboard
#

The main interface provides access to:

  • Long Bell: Manual trigger for long bell sound
  • Short Bell: Manual trigger for short bell sound
  • Prayer: Manual trigger for prayer announcement
  • Edit Bell: Configure bell schedules

Bell Schedule Management
#

The “Edit Bell” section allows you to:

  • Set different schedules for each day of the week
  • Configure multiple time slots per day
  • Choose bell types for each time slot:
    • L: Long bell
    • S: Short bell
    • P: Prayer
    • N: No bell

Example Schedule Configuration
#

For a typical school day (Monday):

08:50L,08:54S,08:55P,09:00S,09:50S,10:40S,10:55S,11:45S,12:35S,13:25S,14:15S,15:10S,15:20S,16:00L

This schedule includes:

  • 8:50 AM: Long bell (class start)
  • 8:54 AM: Short bell (warning)
  • 8:55 AM: Prayer
  • 9:00 AM: Short bell (first period)
  • … and so on

Customization Options
#

Audio Files
#

You can replace the default audio files with your institution’s preferred sounds:

  • Replace short_bell.wav and long_bell.wav in the bell/ directory
  • Update prayer songs (song1.wav, song2.wav, etc.)
  • Ensure all audio files are in WAV format for compatibility

Schedule Flexibility
#

The system supports:

  • Different schedules for each day of the week
  • Multiple time slots per day
  • Easy modification through the web interface
  • No programming knowledge required for schedule changes

Network Access
#

For remote management:

  • Configure port forwarding on your router
  • Set up SSL certificates for secure access
  • Use strong passwords for admin accounts

Troubleshooting
#

Common Issues
#

  1. Bells Not Ringing

    • Check if the cron job is running: sudo crontab -l
    • Verify the bell-player service: sudo systemctl status bell-player
    • Check audio permissions and hardware connections
  2. Web Interface Not Loading

    • Verify Apache is running: sudo systemctl status apache2
    • Check file permissions: sudo chown -R www-data:www-data /var/www/html/bell
    • Ensure PHP is properly installed
  3. Database Connection Issues

    • Verify MySQL is running: sudo systemctl status mysql
    • Check database credentials in config.php
    • Ensure the BELL database exists

Logs and Monitoring
#

# Check system service logs
sudo journalctl -u bell-player -f

# Check Apache logs
sudo tail -f /var/log/apache2/error.log

# Check cron job execution
sudo grep CRON /var/log/syslog

Security Considerations
#

  1. Change Default Passwords: Immediately change the default admin password
  2. Network Security: Use strong passwords and consider VPN access
  3. Regular Updates: Keep the system and dependencies updated
  4. Backup: Regularly backup the database and configuration files

Future Enhancements
#

The system can be extended with:

  • Mobile App: Remote management via smartphone
  • Multiple Zones: Support for different buildings/areas
  • Integration: Connect with school management systems
  • Analytics: Bell usage statistics and reports
  • Weather Integration: Adjust schedules based on weather conditions

Conclusion
#

This Automatic College Bell System provides a robust, scalable solution for educational institutions looking to modernize their bell operations. With its web-based interface, flexible scheduling, and reliable automation, it eliminates the need for manual bell management while providing greater control and customization options.

The open-source nature of the project allows for community contributions and continuous improvement. Whether you’re a small school or a large university, this system can be adapted to meet your specific requirements.

For more information, visit the project repository: https://github.com/iam-vivekus/automatic_college_bell.git


This project demonstrates the power of combining simple hardware with smart software to solve real-world problems in educational institutions.

Vivek US
Author
Vivek US
A Tech Enthusiast