A small poststamp computer of 2 Euro's can be used to activate the ships illumination (like anchor light) between sunset and sunrise automatically, to monitor the lamps for correct operation, and to adjust the backlight illumination of the switch panel to the ambient light. Description of a small nice Do It Yourself project!
A small project with small parts
For our new switch panel I selected nice waterproof switches with a built in LED. On the cover you can stick a transparant sticker with a symbol on it, and to really top it off you can make the LED glow dimly to light up the symbol, and lit more brightly when the switch is activated, or to make it blink when there is some kind of malfunction.
The problem was that to see the LED's well during bright sunlight they had to light up quite a bit, but then they were blinding during night time. So we decided they should be featured with an automatic dimming system.
Another thing on our wish list was that we wanted to save power by automatically switching off the anchor light at sunrise (when we are still asleep). And if we were going that route anyway, to have all the other ships lights automated in a similar way.
Originally our ship was equipped with a system where the current to the filaments caused a small reed switch to close so you could check whether all lights were working as intended. But when we replaced a lamp with an LED this system ceased to work. And that is unfortunate, because it is very convenient if you can check the proper operation of the lamps during day light hours before you leave for a night trip.
So, time to develop something. It became obvious very soon that the use of a small poststamp computer of 2 Euro's would be the easiest and cheapest way to achieve our goal. As usual, the project increases somewhat in scope and becomes a bit more advanced than originally planned. When it was finally ready, we thought that more cruisers could benefit from it, so here is a description of the project.
Let's see what this tiny box can do:
- Automatic control of the ships lights
- An infinite amount of independent light channels can be connected to this box. The channels can be fused independently. Each channel has a three position switch and can be switched off, on, or set to automatic. Automatic means that the (adjustable) light sensor controls the switch.
- Lamp monitoring
- Up to five channels can be monitored so you can see in a glance that the respective lamps are indeed functioning. If the lamp is lit, the LED in the switch is lit as well. If the lamp is switched off, so is the LED. But if the lamp is defective its current decreases and the LED starts blinking. In addition an alarm output is activated (which you can use for anything including a sirene). Of course for every channel you can configure the nominal current. This also means that in when multiple lamps are connected to one channel that you can still detect the failure of just one lamp.
- Automatic adjustment of the switch backlights to the ambient light.
- The LED's are adjusted to the ambient light. So during daylight hours bright enough to get noticed, but during the night dimmed to a non-blinding level. The maximum and minimum illumination level can be adjusted, just as the ambient lighting level where the setting applies to. The intermediate levels (255 steps!) will be calculated automatically. There are two dimming-channels available: one for the main switch panel inside, and one for an additional panel in the cockpit. The latter can be activated independently.
- Averaging of light intensity fluctuations
- The light sensor is sampled twice per second, but all values are averaged over a two minute course. So someone shading the sensor momentarily or hitting it with a flash light will not influence the adjustment of the ships lights or panel lighting.
- You don't have to use all features. You can use this system partially or introduce it gradually.
How easy to operate is it?
- Control of the lights
- We use switches with three positions: off, automatic, on. Off and On we don't have to explain, except that in these positions the electronics is not involved at all, so you really override the automatic function. On the Automatic position the ambient light intensity is used to decide whether the associated light is switched on or off. We use four channels for our ship (see picture), but we have provided for five. Each channel has its own switch with three positions.
- Adjustment of the treshold
- Adjustment of the treshold where the system switches from day to night is carried out by pressing the push button while switching on the box. The LED on the box starts to blink until you release the push button: the light level at that moment becomes now the new treshold.
- Configuration of the lamp monitor
- Configuration of the lamp current can be done by switching on the lamp and then pushing the button on the box. You only have to do this once because the data will be saved. After this configuration the LED of the respective channel starts to blink when the current decreases more than 10%. This usually indicates that a lamp or LED has become defective. In the beginning it can happen that when the ships voltage decreases the alarm will go off while the lamp functions normally; this is due to the fact that in conventional lamps the current decreases in the same proportion as the voltage. In the case of LED's it is often just the other way around. By pressing the button again the alarm is cancelled and the updated current value is now saved. The current is only saved for channels which are switched on at that moment.
- Configuration of backlight intensity
- If the push button is pushed when no ligting channels are activated then the backlight intensity of the panel is configured. This is how it works: If the ambient light level is below the treshold (the night setting) then the lower limit of the backlight is configured. The potentiometer on the box can be used to set the backlight intensity while the push button is kept pushed in. When the button is released the backlight intensity will be recorded as well as the current ambient light level. The similar applies to setting the day light values: you are then adjusting the brighest backlight intensity at the ambient light level of that moment. All intermediate backlight intensities are then automatically selected according to the ratio between these two set points.
Some experience in building electronics is recommended. There is no PCB available, many parts are located outside the control box anyway. The core of this design is an Arduino Pro Mini, which needs to be programmed for this application. You will find a link to the source code further down this article.
- The light sensor is built around an LM358 opamp. The photo resistor (R1) is a VT93N2. Other types are probably usable as well. Of course the idea is that the sensor is mounted outside, or at least facing through a window. The circuit is dimensioned in such a way that the focus is on the darker area of twilight. The circuit doesn't distinguish between lightly covered or bright tropical conditions. Nobody here who wants to put the treshold in this area, right? The LM358 operates on 5 Volts, taken from the efficient voltage regulator of the Arduino.
- Light switches
- The choice has been made for switching the positive voltage, although that is a bit more complicated in this particular case. But switching the positive voltage has the advantage that when the switch is off there is no voltage anymore on the wires, and that the lamps can share the minus or can be connected directly to the ships ground.
The switches have three positions: ON, OFF, and AUTOMATIC. The circuit has been designed deliberately to have the current going through the switch in the ON position: If the electronics fail the lighting can still be switched on. In the position AUTOMATIC the current is routed via a power Mosfet, type IRFZ44N, but other types might work just as well. It could have been done with relays, but the advantages of Mosfets are that they are cheap, don't wear, and don't consume control current. The resistance in the on-condition is 17.5 milliohms, so not really significant. They can switch 40 Amps so that would be enough for even the most ambitious navigation lights. The only problem is that the Mosfets require a positive control voltage of at least 10 Volts on the gate over the source to switch fully on. But since the source carries 12 Volts already this means that we need 22 Volts to control the Mosfets. Generation of the 22 Volts is carried out with the charge-pump built using the NE555.
- Charge pump
- The NE555 oscillates around 20kHz. The output alternates between 0 Volts and 12 Volts. When the output is "low" C3 is being charged via D2, when the output then changes to "high" C3 is lifted above the power supply rail and will show 24 Volts. This charge can not flow back via D2 but it can flow via D3 to C4. C4 will thus be charged to 24 Volts. The diodes D2 and D2 need to switch fast and with low voltage drop; that's why I used Skottky diodes. With normal diodes (1N4148) it will work too but with higher losses.
The NE555 only receives supply current when the Arduino decides it is "night". The "it_is_dark" output of the Arduino is then high, Q3 goes into conduction causing Q4 to supply current to the NE555. All connected Mosfets go into conduction, but the associated lamps are only lit when their switches are set to "automatic".
- Current sensor
- The current of each channel is determined by measuring the voltage drop over resistance R6. The value of this resistor depends on the target current of the associated lamp: it is best to have about 0.2Volt voltage drop over this resistor. The formula U=IxR dictates that with a current of 1 Amp we will need a resistor of about 0.2 Ohms. It is not cricial, but if we have an anchor light with an LED consuming only 100mA, then a resistor of about 2 Ohms would be more appropriate.
The analog input of the Arduino can measure voltages between 0 and 5 Volts. So we will have to scale down the voltage drop over the resistor to this range. This is done with zenerdiode Z2, which has a value of 10 Volts, which means that it will drop off a fixed value of 10 Volts. So the value measured at the resistor is allowed to vary between 10 Volts and 15 Volts. If the voltage wanders outside this area you will probably have more worries than just a malfunctioning current sensor.
We would like to detect a voltage drop of 0.2 Volts, but the on board voltage can vary between 10 and 15 Volts. So we will have to measure the on board voltage as well as a reference. This is done with the help of zenerdiode Z1, which also has a value of 10 Volts. By comparing this value with the value measured at the resistor R6 we can establish how much voltage has been lost over this resistance.
Of course we could inflate the voltage drop of 0.2 Volts to the full scale 5 Volts of the Arduino's ADC with the help of an opamp. But for our application that would be unneccesary complicated: the Arduino digitizes the 5 Volt scale in 1024 separate steps. So one step would be equal to 5 millivolts. With our intended voltage drop of 0.2 Volts we will have more than enough resolution left.
- LED indication
- In the schematic diagram the indication led of the first channel is labeled D1. This LED receives backlight current via R8. The LED shines bright when it receives current via R9. The backlight can be omitted by taking out R8. The values of R8 and R9 depend on the type of LED you use. Most LED's have 20mA as maximum current. With 5 Volts power supply and 1.5 Volts of voltage treshold over the LED you need to dissipate 3.5 Volts in the resistor. According to the formula U=IxR you will need a resistor of 180 ohms to achieve this.
In our ship we have used ultra efficient LED's which are still very bright with only 4mA's. For backlight function we have used a series resistor of even 33k, so this means that the current through the LED is only 0.1mA! So what this all means is that you will have to experiment a little and adjust the resistors to your LED's. For R8 you should use a value which produces the maximum of light you would like for backlighting, for R9 you should use a value which produces the maximum value you would like for indication purposes. The Arduino can dim this level, but it can not increase it.
The minus of each LED is not connected directly to ground, but via Mosfet Q2. This Mosfet is controlled by the Arduino and delivers pulsewidths which can vary between 0% and 100%. The connected LED's can be varied in light intensity in 255 steps.
- In the schematic diagram there is one channel depicted (around Q1), plus another one (without component labels) on the right side. In a similar way the amount of channels can be extended to five. Even more channes is possible, but then the additional channels won't have current sensing and thus computer controlled LED indication. Z2 and R10 can then be ommitted for the extra channels, and R9 will not be connected to the Arduino but to the positive wire of the assiciated lamp. Resistor R6 for these channels can be replaced by a solid wire.
- Alarm. The output labeled ALARM in the source code will become high (5 Volts) when any lamp malfunctions.
- Extra PWM-output. There is an additional LED backlight group available on pin "PWM2_OUT". This output can be used in a similar way as with Mosfet Q2 to control an additional group of LED's, like for a panel in the cockpit. The output PWM2_OUT only activates when the input "PWM2_ENABLE" is connected to ground.
The software is surprisingly uncomplicated. To program the Arduino you will need, dependent of the model Arduino, an external programmer. The Arduino Pro Mini we used needs an external programmer, but it is commonly available, with the same size and costs of the Arduino itself. And of course you will need the source code: Download the source code here.
The source code is commented so you can easily adapt it to your own needs. But only start doing this once you have confirmed that your combination of electronics and software actually works.