Experiment 7: It’s Chronophotonic - Make: More Electronics (2014)

Make: More Electronics (2014)

Chapter 7. Experiment 7: It's Chronophotonic!

This experiment will make use of the information from previous experiments relating to transistors, phototransistors, 555 timers, and comparators. Yes, there was a good reason for laying all that groundwork: you will now be able to utilize that knowledge to build a gadget that has a practical application. Moreover, there will be a bonus: the fun of cracking open a digital alarm clock, figuring out how it works, and repurposing it.

A slightly different and much shorter version of the project was published in Make magazine, where I had to omit a lot of explanations for reasons of space. This new version contains several improvements, is much more detailed, should be easier to understand, and will work with a wider variety of clocks.

The objective here is simple enough: to create a device that will switch a lamp on and off in your home when you’re not there. Of course you can buy a variety of cheap gadgets to make it look as if you are at home, but for me, they don’t do the job right. Where I live, the sun sets two hours later in the summer than in the winter, and if I use a timer, I have to reset it manually several times a year to allow for this.

Really, the lamp should turn itself on by sensing the dimming of the light that occurs at sunset, and a phototransistor connected with a comparator can be adapted to perform this task. You can buy a gadget to do this, but it turns the lamp off after a fixed interval. This seems inappropriate to me. Most people go to sleep on a fairly consistent schedule. They don’t turn a lamp off later just because the sun sets later. Therefore, to be realistic, the lamp should turn itself off at the same time every night.

So, here’s the specification for my kind of lamp controller: it should use a light sensor to switch the lamp on, and a timer to switch it off. Does such a device exist? Apparently not. Thus I created the chronophotonic lamp controller, because I had no other choice.

Warning: Avoid Dangerous Voltage

This circuit is capable of controlling a lamp of up to 60W powered by house current. If that’s what you want to do, I can’t stop you from doing it, but I think it’s a much better idea to use a 12V LED lamp or 12V halogen lamp. House current at 110VAC or 120VAC really is dangerous. If you’re a young reader, please ask for parental advice before messing with it. No matter how old you are, you can always make mistakes, and your life may last longer if you make mistakes with low voltages than with house current.

If you really want to switch house current, a good compromise is to buy something designed for this purpose, such as the PowerSwitch Tail from MakerShed. This requires a 3VDC to 12VDC input that passes through an internal opto-isolator, keeping you (and your breadboarded circuit) safe from higher voltages. You can use the 6V bus voltage in the Chronophotonic Lamp Switcher circuit as the power to be switched by the relay in the circuit, connecting directly to the PowerSwitch Tail. Of course, you will pay extra for this protection.

The Circuit Basics

Figure 7-1 shows a schematic that will get you acquainted with some of the components. The top half is very similar to the comparator circuit from Experiment 6 (in Figure 6-3), with some of the wires rerouted. The principal differences are that the LED attached to the LM339 output has gone, the pullup resistor to the left of the output of the LM339 has been increased from 470Ω to 10K, and the 500K potentiometer providing adjustable positive feedback between the output and the input has been replaced with a fixed 220K resistor, because this will set an appropriate amount of hysteresis here.

After you make these alterations, you’ll be ready to add the rest of the components in the circuit. Figure 7-2 shows how a breadboarded version can look.

The phototransistor and comparator from Experiment 6 now trigger a 555 timer that emits a one-second pulse. The circuit is now powered by 6VDC.

Figure 7-1. The phototransistor and comparator from Experiment 6 now trigger a 555 timer that emits a one-second pulse. The circuit is now powered by 6VDC.

The first section of the chronophotonic lamp switcher.

Figure 7-2. The first section of the chronophotonic lamp switcher.

§ This is now a 6VDC circuit. Because I will be adding a transistor-driven relay that has a common ground between its coils, transistors driving the relay must be used in common-collector mode, which entails a significant voltage drop. The 6V supply will compensate for this.

You need to remove the LM7805 voltage regulator from your power supply and substitute an LM7806. This is a simple substitution, because their pinouts are identical. I have not bothered to include the power supply in the schematic, because it’s so simple.

The output from pin 2 of the LM339 now runs down the left side of the schematic, through a 1µF capacitor, to the trigger pin of the 555 timer. The timer has its own 10K pullup resistor to keep it normally positive so that its output is normally low. Remember:

