arduino:art-clockbell
Differences
This shows you the differences between two versions of the page.
Previous revision | |||
— | arduino:art-clockbell [2024/11/22 12:02] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Arduino Art - Town Hall Bell clock - Real Time clock with LCD display and Bell functionality ====== | ||
+ | {{htmlmetatags> | ||
+ | metatag-description=(Arduino Art - Town Hall Bell clock - Real Time clock with LCD display and Bell functionality) | ||
+ | }} | ||
+ | |||
+ | ===== Introduction ===== | ||
+ | The scope of this project was to mimic the functionality of a Church or Town Hall Bell, which sounds **on** the hour with a number of " | ||
+ | |||
+ | The project was originally intended for a "live sculpture", | ||
+ | |||
+ | On the other hand, the programming methods for creating pulses with duration of several seconds, far beyond the period of a normal Arduino loop, may be found useful by the community. That was the main reason for deciding to publish this article. | ||
+ | |||
+ | Pictures of the prototype are shown below. | ||
+ | |||
+ | {{arduino: | ||
+ | |||
+ | {{arduino: | ||
+ | {{arduino: | ||
+ | {{arduino: | ||
+ | {{arduino: | ||
+ | |||
+ | |||
+ | |||
+ | ===== Components ===== | ||
+ | * **Arduino nano**. My favorite arduino for small-scale controller projects | ||
+ | * **Power supply**. A low cost 5V socket power supply from hobby electronics or a mobile phone charger, capable of feeding 2A. In case of a USB phone charger, you may need to cut the cable and replace the micro-USB socket with a male 5.5x2.1 mm barrel connector | ||
+ | * **16x2 LCD display QC1602A**, based on the HD44780 chip | ||
+ | * **PCF8574A**. An I2C extender chip | ||
+ | * **Real Time Clock (RTC) module** with integrated battery, based on DS3231 or the older, lower precision DS1307 | ||
+ | * Various electronic components mentioned in the Schematic | ||
+ | |||
+ | ===== Arduino Libraries and other software ===== | ||
+ | **LiquidCrystal I2C version 1.2** | ||
+ | Author Frank de Brabander | ||
+ | Maintainer Marco Schwartz Website https:// | ||
+ | which I downloaded from https:// | ||
+ | |||
+ | |||
+ | **RTClib by NeiroN** by JeeLabs (http:// | ||
+ | |||
+ | |||
+ | For presenting custom characters to the LCD, I used the designs from https:// | ||
+ | |||
+ | You shall also need the RTC library **MD_DS3231** by majicDesigns Version 1.2.0 for another sketch that I use to set the initial time of the real-time clock. | ||
+ | |||
+ | ===== Schematic ===== | ||
+ | |||
+ | {{arduino: | ||
+ | |||
+ | //Handmade schematic?// | ||
+ | |||
+ | The Arduino Nano is connected via the I2C bus to the RTC and the PCF8574A. The PCF8574A chip demultiplexes the I2C signals and controls the 7 pins required by the LCD (D4-D7, RS, RW and E). The chip is installed below the LCD display with the purpose of keeping short the wiring between its pins and the display socket pins. | ||
+ | |||
+ | The potentiometer controls the LCD contrast. Set it to a value that provides a balance between the maximum brightness of the characters, without having the pixel background show that much. | ||
+ | |||
+ | The NPN transistor BC337 is driven by Arduino Nano pin D7 and controls a relay. This relay will drive the actuator which rings the bell. | ||
+ | |||
+ | Three micro-switches are connected to Arduino pins D4, D5 and D6. They are used for correcting the time, after it has shifted significantly from the correct time. These switches are marked H, M and S and correct hours, minutes and seconds respectively. | ||
+ | |||
+ | One header pin wired to GND and D3 serves for the wiring of an external " | ||
+ | |||
+ | A peculiar circuit is built around a PNP transistor BC557C. One would immediately notice that the transistor is redundant because it always allows the flow of current without exercising any control. This is true. The reason for the existence of this circuit block is because for this project I used an existing prototype board that I have built for another project, a few months before. In that project, I was using a different library for driving the display which was also called LiquidCrystal_I2C, | ||
+ | Pins RS, RW and E of the LCD were wired to pins P6, P5 and P4 of PCF8574A and the data pins D4, D5, D6, D7 of the LCD were wired to pins P0, P1, P2 and P3 of PCF8574A. Additionally, | ||
+ | |||
+ | Unfortunately, | ||
+ | |||
+ | Going back to hardware issues, please note that backlighting of the LCD is performed by internal diodes, whose operating current should be less than 25mA according to the manufacturer specification. My testing showed that 5mA were enough for proper lighting. Pin A is the Anode and pin K the cathode. Note that these pins must be driven by current - not voltage. The Vf between A and K is approx. 3V, so to keep the current at a reasonable value of 5mA, we need a series resistor of (5-3)/0,005 =~ 390 Ohms. The 1N4148 in the schematic is also redundant. | ||
+ | |||
+ | To cut a long story short, if I built the circuit again, I would use a single 390 or 330 Ohm resistor from +5V to pin A of the LCD. Even better, I would buy an LCD display with a piggyback PCF8574 module, such as [[https:// | ||
+ | |||
+ | The relay is used to drive the bell actuator. When I started the project, the sponsor have not yet decided on the bell and the associated type of actuator, so I installed an 8A/250V contact relay activated by a 5V coil. Should I have the specs of the actuator beforehand, I would design using transistors or MOSFETs. Yet the relay provides a more generic solution. | ||
+ | |||
+ | One barrel 5.5x2.1 mm connector for the PCB and alternatively a block connector are used for providing power to the board. Note that 5.5 mm refers to the outer diameter (OD) of the plug and 2.1mm to the inside diameter (ID). There are also in the market 5.5x2.5 mm. Match the socket with the plug so that they are of same specifications. | ||
+ | |||
+ | A 1N5819 schottky diode is used to allow us to program the Arduino nano via the USB cable while the circuit is powered at the same time by the power supply. I cover this issue in detail in [[arduino: | ||
+ | |||
+ | The Arduino Nano, the RTC module and the LCD display module are not soldered directly on the board. I am using socket pins, like the ones shown at the top of the picture (those are not used in this circuit). I then insert the module header pins into the main board socket pins. Sometimes, in case the module arrives with the pins soldered on the " | ||
+ | ===== Software ==== | ||
+ | The most notable thing in the code is the measure of time. Several issues that caused drifting were discovered using an oscilloscope and the code was developed in order to ensure precise timing. | ||
+ | |||
+ | When the time is exactly on the hour, the system produces a number of " | ||
+ | |||
+ | The value of TIME_BELL_ON defines the time the relay will be at the ON state. Because we want to send a short pulse to the actuator, such as a mini solenoid electromagnet, | ||
+ | |||
+ | The value of TIME_BELL_OFF defines the time the relay will be at the ON state. We want the bell to reverberate for a while, so the value of 35 produces 3500 milliseconds which is 3.5 seconds. | ||
+ | |||
+ | < | ||
+ | Example for ringing | ||
+ | ______________ | ||
+ | I I I I | ||
+ | I I I I | ||
+ | ______I | ||
+ | | ||
+ | < | ||
+ | < | ||
+ | </ | ||
+ | |||
+ | |||
+ | The Real Time Clock module synchronizes time every minute. The synchronization takes place 10 seconds before completing a minute. I selected 10 seconds before because usually programmed events take place exactly on the hour and I wished to avoid several things happenning at the same time. | ||
+ | |||
+ | One safety feature is that, if the clock has sounded the hour and for some reason the synchronization sets the time back, the same hour will not sound again. | ||
+ | |||
+ | Finally, the Night Mode keeps the device silent after hours. This means that if Night Mode is active, the bell will sound only at normal working hours. Night Mode is the default mode, provided that the pin headers are not wired together. The silent hours are defined in array silent_hours[]. | ||
+ | |||
+ | A copy of the code is shown at the end of this document. I will try to post same on Github when I find the time | ||
+ | |||
+ | |||
+ | |||
+ | ===== Operation ===== | ||
+ | Install a CR2032 coin battery into the RTC socket. | ||
+ | |||
+ | When powering the device for the first time, the RTC will have an undefined date and time. Load any example sketch that will allow you to set it manually. I used [[arduino: | ||
+ | |||
+ | Of course, it will not be possible to set the exact time with this method. You will definitely be off, at least by a few seconds. | ||
+ | |||
+ | After setting the RTC, load the sketch of the project. The date will appear at the first line and the time at the second line. You can now fix the time precisely using the switches. | ||
+ | |||
+ | Here is how the switches operate: | ||
+ | |||
+ | * The Hour and Minute switches increase the value of hour and minute respectively by one. | ||
+ | * When the Seconds switch is pressed, the seconds value is reset to zero. | ||
+ | * When the two pins of the Night Mode header are not wired together, Night Mode will be active. A Lock symbol appears in the far right column of the first line of the display. The bell will not sound at silent hours. | ||
+ | |||
+ | |||
+ | When the two pins of Night Mode are wired together, Night Mode is deactivated. A bell symbol appears in the far right column of the first line of the display to signify that the bell will sound each and every hour during day and night. | ||
+ | |||
+ | The last column of the second line of the LCD presents a music note symbol if the current hour is non-silent. No symbol appears for silent hours. | ||
+ | |||
+ | ===== Ideas for future enhancements ===== | ||
+ | |||
+ | - Implement Daylight Saving | ||
+ | - Modify switch operation so that both date and time can be adjusted. Better debouncing is required. Three switches will suffice, one for item (year-month-day-hour-min-sec) selection and two for Up and Down. The selected item should blink. | ||
+ | |||
+ | ===== Conclusion ===== | ||
+ | Although at first the concept appeared easy - a simple clock and something to do on the hour - it proved to be a detailed work, needing to examine several Arduino features regarding the handling of timer functions and timer interrupts, as well as the system behaviour during the loops. Minor time drifts would add up and cause significant variations over time. Several solutions were examined originally, even the use of two arduinos, one to handle time and the second to handle ringing. Another solution was to implement custom hardware for ringing. | ||
+ | |||
+ | Yet, since the whole project involved the notion of " | ||
+ | |||
+ | Finally, after lots of testing and debugging, the prototype was ready to be delivered to the project sponsor and subsequently to the open source community. | ||
+ | |||
+ | Have fun! | ||
+ | |||
+ | If you have any feedback, please contact me via [[https:// | ||
+ | |||
+ | ===== Source Code ===== | ||
+ | |||
+ | The source code of the project [[arduino: | ||
+ | |||
+ | ~~DISQUS~~ |