PDA

View Full Version : sensor switch


Malc C
Jul 24, 2005, 07:31 PM
I'm looking for ideas on how to wire up a switching CCT (OT not model related)

I use a plug in timer that turns on and off a set of mains voltage lights. I also have a set of LEDs that are run from a power adaptor. What I would like to do is to detect when the mains light switches off so it then activates the LED.

I intend to program a PIC with a simple delay so that the LEDs are switched off after a period of around an hour. So the cycle goes like this:

11:00 am - Mains light on
10:00 pm - Mains light goes off and LED's come on
11:00 pm - LEDs go off

This then repeats each day.

I did think about using a relay with a 240 v AC coil which is driven from the plug in timer, with the contacts used as an inline switch for the PIC/LEDs. When the power to the main lights is cut the relay drops out and the contacts close allowing the +5v to be fed to the PIC, which switches on the LEDs (via a transistor driver) for the length of the delay loop. When finished the LEDs are switched off by the PIC and then the hole thing is reset the following morning when the mains light is turned on again.

just wondering if there is an easier way to go about it ??

thanhTran
Jul 26, 2005, 05:00 PM
I think parallel your pic (with power adapter) with the main switch (timer switch). That's when the switch is open, the power goes throught the load and will supply to your adapter with the PIC on the other side of the adapter. PIC will act as a timer and turn off the led after 1 hour. You don't need any relay in this case.

thanh

Malc C
Jul 27, 2005, 05:29 AM
Thanh, I don't really follow your logic. If I run the PIC off the same feed for the lights, there will be no power to the leds when the timer switches the power off.

thanhTran
Jul 27, 2005, 06:28 PM
The basic circuit is like this:

AC in main switch
+---------+--+--/ +---+--------+(load bulb)+-+
| | |
| | |
+- adapter -+ |
plus pic |
timer |
|
+----------------------------------------------+

What I intented was that when the switch is open, the AC will flow through the load (bulb) and feed to the adapter which will feed the pic with timer to turn on the led. When the switch is close, the bulb (load) and there is no power feeding the adapter. Hope you get the idea. I think it will work :).

Thanh

thanhTran
Jul 27, 2005, 06:29 PM
darn, all my ascci text are not aligned

thanhTran
Jul 27, 2005, 06:40 PM
this is what I meant:

http://static.rcgroups.com/gallery/data/500/41019pictimer-med.JPG

Malc C
Jul 28, 2005, 05:24 AM
Can't see that working myself as power can flow through the transformer regardless of if the switch is open or closed ??

TimAuton
Jul 28, 2005, 12:06 PM
It can but it won't; the transformer is a high-inductance path and the closed switch provides a very low inductance path. Electrons always prefer to take the easy way, the lazy sods.

jfitter
Jul 28, 2005, 12:21 PM
Try this. Theoretical only - I haven't built it and don't intend to. Just provided here for you to get ideas.
Note - this is a HOT circuit. Only play with this if you know what you are doing.

The principle is that a forward biased LED can be used as a voltage reference in a regulator. It works very well. Here we have 3 red leds in series to provide about 5.1V. If you want more leds, put them 3 at a time in parallel. 240Vac is applied across the leds through a current limmiting resistor. The diode works as a half wave rectifier and protects the leds from the high reverse voltage.

No guarantees. This is just an idea. Don't kill yourself.

Malc C
Jul 28, 2005, 12:35 PM
Jfitter,

looks good.. might try that

jfitter
Jul 28, 2005, 12:37 PM
Malc C - The circuit IS the regulator. All of the circuit is shown - there is no more.

jfitter
Jul 28, 2005, 12:43 PM
I just noticed something. If the lamp fails the leds go out. Is that a bug or a feature - as Bill would say!!!!

Dan Baldwin
Jul 28, 2005, 01:19 PM
It looks like the transistor will initially be turned on, preventing the PIC from powering up. Perhaps a capacitor could be added between the base and emitter of the transistor to keep it off for long enough for the PIC to power up and turn the transistor off with the output.