§ When a 555 timer is wired to run in monostable mode, its output stays low so long as the voltage on its trigger pin remains high.

§ When the trigger pin is pulled low, the output goes high, for a duration determined by the capacitor and resistor attached to the timer.

The idea is that the phototransistor causes a change in the output from the LM339 when the light gets dim, and the LM339 triggers the timer, which will emit a pulse lasting for about one second. This in turn will activate a latching relay (not shown yet) that will turn on a lamp. For the time being, I have shown an LED attached to the output of the timer, just so that you can see that it’s working.

Apply the power and wait for the timer to reset. Shine a bright light on the phototransistor, then slowly move the light away (or shadow it with your hand) to simulate the dimming that occurs at sunset. You should see the LED pulse for 1 second. Now try adjusting the sensitivity of the phototransistor with the trimmer potentiometer, and repeat. Make sure this circuit works reliably before you continue.

Step Two

The next step in this project is shown in Figure 7-3. The output from the timer now goes through a 1K resistor to the base of a transistor, and the transistor will switch one coil of a 3VDC latching relay. The other coil of the relay is activated by a pushbutton, such as a tactile switch. The 47Ω resistor is necessary to protect the relay from the full voltage of the power supply. This pushbutton will be eliminated in the final version of the circuit, but is useful for demonstration purposes. Likewise, LEDs have been added to the relay outputs, to show their status.

The previous schematic has been extended by adding a relay. Previous wiring is gray.

Figure 7-3. The previous schematic has been extended by adding a relay. Previous wiring is gray.

You may remember from Make: Electronics that a latching relay “sticks” in either of its two states without consuming any power. It just needs a brief pulse to flip it to and fro. Consequently, it’s ideal for a circuit that has to switch something on (in this case, a lamp) for long periods, while minimizing power consumption.

You may wonder why we need a transistor between the relay and the output from the timer. Isn’t a bipolar 555 timer sufficient to drive a small relay directly? Well, theoretically, yes; but when a relatively low power-supply voltage is being used, the relay can make the timer behave erratically. This is not described in the timer’s datasheet, but I’ve seen it happen.

Circuit Testing

Follow these steps to check out your circuit:

§ Press the button, and the lower LED beside the relay should light up. Eventually this setting of the relay will turn an external lamp off, when we connect it.

§ Release the button, and gradually dim the light that falls on the phototransistor, simulating the setting of the sun.

§ Eventually the relay should click into its other position, causing the upper LED beside the relay to light up. Eventually you will replace this LED with a lamp that comes on at sunset.

§ Press the button again. The button will eventually be replaced by a clock that turns the lamp off at a predetermined time.

§ Allow the light on the phototransistor to increase gradually, simulating the beginning of a new day. Nothing should happen.

§ Dim the light again, and the cycle should repeat.

Relay Details

The relay I have chosen is a Panasonic DS1E-SL2-DC3V that has coils designed for 3VDC, because the output from the transistor will be around 4V, which will not switch a 5V relay reliably. According to the datasheet for the 3VDC relay, it can tolerate a coil voltage as high as 4.8VDC, so it is appropriate for this job.

The relay is shown in Figure 7-3 with the pins positioned as you will use them (seen from above). Check Figure 7-4 if you are uncertain about their function. The numbers beside the pins are the numbers you will find molded into epoxy underneath the relay. If you’re wondering why the pins are not just numbered 1 through 6, it’s because Panasonic wanted a numbering scheme that would be consistent throughout all of its relays, some of which have as many as 12 pins.

If you substitute a different relay, check its datasheet for the pin locations and functions, as they are not standardized among different manufacturers. You must use a 3VDC dual-coil latching relay, and it should be rated to switch 2A.

Pinouts of the Panasonic DS1E-SL2-DC3V relay, seen from above. If a substitute relay is used, its pin layout will almost certainly be different.

Figure 7-4. Pinouts of the Panasonic DS1E-SL2-DC3V relay, seen from above. If a substitute relay is used, its pin layout will almost certainly be different.

Note that the coils inside a relay may not be bidirectional. For the Panasonic relay, you have to apply negative ground in the position shown. If you put the positive supply there instead, it won’t work.

