School bell code timing

Pls I am trying to use different alarm timing for each day, I am a newbie in Arduino, I tried using interrupt for this but I cant seen to process the code, any suggestions, urgently needed pls

pls mention the components.

and also the circuit

That is not what interrupts are for!

As a beginner, it is incredibly unlikely that interrupts will be useful to you.

A common "newbie" misunderstanding is that an interrupt is a mechanism for altering the flow of a program - to execute an alternate function. Nothing could be further from the truth! :astonished:

An interrupt is a mechanism for performing an action which can be executed in "no time at all" with an urgency that it must be performed immediately or else data - information - will be lost or some harm will occur. It then returns to the main task without disturbing that task in any way though the main task may well check at the appropriate point for a "flag" set by the interrupt.

Now these criteria are in a microprocessor time scale - microseconds. This must not be confused with a human time scale of tens or hundreds of milliseconds or indeed, a couple of seconds. A switch operation is in this latter category and even a mechanical operation perhaps several milliseconds; the period of a 6000 RPM shaft rotation is ten milliseconds. Sending messages to a video terminal is clearly in no way urgent,

Unless it is a very complex procedure, you would expect the loop() to cycle many times per millisecond. If it does not, there is most likely an error in code planning; while the delay() function is provided for testing purposes, its action goes strictly against effective programming methods. The loop() will be successively testing a number of contingencies as to whether each requires action, only one of which may be whether a particular timing criteria has expired. Unless an action must be executed in the order of mere microseconds, it will be handled in the loop().

So what sort of actions do require such immediate attention? Well, generally those which result from the computer hardware itself, such as high speed transfer of data in UARTs(, USARTs) or disk controllers.

An alternate use of interrupts, for context switching in RTOSs, is rarely relevant to this category of microprocessors as it is more efficient to write cooperative code as described above.

2 Likes

Hello baofix
Welcome to the forum. After the great project kickoff from the forum member Paul_B, he has given a very a brillant summaration, I will take the fokus to the hardware.
As above mentioned your system should be execute daily action with a related sound. This function requieres a calender function and MP3-Player . On the market a lot of RTC-shield and MP3 player are available. Do some market analysis using your list of requierments and start with the design of a block diagram that shows all needed componets, including a power supply.
If do you have a ready designed block diagram, that fits to all requieremts, in the next step you can start with the design of the sketch.

Lcd i2c, ds3231, keypad, Arduino nano, relay module

Specifically, I intend to design an automatic school bell which triggers a relay at set time for each day, I was able to get day timing sketch but each day time are different, I thought interrupt will do the job but ur analysis shows its a bad idea, any other suggestions will be warmly welcmed