Dan

jfitter
Jul 28, 2005, 01:57 PM
I caught it too Dan. Trouble with these fora, one tends to rush things a bit too much. The original circuit would not work for the reasons you stated. The new circuit is better - safer (neutral referenced) - zener for a reg - just need enough leds to make a voltage drop more than the zener. I've used zeners for simple pic circuits often and they work fine. The pic doesn't care too much what it gets fed. Low current only. Here we have just the pic (2mA) and the base drive for the tranny (not much, sfa if you use a fet).

Dan Baldwin
Jul 28, 2005, 02:20 PM
Yup, that otta work. The LEDs still won't light if the main bulb is burned out, but that sounds like a feature to me. :D

Dan

thanhTran
Jul 28, 2005, 06:46 PM
Can't see that working myself as power can flow through the transformer regardless of if the switch is open or closed ??

Why not?

1. when the switch is close, the light is on, there will be no power to the light. This is correct right?

2. When the main switch is off (due to your timer or whatever), the current runs through the load and go to the adapter. Your pic will now has power. Right?

I can't see why it's not working :confused:. I have done many things this way many times.


thanh

thanhTran
Jul 28, 2005, 06:49 PM
It can but it won't; the transformer is a high-inductance path and the closed switch provides a very low inductance path. Electrons always prefer to take the easy way, the lazy sods.

Right, but that's what he wants right? When the switch is close, there is no need to do anything. Only when the someone turn off the main light (by the switch) that's WHEN the PIC needs to work to turn on the led for another hour!

Can't see anything wrong with mine :)

thanh

jfitter
Jul 28, 2005, 08:08 PM
When the switch is open the current through the coil lights the lamp. You need current limiting.

thanhTran
Jul 28, 2005, 10:01 PM
When the switch is open the current through the coil lights the lamp. You need current limiting.


that will be very minimum. If the transformer & pic consume 2W, and the light is 100W, would it be noticed? The light bulb is just like some wire in that case.

thanh

jfitter
Jul 28, 2005, 11:04 PM
If the switch is closed, the lamp glows and the pic gets no power -OK
If the switch is OPEN, the coil is a DEAD short to the lamp. Either the lamp will glow or the coil will fry. The coil will not limit current.

thanhTran
Jul 29, 2005, 04:08 AM
If the switch is closed, the lamp glows and the pic gets no power -OK
If the switch is OPEN, the coil is a DEAD short to the lamp. Either the lamp will glow or the coil will fry. The coil will not limit current.

1. It won't fry. The "coil" is a 110-5volts AC adapter. It won't fry when it's connected directly to AC so it won't fry when serialize with a lamp either.

2. The current is too small that the lamp won't lit.

Try it. I just did to prove it :)

http://www.tjtrc.com/Pictures/miscs/s_IMG_4915.JPG

http://www.tjtrc.com/Pictures/miscs/s_IMG_4916.JPG


In the picture, the lamp is 100W 110v. The "coil" is a 110v wall charger for my Hitec Eclipse 7 TX. And the voltage on that socket is 110V. Yup the wires ARE HOT. Don't worry :) I used to play with basic electric, transformer, light bulb, switch with hot AC voltage when I was in 9th grade. I rewounded my first transformer to convert 110vol down when I was in 7th grade.


thanh


edit: the voltage is AC so the "coil" is not a registor. I used to be afraid to plug a transformer to AC when I measured it had only 3 Ohms.

TimAuton
Jul 29, 2005, 09:34 AM
If the switch is closed, the lamp glows and the pic gets no power -OK
If the switch is OPEN, the coil is a DEAD short to the lamp. Either the lamp will glow or the coil will fry. The coil will not limit current.

The coil will limit AC current, assuming there is a load on the other side of the transformer. It may not have much in the way of resistance, but it does have impedance by virtue of its magnetic coupling to the other side of the transformer and the load on that side. It's a dead short for DC, but not for AC.