The Coupling Capacitor

A key concept in this circuit is the 1µF capacitor between the output from the comparator and the trigger pin of the 555 timer. Remember that a capacitor in this configuration blocks DC, but when the voltage applied to it changes, the capacitor passes the pulse through.

Here’s how it works:

§ Bright light on the phototransistor creates a high input to the comparator.

§ The high input eventually causes the comparator to have a high output, keeping a positive charge on that side of the capacitor.

§ The 555 timer has a high input because a 10K pullup resistor maintains it.

§ The relay is in its “off” position.

§ Nothing happens.

Now when the light on the phototransistor starts to dim:

§ The voltage from the phototransistor drops below the reference voltage on the comparator.

§ The comparator output flips low.

§ The coupling capacitor passes this fluctuation through to the timer, momentarily overwhelming the 10K pullup resistor.

§ The timer reacts by emitting a high output pulse that triggers the relay. The relay moves to its “on” position (which can turn on a lamp).

§ After that, the coupling capacitor resumes its function of blocking DC.

Make sure that the circuit works. So far, it is only being triggered by photons (which you can think of as being particles of light) and the tactile switch. The next step is to add the “chrono” part of “chronophotonic.”

Cracking a Clock

If you wanted to build your own programmable timer, you would buy a timer on a chip, and a numeric display, and some pushbuttons to set the timer—but that sounds expensive and complicated to me. Alternatively you can use a microcontroller with an external clock crystal, but you would still need a numeric display, and the setup is still more complicated than I prefer.

At my local Walmart, Target, or Walgreen’s, I can buy a battery-powered digital alarm clock for about $5 that has its display and buttons built in. Can it be used somehow with the chronophotonic lamp controller circuit? I think it can.

Just make sure that you choose a clock that runs off two 1.5V batteries. Be careful about this: Some alarm clocks only use a single 1.5V battery, which will not work in this circuit. Travel clocks often are powered by one 1.5V battery. Read the box carefully!

Warning: No AC-Powered Clocks!

Please don’t try to adapt a clock that plugs into a wall outlet. Internally the clock probably transforms 110VAC to a safe voltage, but there’s a significant risk of making a connection with the higher voltage by error.

Looking Inside

So long as you have a 3V battery-powered clock, the brand and model shouldn’t matter, because any digital clock must switch power to a beeper internally, and this switching operation can be tapped for the needs of our circuit.

Your first step is to open the plastic case of your clock. The black clock in Figure 7-5 has four screws underneath (circled), three of them deeply recessed. The white clock in Figure 7-6 has only one screw, hidden inside the battery compartment. The picture shows it being removed with the kind of miniature Phillips screwdriver that you will probably need. They are sold in sets for a couple of dollars at your local hardware store.

All four screws (circled) must be removed to open this clock.

Figure 7-5. All four screws (circled) must be removed to open this clock.

Only one screw secures the case of this clock, but it is hidden inside the battery compartment.

Figure 7-6. Only one screw secures the case of this clock, but it is hidden inside the battery compartment.

Clock Voltage

Once you open the case, your first priority is to check the power. Insert the batteries and then look at the underside of the battery compartment. Three clocks are shown in in Figure 7-7, Figure 7-8, and Figure 7-9. In each photograph, the tabs labelled A and B deliver +3V and 0V, respectively. Use your meter to check the tabs in your clock.

3V battery power is delivered through tabs A and B. Tab C has no connection. D identifies the beeper. E connects with an LED that lights the display when the alarm goes off.

Figure 7-7. 3V battery power is delivered through tabs A and B. Tab C has no connection. D identifies the beeper. E connects with an LED that lights the display when the alarm goes off.

3V battery power is delivered through tabs A and B. Tab C provides 1.5V for the clock chip. D identifies the beeper.

Figure 7-8. 3V battery power is delivered through tabs A and B. Tab C provides 1.5V for the clock chip. D identifies the beeper.

3V battery power is delivered through tabs A and B. Tab C provides 1.5V for the clock chip. D identifies the beeper.

Figure 7-9. 3V battery power is delivered through tabs A and B. Tab C provides 1.5V for the clock chip. D identifies the beeper.

