Battery ChargerBattery Circuit DiagramsClock & Timer Circuit DiagramsLCD-LED DisplayLights and Display Board CircuitsPower Supplies

Ambience Lighting Controller Schematic Circuit Diagram

Customizable Color Control

Nowadays, color LED strips are abundantly available at a low cost, coming in various types and sizes. This controller circuit detailed here offers the flexibility to set your desired colors and even program and execute complete lighting sequences. What sets it apart is its battery-powered operation, enabling its use in areas where AC power sources are not easily accessible.

Origins and Expansion

Initially conceived to drive color LED strips from a well-known Swedish home furnishing store, these LED strips typically include a basic controller with a limited color selection. This limitation served as a catalyst for the author to create a DIY controller with enhanced capabilities. The resulting ‘ambience lighting controller’ is compatible with all RGB LEDs and LED strips that can function on a 12 V supply voltage, requiring a series resistor for current regulation. In the author’s specific application, powering the LED strips directly from the AC line was not feasible. Therefore, the controller was specifically designed to operate on a 12 V gel-cell battery. The fundamental features of the circuit are outlined in the inset.

Schematic diagram:

As you can see from the schematic in Figure 1, the circuit is fairly simple. The author chose a PIC16F887 for the microcontroller on account of its integrated EEPROM (for convenient storage of lighting programs), extensive I/O capacity and integrated ADC. Although the PIC16F877A is more popular, a sibling device was selected for this application because its ADC configuration allows the ADC inputs on RA0 and RA1 to be used without requiring any reference voltage input on RA2 or RA3.

Here RC3 is connected to switch S1, which allows the battery charge state to be shown on the LCD module in two different ways. Connector K6 is the ICSP port for in-circuit programming of the microcontroller. The microcontroller is clocked at 20 MHz by crystal X1. This relatively high clock frequency is necessary because the clock signal is divided by 4 inside the microcontroller. The resulting 5 MHz signal is essential for the PWM control function implemented in software.

Display Module Configuration

The display module employed here is a standard version featuring two lines, each accommodating 16 characters. This module is readily available in the Elektor Shop and is connected to port RB. In the event that a different type of LCD is utilized, adjustments to the polarity of the supply voltage for the backlight can be made if required. These alterations can be achieved through jumpers placed at positions J1 and J2. Transistor T2 plays a crucial role by automatically turning off the backlight if there is no user input within a span of 10 seconds. Additionally, the contrast of the display can be fine-tuned using the trimpot P1. Unlike the majority of circuits utilizing an LCD module, in this setup, the LCD operates in 8-bit mode rather than the more common 4-bit mode. This choice was made based on the availability of sufficient I/O pins on the microcontroller.

Ambience Lighting Controller Schematic Circuit Diagram 1

Ambience Lighting Controller Schematic Circuit Diagram .2 jpg

LED Control and User Interface

The intensity of the connected LEDs is regulated through pulse width modulation (PWM). Although the microcontroller has adequate PWM outputs, the author opted for a software-based PWM setup to simplify the prototype circuit board’s layout. Power MOSFETs T3, T4, and T5, operating from TTL-level signals, drive the RGB LED strips (up to 4) connected to connectors K2 to K5. Each MOSFET can supply multiple amps without additional cooling. Buzzer Bz1, equipped with a built-in oscillator, produces an audible tone when supplied with voltage.

The control elements feature three rotary encoders with built-in pushbuttons. Microcontroller pins RA0 and RA1 serve as A/D converter inputs. RA0 measures the battery voltage, while RA1 detects if a battery charger with a voltage above approximately 14 V is connected. Voltage dividers R5/R4 and R6/R7 adjust the sensed voltages within the microcontroller’s measuring range. Capacitors C8 and C9 remove any ripple voltage on the sense lines. Additionally, a serial to USB converter module allows connection to a PC, enabling remote control using specific commands in a terminal emulator program.

Power Supply and Charging System

The supply voltage is regulated by a conventional 7805 voltage regulator alongside capacitors (IC1, C1–C4) and a diode (D2) for polarity protection. Fuse F1’s value in the power supply stage depends on the load; a 2A slow-blow fuse should suffice for 6.5-ft (2-meter) LED strips, although measuring the load current in the actual application is advisable. Connector K7 serves as the power input for a gel-cell battery, and an AC adapter with an output voltage of around 15 V at 2 A or more can be connected to K1. Transistor T1 controls relay RE1, which shorts out resistor R1 during battery charging. The circuit consumes approximately 25 mA during operation, or around 50 mA with the backlight activated.

PCB Assembly and Components

The PCB layout, designed at Elektor Labs for this lighting controller, uses only leaded components, ensuring straightforward assembly even for those with limited soldering experience. All components are mounted on the side with the component overlay. Components like the voltage regulator and MOSFETs should have their leads bent at right angles before soldering to lie flat on the board. These components don’t require heat sinks for standard use. The microcontroller, available preprogrammed if desired, should be placed in a socket. For users intending to establish a serial link with a PC, the Elektor USB FT232R breakout board can be directly fitted onto the PCB or connected using a pair of 9-pin SIL socket strips.

Software