Light bulbs also have different resistance depending on temperature, at a low temperature the filament has a lower resistance then when hot. If the limited current that gets past the transformer isn't enough to significantly heat the element it will remain at a relativley low resistance, looking more like a bit of wire than a load.

Malc C
Jul 29, 2005, 12:51 PM
:eek: that looks scary !

The idea I had, and probably safer is to use a 240 ac relay with change over contacts. The relay coil is wired in paralle with the main lights so that it is always "on" when the main lights are on. Then when the timer cuts the power to the main lights the relay is de-energised and the contacts change over and thus allows the 12V from the power adaptor to flow to the timer board where a 5v regulator is used to run the PIC. The output from the PIC then switches either a relay or transistor to allow 12v to flow to the invertor for use with cold cathode tubes. I need to use something that can handle 500mA current draw for the invertor. Hopefully the attached image will make it clearer

thanhTran
Jul 29, 2005, 01:40 PM
Malc, your circuit will definitely work and probably safer to use. It just happens to have more parts on it. Maybe if you can't find a 240v relay you can use another 12v with another 12vol transformer. I just try to say that the lamp and a small transformer would work like I prove above. The transformer was charging a flight pack and the main light wasn't lit. I also belive 12v at 500mA (6W) will also work. It's probably not a good idea to use that in your case as you are using neon lights with transformer in your design. It may still work but I'm not sure.

I like the circuit jfitter designed. But since you need 500mAh, that's probably not working

By the way, anyone has a method of converting down 110v or 220v down to use for a pic or led with some capacitor, registor and diode?. I saw this circuit in some wall flash light charger, but I don't know how to calculate them :). The one jfitter designs use registors and diode, which could cause the regitor to burn up if the current is a little high.


Thanks

Thanh

Malc C
Jul 30, 2005, 07:19 PM
Thanks for all your ideas guys and to Thanh for risking a few kicks from mains voltage !

To be safe I intend to use a 240v ac relay as the trip switch for the device amd I've been playing with the PIC and working out some timings. I've also come up with this proposed diagram for the CCT. From what I can gather the invertor draws less than 300 mA hence the use of a simple transistor. Comments please

Dan Baldwin
Jul 31, 2005, 12:44 AM
You can't just put a zener across a 12 volt wall transformer to limit it to 5.1 volts. You will need to use something to limit current such as a resistor between the 12 volt rail and the zener/pic.

Dan

Malc C
Jul 31, 2005, 05:39 AM
Dan,

Something like this:

Dan Baldwin
Jul 31, 2005, 09:22 AM
Yes, something like that. I would use a smaller resistor though; perhaps a 330 ohm.

Dan

Malc C
Jul 31, 2005, 09:38 AM
Cheers,

I'll try it with a 330 Ohm and see what happens :)

Dan Baldwin
Jul 31, 2005, 10:20 AM
I see a couple more problems. You say that the inverter draws about 300 MA, but the transistor you are planning on using is only rated at 100 mA.

Since the PIC is running at 5 volts, and you have a 1 k resistor in the base circuit of the transistor, you will have less than .5 MA current flow, so whatever transistor you use will have to have a current gain of over 600.

You could use a darlington power transistor such as the TIP120, and it would take care of both problems.

Dan

Malc C
Jul 31, 2005, 03:11 PM
I just didn't want to drive the tranny hard and though a 1K would be fine. Thanks for the suggestions

Dan Baldwin
Jul 31, 2005, 11:41 PM
In this case since you are using the transistor in a switching circuit, you want to drive the transistor into saturation, so you need to drive it hard, but you do need to limit the base current with a resistor. If you use a darlington transistor, the 1K is fine. If you Don't use a darlington, you will probably want to change the base resistor to 330 ohms, and the resistor before the zener to a 220 ohm, or replace the resistor and zener with a 5 volt regulator like a 7805.

Dan