In the three photographs, the tab labelled C can supply 1.5VDC by tapping into the connection between the batteries. Some clocks don’t make use of this feature, while others use it to run chips that are designed for low voltages. It is of no interest to us, because we need the 3VDC that the clocks use to activate their alarm beepers.

The beeper in each clock is labelled D. The red clock in Figure 7-7 also has a wire labelled E, which lights an LED.

Now you need to find out what the clock actually does when it starts beeping. With the batteries in the clock, hold your black meter probe against tab B, the negative side of the power supply. You may find this easier if you use a patch cord with an alligator clip on each end. One alligator grips the tab, while the other grips the black meter probe. This allows you to use both hands for the rest of the procedure. A setup to measure beeper behavior is shown in Figure 7-10.

Measuring voltage on the beeper inside a clock, using patch cords with alligator clips to allow hands-free operation. The beeper is the thin, circular object with a red alligator clip gripping one of its solder joints.

Figure 7-10. Measuring voltage on the beeper inside a clock, using patch cords with alligator clips to allow hands-free operation. The beeper is the thin, circular object with a red alligator clip gripping one of its solder joints.

Touch the red probe to tab A, just to check that you have at least 3VDC. Now move the red probe to one of the solder bumps on the back of the beeper, and most likely you will find the same 3V voltage as you measured from the batteries. Try the other solder bump, and it should be the same, too. Because there is full positive voltage on both sides of the beeper, there is no potential across it. This explains why it isn’t beeping!

Set the alarm for one minute ahead of the current time, and make sure the alarm switch is on. Your black meter probe must still be securely attached to the negative side of the battery power supply. As soon as the alarm starts beeping, touch your red probe to each solder bump on the beeper again. This time I am betting that one side of the beeper will show an unstable, lower, fluctuating voltage, while the other side stays high. I’m going to refer to the unstable side of the beeper as the “low side.”

Reset the meter to measure AC volts, and test the low side again, while the beeper keeps beeping. I think you will see an AC voltage lower than 3V but probably higher than 1V. It will be fluctuating within a narrower range than the DC reading.

How It Beeps

What is happening here? Well, something has to turn the beeper on and off, and that would be a transistor inside the clock. In all the clocks that I have investigated, the transistor is connected to the low side of the beeper (just like an open-collector output in a comparator) and sinks current through it to make it beep. This concept is suggested in Figure 7-11.

You won’t be able to see an actual transistor, because it will be embedded in the main chip that controls all the clock functions. It’s very likely to be a CMOS transistor rather than the bipolar type illustrated in Figure 7-11, but the principle is still the same. I’ll refer to it as the “beeper transistor.”

Typical configuration to sound a beeper inside the alarm clock. In reality, a CMOS transistor may be used, but the principle remains the same.

Figure 7-11. Typical configuration to sound a beeper inside the alarm clock. In reality, a CMOS transistor may be used, but the principle remains the same.

When the alarm is not going off, the beeper transistor blocks current. The power from the battery has nowhere to go, which is why you could measure full voltage with your meter. You were measuring the voltage either on the high side of the beeper, or on the low side, passing through the beeper.

When the alarm does go off, the transistor sinks power through the beeper, and also sinks power from your meter probe, enabling you to measure a lower voltage on the low side of the beeper. But the voltage didn’t just diminish, it also fluctuated; why was that?

You can buy beepers that create their own audible frequency when they receive plain-and-simple DC power. But they are more expensive than beepers that are passive, like loudspeakers. A cheap clock will have a cheap beeper in it, and the chip in the clock will have to do the work of creating an audio frequency. This is a form of alternating current, probably between 1KHz and 2KHz, which is why you obtained a more meaningful reading with your meter set to AC volts.

I’m betting that the voltage fluctuates between a high near 3V and a low near 0V. You didn’t see this on your meter, because it cannot react fast enough to show it.

Using the Beeps

How can we use the fluctuating beeper signal? Well, we have four comparators inside the LM339, and we’re only using one of them so far, to work with the phototransistor. I’ll call it Comparator A. We can use another, which I will call Comparator B, to work with the clock. In response to a signal from the clock, Comparator B will trigger another 555 timer, which will energize the second relay coil, and switch off the lamp.