The program for this circuit was written in ANSI C using MPLAB and compiled using a full-function Hi-Tech C compiler running in evaluation mode (45-day trial license). The “lite” version of this compiler is not suitable in this case because it does not provide sufficient optimization, with the result that the executable code is too large for the 8 KB of program memory in the microcontroller. The source code and hex code, as well as the PCB layout, are available on the Elektor website [2] for free download.

Microcontroller Programming and Optimization

In the Elektor Shop, a pre-programmed microcontroller is available for purchase, offering convenience for users. The software’s pivotal component is the interrupt service routine (ISR), meticulously optimized using MPLAB’s stopwatch function. This routine is subdivided into multiple subroutines designed to execute at intervals of 100 µs, 5 ms, 100 ms, or 1 s. The ISR triggers every 100 µs, ensuring proper execution of subroutines within the specified time frames. Initially, a counter was employed to track the 1-ms and 100-ms intervals, but to conserve memory, a more efficient approach was adopted. A second counter was introduced to determine the 1-ms intervals, eliminating the need for time-consuming modulus calculations during each 100 µs interrupt call.

Automatic Light Level Control

The automatic light level control operates based on a straightforward principle. With a nominal PWM clock frequency of 100 Hz at 11 V, adjusting the duty cycle alone would make the LEDs brighter if the battery voltage surpasses 11 V. To simplify this process, a different strategy was employed. Instead of recalculating the duty cycle for each color when the battery voltage changes, the ‘on’ time remains constant. Instead, the PWM clock frequency is reduced as the voltage rises. This approach significantly streamlines the calculation process, requiring only one calculation to yield consistent results.

Ambience Lighting ControllerSchematic Circuit Diagram List 1

Ambience Lighting Controller Schematic Circuit Diagram List 2

Optimizing Color Transitions

The minute disparity between PWM clock frequencies, such as 100 Hz and 90 Hz, often goes unnoticed to the human eye. However, another programming challenge surfaced in the form of color transition code. In theory, the calculation appears straightforward: determine the PWM value for each color, compute the difference between this value and the next, and distribute the outcome over the transition period. Adjust the PWM values for each color incrementally during this interval, typically defined in increments of 100 ms. The challenge arises due to the fractional results generated by this division, necessitating the use of floating-point variables for accurate calculations and storage. However, PIC16F microcontrollers, being 8-bit devices, encountered difficulties with these relatively large floating-point variables. This struggle resulted in timing discrepancies and errors within the compiled code.

The solution to this dilemma was surprisingly straightforward. Utilizing integers for multiplication and division operations consumes less time and memory compared to handling floating-point numbers. Consequently, the disparity between PWM values for each color is first multiplied by 100 and then divided by the transition time. This approach ensures integer outcomes “rounded off” to two decimal points, as depicted in the provided code segment (Listing 1). During each step of the transition period (occurring every 100 ms), the current PWM value is calculated and subsequently divided by 100, yielding an integer output (Listing 2). By adopting this method, an 8-bit microcontroller adeptly manages color transitions without encountering significant performance issues.

Operation:

After the controller is switched on, it first shows a welcome message on the display consisting of its name and version number. The menu becomes available 1 second later. Operation of the controller is self-explanatory, but an extensive User Guide is also available as a free download [2]. You can scroll through the menu using rotary encoder ENC1. First you see the three options Run Program (where x is 1, 2 or 3) for running one of the defined programs. Select one of the three programs and press Enter (the pushbutton of ENC2). To return to the menu, press Back (the pushbutton of ENC3). The menu option Charge Battery selects monitored battery charging mode.

Battery Charging and Monitoring:

To initiate the battery charging process, start by connecting a 15-V battery charger and select this option from the menu. When this mode is activated, the relay is energized, short-circuiting resistor R1 to facilitate increased current flow into the battery. To prevent potential damage from the higher input voltage, the color LED strips are turned off temporarily. Once the battery voltage reaches 13.8 V, the relay is disengaged, reducing the charging current to a trickle charge level. Simultaneously, the color LEDs are reactivated. The Battery Charge option provides a visual representation of the battery charge level in 10% increments.

This value is derived by measuring the battery voltage and expressing it as a percentage, with 0% corresponding to 0% charge and 13.8 V indicating a fully charged battery. LED D5 serves as an indicator for the battery’s charge state. When the battery is fully charged at 13.2 V, the LED remains steadily lit. As the battery depletes, the LED blinks with a duty cycle proportional to the remaining charge. If the battery charge is critically low, the LED briefly illuminates. When the battery level necessitates deactivating the color LEDs, the buzzer begins beeping.

Child Lock Function and Color Configuration:

Switch S2 offers a Child Lock function. When closed, this setting restricts access to the Edit Program and Edit menu options. To adjust a specific color setting, select Edit, press Enter, and utilize the rotary encoders to establish the red, green, and blue levels within the range of 0 to 100%, in 1% increments. Pressing Enter saves the updated settings, while selecting Back returns to the menu without saving changes. To configure a program, initiate the process by selecting Edit Program and then pressing Enter. Use rotary encoder ENC1 to choose the color, encoder ENC2 to set the Hold time, and encoder ENC3 to establish the transition time.

Internet Links

[1] www.elektor.com/110553

[2] www.elektor.com/110406

Tags

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button
Close
Close