The only remaining question is the difficult one: How do we connect the clock to Comparator B? The clock uses 3VDC, while the comparator circuit uses 6VDC, and we have to protect the clock from the higher voltage. The way to do this is by using the convenient feature of the comparator that I mentioned previously: the voltage that the comparator controls can be completely different from the voltage that activates the comparator.

Take a look at Figure 7-12 and the breadboard photograph in Figure 7-13. The three white labels at the top of the schematic indicate connections coming via wires that you will attach to the clock’s positive power, negative ground, and the low side of the beeper. The signal from the beeper passes through a coupling capacitor to the noninverting input of Comparator B on pin 11 of the LM339. This voltage will be 3VDC or less, and activates the comparator.

Pin 13 is the output pin from Comparator B. It uses 6VDC (passed through a 10K resistor) to trigger a second 555 timer, which has been inserted directly above the relay, and now controls the second relay coil through a bipolar transistor.

Incidentally, when you’re wiring this circuit, notice that on the LM339, the pin for the noninverting input that you used previously is not directly opposite the pin for the noninverting input on the righthand side. Check the pinouts of the LM339 in Figure 6-12 to make sure you don’t get the inputs mixed up. Remember, the “plus” input is the noninverting input.

To make this work, the clock and the breadboard must share a negative ground. All voltages have to be relative to the same ground. But the 3V positive voltage from the clock must be kept separate from components on the breadboard, except for the inputs of the LM339. As previously noted, the voltage associated with the current passing through the comparator can be separate from the voltage that is powering the comparator.

When you attach a wire to the beeper in the clock, make sure you use its low side—the solder bump where you detected a fluctuating voltage when the beeper made noise.

The complete schematic for the chronophotonic lamp switcher.

Figure 7-12. The complete schematic for the chronophotonic lamp switcher.

Breadboarded version of the final chronophotonic lamp switcher, omitting the alarm clock and the power supply that are necessary. The three colored wires disappearing off the edge of the photograph at top-right will be connected with the clock.

Figure 7-13. Breadboarded version of the final chronophotonic lamp switcher, omitting the alarm clock and the power supply that are necessary. The three colored wires disappearing off the edge of the photograph at top-right will be connected with the clock.

Adding a wire to that solder bump may damage the beeper with excessive heat—or, equally problematic, you may end up unsoldering the existing wire while you are trying to attach your own wire. Therefore I used wire strippers to open a segment of the existing wire, and I tapped into that. This is shown in Figure 7-14.

The yellow wire is attached to the existing white wire connecting with the low side of the beeper inside the alarm clock. The blue and red wires have been attached to the battery carrier.

Figure 7-14. The yellow wire is attached to the existing white wire connecting with the low side of the beeper inside the alarm clock. The blue and red wires have been attached to the battery carrier.

Eventually you may want to disconnect the beeper, because its noise is irrelevant to the performance of the lamp controller. But for the time being, the noise is useful to notify you of clock activity while you’re getting everything to work properly.

Hooking Up the Clock

Here are the precise steps to upgrade the circuit. Remove batteries from the clock while you follow these steps, until you reach step 6:

1. Connect the negative side of the battery compartment in the clock to the negative bus on the breadboard.

2. Connect positive power from the clock’s battery compartment to one side of a 500K trimmer potentiometer, which will provide the reference voltage for Comparator B. Connect the other side of the trimmer to the negative bus on the breadboard. Connect the center pin of the trimmer to pin 10 of the LM339—the inverting input, which will receive the reference voltage. Set the trimmer to the midpoint of its range. These connections are shown on the righthand side of the schematic.

3. Connect a wire from the low side of the beeper to a 1µF capacitor on the breadboard. (This is another example of a coupling capacitor.) Connect the other side of the capacitor with pin 11 of the LM339, which is the noninverting input. The capacitor will pass pulses from the clock to the comparator, while blocking DC voltage.

4. Add two pullup resistors to pins 11 and 13. Note that one of them is 100K, and its power source is the 3V from the clock, not the 6V on the breadboard. This is important.

5. Power up your breadboard, and check all the voltages carefully, especially on the wires that lead to the clock. You don’t want to burn out your 3V clock with 6V from your breadboard!

6. Insert batteries in your clock and check that there is 3V on the wire carrying power from the clock to the breadboard. Check that the negative ground from the clock is connected with negative ground on the breadboard.

7. Set the alarm for one minute ahead, and wait until it sounds. Your red meter probe should now show a fluctuating output from pin 13 of Comparator B.

This all sounds complicated, but once you get it working, it will be reliable.

The next step is to add your second 555 timer. This is wired to the righthand side of the LM339 in exactly the same way that the first 555 timer was wired to the lefthand side.

How It Ought to Work

While the alarm clock is not sounding its alarm, the positive power from the clock batteries passes through the 100K pullup resistor and keeps the noninverting input of Comparator B at about 3VDC. The impedance of the LM339 is so high, it only draws a few microamps. Then when the alarm goes off, the beeper transistor inside the clock will start oscillating at an audio frequency, sending bursts of pulses through to the noninverting input of the comparator. The comparator will see that during the short intervals between each pulse and the next, the voltage drops below the 1.5V reference that you set with the trimmer on the righthand side of the circuit. Consequently the comparator will trigger the 555 timer, which will activate the relay, which will turn off the lamp.

To a comparator, an audio frequency is quite slow. As soon as the voltage dips below 1.5V just for a fraction of a second, the comparator will pull down the voltage on its output, triggering the 555 timer. The timer, like the comparator, has no problem responding to a rapid input. It will send a 1-second pulse to reset the relay.

As the clock alarm keeps on beeping, it will cause the comparator to retrigger the timer, and the timer will continue to send a high output to the relay—but that doesn’t matter. The relay has already moved to its “lamp off” position, and a continuing high input will just tell it to do what it has already done. After a minute or so, the clock will get tired of beeping, and will stop. The circuit will be stable for the rest of the night.

What happens next? Dawn light will wake up the phototransistor, and Comparator A will respond by changing its output from low to high. This will send a positive signal to the first 555 timer, which the timer will ignore, because it already has a steady positive input from its pullup resistor.

During the day, nothing happens. Then sunset arrives, causing a low output from the phototransistor to Comparator A. The comparator’s open-collector output now sinks current, which is interpreted as a low pulse to the first 555 timer, momentarily overwhelming its 10K pullup resistor. The timer is triggered, and it sends a pulse to the relay, which turns the lamp on.

Now the lamp will stay on until the alarm clock turns it off. Then the cycle will repeat.

You may be wondering, at this point—is this really going to work? Well, my version has worked (with three different clocks), and I think yours will, too. It doesn’t matter what kind of clock you use, so long as it is battery-powered and digital (not some ancient clock with hands that move). Any digital alarm clock must contain a beeper. The voltage on the beeper must change when the alarm goes off, and if you tap into that voltage change, the clock won’t know the difference (so long as you connect it with a very high-impedance device that draws hardly any current—such as a comparator).

Perhaps there is a clock out there in which the beeper voltage goes from low to high, and perhaps it will be a DC voltage instead of the rapid cycles that I have talked about. But all digital alarm beepers sound intermittently, so there will be high and low pulses, and the first low pulse will trigger Comparator B.

Testing

To test the circuit, apply power, shade the phototransistor, then expose it to bright light, then darken it again. This should switch the relay into the “lamp on” position. Now set the alarm for one minute ahead, and when the alarm sounds, it should flip the relay to “lamp off” position. If the on or off cycle doesn’t work, use your meter to check voltages at every point around the circuit. The key to success is being slow, calm, and persistent!

Once the circuit is working, you can remove the LEDs, which are not needed anymore.

For reliable operation, and to minimize power consumption, it’s a good idea to stop the unused inputs of the LM339 chip from “chattering” because they have an undefined state when they are unconnected. Figure 7-15 shows how they can be terminated. One input should have a clearly defined high state, while the other has a clearly defined low state. It doesn’t matter which is which.

How to deactivate the two unused comparators in the LM339.

Figure 7-15. How to deactivate the two unused comparators in the LM339.

Connecting Relay to Lamp

Disconnect the wire that feeds 6VDC to the bottom-right terminal of the relay. Connect this terminal with one side of a power supply for your lamp, and run a wire to the lamp from the top-right terminal of the relay. The other side of your lamp is connected back to the other side of its power supply. Be very careful to keep the lamp’s power supply separate from all other components and conductors on the board. Figure 7-16 shows the circuit.

After the circuit has been fully tested, the LED indicators can be removed from the relay, and a lamp can be connected as shown here.

Figure 7-16. After the circuit has been fully tested, the LED indicators can be removed from the relay, and a lamp can be connected as shown here.

As noted previously, I strongly suggest that you use a 12V lamp. You should find various types of 12V LED lighting cheaply available, and 12VDC power supplies are easy to find because they have been manufactured in huge numbers for laptop computers. Check eBay for “12V AC adapter.”

Once you get the chronophotonic lamp controller to behave properly, you need to decide where to put it. Ideally it should look out through a window facing north. The phototransistor should be protected from direct sunlight and also should not “see” the lamp that it switches.

Wait until the sun is setting, and adjust the left-hand trimmer potentiometer, which sets the reference voltage for the phototransistor. Turn up the trimmer until the lamp comes on, and then back it off just a fraction.

Warning: AC Precautions

If you insist on powering a lamp with AC house current, please take these precautions:

§ Make a permanently soldered version of the circuit. Never supply house current to a breadboard, because it’s too easy to push a wire into the wrong hole. You don’t want components literally blowing up in your face. Also, wires can come loose too easily.

§ Any exposed solder joints that will have 110VAC or more on them should be covered with liquid insulation or some similar compound that becomes an insulator as it sets.

§ The live side of the power supply must pass through a 1A fuse before it reaches the relay.

§ The circuit must be enclosed in a project box. If the box is metal, it must be grounded.

§ Don’t attempt to switch more than a 60W incandescent bulb, and avoid fluorescent bulbs. They contain a ballast that can draw an initial surge of current. This will be bad for the contacts in your relay.

Make Even More

The circuit has a reasonably low power consumption. My version draws about 11mA overall in standby mode, after removing the LEDs from it. The relay uses about 65mA when it is changing from “on” to “off” or back again, but that only occurs twice a day. Therefore, the lamp switcher can be battery powered—but only on a temporary basis. A 9V battery will last for about 24 hours.

You need an AC adapter to provide long-term power. At the same time, if you live in an area where outages are relatively common, you may want to keep a 9V battery in the circuit for emergency backup.

Figure 7-17 shows how it can be done. So long as there is at least 10V going to the 6V voltage regulator, the 9V battery has no load on it and should remain good for at least a couple of years. (Use an alkaline battery, not a rechargeable battery. Rechargeables don’t keep their charge for very long.) The battery might not react well if the AC adapter tries to push current into it, so a diode is put in the way. If the AC power supply fails, the battery takes over, and a second diode prevents it from wasting energy by trying to pass current through the output end of the AC adapter.

Enhancements to the lamp switcher can include power from an AC adapter, 9V battery backup, and a 3.3V voltage regulator that powers the alarm clock, eliminating the need for its batteries.

Figure 7-17. Enhancements to the lamp switcher can include power from an AC adapter, 9V battery backup, and a 3.3V voltage regulator that powers the alarm clock, eliminating the need for its batteries.

If you buy an AC adapter that provides 12VDC, you may also use it to power a 12V LED or halogen lamp. You should add a 100µF (minimum) capacitor across the output from the adapter, just in case it needs some smoothing.

You can get rid of the clock batteries by adding a 3.3V voltage regulator to your breadboard, as shown in Figure 7-17. Its 3.3V output will be acceptable to the clock, as fresh batteries provide almost this much voltage. The regulator will connect with the wires labelled “Alarm ground” and “Alarm positive 3V” in the schematic. The wires that run to the clock will remain in place, because now they will be sending power to the clock instead of taking power from it.

The input to the 3.3V regulator can come from your existing 6VDC power supply. The ground must be the same, but you must be very careful to keep the output separate from the 6V bus. Also, you have to include the usual 0.1µF and 0.33µF capacitors to guarantee an accurate output from the regulator. See Figure 7-17 for details.

What’s Next?

This was a fairly substantial project. Time now for something a bit more “lite” in nature: the interesting things that you can do with an electret microphone costing less than $1, in conjunction with an op-amp, which functions very similarly to a comparator—although with a different kind of feedback.