IR detector, transistor and relay - Page 1
Forum section: electronics / beginners

author: neel
author_rank: Contributor
timestamp: March 30, 2014, 05:47:08 pm
content: Hello there,I'm trying to hack an IR detector to activate a relay. This detector has a led that blinks on detection so my idea was to plug a transistor there that would then activate the relay.My schematic is as attached to the post.Should it work layout-wise or do you see errors ?Just to know if my layout is correct before checking is the problem comes from anywhere else, like base current too low or defective transistor for example.If first tried without the relay part (so, nothing connected to the transistor collector) to check the led was still blinking. Then I added the relay part but it doesn't trigger. I then tried to remove the led from the circuit and it still doesn't trigger the relay.Thank you by advance for your help.edit: forgot to mention on the shematic, relay is an AZ 428. Also when doing this schematic I realized I may have to add a resistor at the collector side, right ?

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: March 30, 2014, 06:38:35 pm
content: Put your led + led current limiting resistor across your diode/relay, emitter goes strait to groundYour IR module might be o/c output ( open collector ) - if that's the case you could use a pnp

author: JoeO
author_rank: Frequent Contributor
timestamp: March 30, 2014, 07:16:51 pm
content: Your relay operates on 12 Volts. It may not work with a supply voltage of 9 volts.

author: neel
author_rank: Contributor
timestamp: March 30, 2014, 07:35:51 pm
content: Yes I agree the LED + it's R should be the relay side. The reason it is there is because it's limiting resistor is on the IR detector, and I just wanted to 1st check my "signal" was going through the base-emitter of the transistor. I was wondering though if having the led there could make too much current go through the transistor base and burn this transistor (?).Now as said I have also tested without the led, so emitter being connected directly to ground (well, to negative led pin on the IR detector, which is not really ground if I'm not mistaken), and the relay still doesn't trigger.I have tried the relay with 9V and it is enough to trigger it. So if you tell me there is no mistake in my schematic, I guess the problem could be R1 being too high ?edit: btw, my DMM is half broken and can only measure ohms, so unfortunately I have no way to check what is happening on voltage/current side until I receive my new meter. Would have helped to find what is going wrong.edit2: I have tried with a led at the collector side and it blinks, so I guess the current is just not enough to trigger the relay.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: March 30, 2014, 08:18:50 pm
content: Quote from: neel on March 30, 2014, 07:35:51 pmMmmmm,The base current controls the collector current.You say 'its limiting resistor is on the detector'and your using that to drive the transistorYou need to know what the pull in current of the relay is.The rule of thumb to use a transistor as a switch and drive it into saturation is Ib = 1/10 of Ic.So, if your relay needs 100mA to pull in, then you'll need around 10mA for Ib.But you say 'its limiting resistor is on the detector', do you know the value of this limiting resistor.You need to provide more info about your IR detector and how it was originally connected.

author: neel
author_rank: Contributor
timestamp: March 30, 2014, 09:35:26 pm
content: Yes I understand Ib drive Ic, the 10x ratio approximation and the needed relay current to be able to determine Ib (thus R1).I have checked therelay datasheetbut couldn't guess from it what the needed current really is. It says "as low as 25mW per pole" at the top, and in the coil section there is "450mW standard" and "80mW, 2pole. 180mW, 4pole (25mW per pole available)" which I don't really understand.So I took 450mW as a safe value, so 50mA @9V for Ic, thus 5mA for Ib. Then I'm not sure why I stated a 5V drop across R1 (guess I messed up with the 5V Vebo in the BC337 datasheet) thus ended with this 5/.005=1kohm for R1Now, on top the R1 voltage drop certainly isn't 5V (right ?) I also "eluded" what was past those led connector pins and considered it was "a 9v power supply" for my transistor baseA fully working meter would help but I haven't any atm. Idk if using a potentiometer for R1 to gradually lower R1 until the relay triggers would be a good idea ? (not sure it would be precise enough to remain safe for the transistor, I guess not).I provided pictures of the IR detector attached to the post if it can help sorting it out.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: March 31, 2014, 02:24:00 am
content: ArrrrrrIt's an alarm PIR unit.Well, i would say that that big long silver thingy to the right of the sensor IS a relay, and if it is an alarm pir then you will have n/o and n/c contacts available on the edge connector, normally with a common between them. Or possibly requiring an external link.If that's the case, that relay should have sufficient current switching to drive your external relay on it's own. using the n/o contacts.

author: neel
author_rank: Contributor
timestamp: March 31, 2014, 08:00:50 am
content: Indeed, I had the feeling from your previous answers there may have had confusion about what the "IR detector" was. Yes, it's a PIR based alarm, sorry if I wasn't clear enough about that.From my understanding, it has only a N/C switch at the I/O bar (see attached picture with those I/O labels). That does not suit well my final goal that is to trigger a mouse click on motion detection.I thought about using a relay directly on this alarm I/O but I wasn't sure it could handle the required current for the relay (though now you tell me it should be ok).But there is another problem possibly preventing using that solution. When I tried the relay to check it was working, I noticed there was a significant delay for the relay to switch when powering it off. It switches fast on power on but takes a few seconds to switch back when cutting power off. That's why I finally decided to plug at the led pins side of the PIR alarm as the behaviour is reversed (normally open).Now maybe the delay I noticed at power off is due to the power source I used to test this relay. I used a 9V DC power supply (it seems you name this "wall adapter power supply" in english) that I just plugged/unplugged from 220V to test the relay, hence the delay for the relay to switch back when unplugging the 9V DC adapter from 220V maybe. Now you told me the PIR alarm onboard relay should handle the current needed for my external relay, I will try this to check if it switches faster on motion detection. If yes, this solution would do the job, though I just find it not the most elegant to have the relay continuously powered ON due to the n/c nature of the PIR alarm output.edit: it seems to work, thank you for your help

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: March 31, 2014, 02:06:44 pm
content: Looking more closely at the pictures, the relay outputs go through resistors to the output connections. So it won't drive your relay directlyThe delay on power down will be caused because of the high on board power filtering and with a low quiescent current will, as you have found, take a few seconds for the caps to discharge and the relay released.If your not using the sensor as designed, why not just remove the on board relay and hook yours across that.Also on the board are two t092 devices, they could both be transistors, one definitely for driving the relay, the other could be a voltage regulator.The diode shown to the right of the sensor, connector side is probably the shunt diode across the relay coil.Another problem is that on power on, the relay is on. To keep the on board relay working and drive your external you could drive your relay with a npn connected via a base resistor to the collector of the original relay transistor. Such that with the circuit powered, the on board relay will be on, grounding the base of your npn keeping it off, when something is detected, the on board relay is turned off, your base goes high turning on your external relay.And then again, you could have another problem, your simulating a mouse key press, you could have problems with keeping the key down for tooo long and relays have nasty bouncing which will cause multiple key presses till it settles.If you can find out which op-amp is the output of the comparator that detects the positive and negative pulses from the sensor that could be used to give you a quick relay pulse.And then again, instead of using a relay, your only simulating a mouse key press, use an opto isolator, no bouncing on them. You'll find one on a dead atx psu.

author: neel
author_rank: Contributor
timestamp: April 01, 2014, 07:40:06 am
content: Hi Mr Smiley,Lot of interesting informations in your answerI will comment one by one but before that will describe a bit my whole project so you get a better idea of it (and maybe have some new interesting ideas that could improve efficiency even more).So what I'm doing is an airflow test bench. I have attached some pictures of it to the post. Basicaly it is a variant of the bag inflation method. I have had disappointing results with the latter as from one test to another the time measurement could vary from a factor 2 (inflation test B taking 2x longer than test A). My guess was the difference was due to how the bag was folded (not the same for each test) and some other factors like the begining of the bag inflation that would also differ largely from test to test (I began the tests with the fan started to prevent measuring the fan acceleration to its nominal speed. This means I had to handle the bag closed until the fan reaches its nominal speed, and when I then let the airflow go into the bag the beginning of inflation was made with higher pressure as the bag side was just in front of the fan, which again induced lot of variation from test to test).Hence why I imagined this variation of the bag method, where the bag is replaced by a solid tunnel. No more variation coming from how blend the bag is at startup, and no more high pressure at the begining of the test as it starts with the tunnel open (so the tunnel is the only load for the fan and this load remains the same for each test). Also the moving plate that goes through the tunnel doesn't touch the border (there is between 1-2mm between the plate and the tunnel border, see attached picture) so the only friction is at the small metalic tube that handles the moving plate on the string guide. The moving plate is also light (esp. versus airflow strength), which mean limited inertia.Ofc, on top of tunnel load, some (limited) friction and inertia, some air goes around the plate as it doesn't touch tunnel border, but not that much I think, if you consider the size of this hole vs the size of the plate. Also the goal is not to measure the exact airflow but to compare with a reference. What I'm doing is to replace the fans of a video projector so I just need to get a decent estimation of how the replacement fans airflow compare with the original ones, which I hope this new bench method will give reliable results about. If the test shows decent repeatability, I think the comparative results with my reference fans should be reliable.So now the goal is to get the best accuracy from the test bench, which means not hurting the current mechanical accuracy with the electronic detection of the starting / ending points. I expect the typical measurement to be (well ?) below 500ms (with the bag inflation test, that was about the same size than my tunnel, typical measure was below 1000ms). Software side, I managed to make a ms accurate time meter. The end of the plate travel is detected by contact of an aluminum ring on the plate (see picture) with the screws that makes the mechanical stops in my tunnel, so I guess it should give a very good detection accuracy.Remains the detection at entry point. My initial idea was to do it by mechanical contact like for ending point. I tried with very thin metalic wires each side of the tunnel entrance and detection was very bad. I did the same with small aliminum foil, expecting better contact chance but still detection was bad. On top of that, despite both were very flexible (mechanicaly), there was still a chance it could hurt measurements accuracy as it would slow down a bit the moving plate, even if my main concern was it could possibly skew the plate on its string guide, hurting the smoothness of its travel, thus repeatability of the test.So here came in play the idea of a contactless detection of entry point. I checked around what I had available, I had not photodiode but had those PIR alarm. I was not sure it would work but by heating a bit my moving plate it does detect it wellNow about your last answer:- I had in mind the relay bouncing and the long key press (due to the relay staying closed for a while) but this can be easily handled software side. I will just activate a flag in the software at the begining of the detection signal and then ignore the rest.- You tell me the PIR alarm output won't drive the relay directly because it goes through resistors. That's precisely what I was wondering, what components this output could go through that could be damaged by the current for the relay. Though, as said in the edit at the end of my previous post, I have tried and it works. Do you think I could damage the PIR alarm circuit if I continue like this ?- Replacing the PIR alarm relay with mine: I had not thought about that (didn't even new the alarm had a relay before you tell me). But couldn't this damage the alarm circuit as my relay should need more current than the original one ?- Cascading the original relay with mine (with a transistor driving my relay): this could be an option if you think driving it with the alarm output as I currently do is not safe for the alarm circuit. That's basicaly what I was trying to do initially by pluging at the led pins of the alarm (but of course pluging at the alarm relay is a better idea).- Using an opto-isolator: I love that idea. A concern I had when the idea of contactless entry detection came in was to electrically separate the detection circuit from the mouse connected to the computer, as hurting the computer is the last thing I want to do ofc^^ Due to my limited knowledge in electronic I sticked to the first thing that came to my mind, which was the relay. Opto-isolator could be a great replacement especially since it seems fast and latency is a concern for my measurements.Currently I cumulate the latency of both relays (+ possible latency of the rest of the PIR alarm circuit). Now, as long as the relay latencies remain constant I could still compensate it by moving the detection point a bit ahead of the tunnel entry (which I already do a bit as you can see on the pictures). The only issue with this compensation will be that from one fan testing to another (so, different airflow), the speed of the moving plate at entry point of the tunnel will be different (the plate starts to be sucked in at approx 10cm of the tunnel entrance, so it arrives at tunnel entrance with high speed already, making also the detection a bit tricky with the PIR alarm. Improving sensivity would help), which means I should have to re-tune the position of the PIR alarm for each different fan. This means the less latency at the detection circuit, the more the PIR alarm can stay at the same position for various fan tests, which would better for reliability as the test conditions would remain the same, which is always better I think.Atm, the entry detection is not that bad (see attached animated gif, but this is a best case. Although I managed to have the same accuracy several times over a few tries), but not good enough to only rely on the PIR alarm detection. If I cannot improve the detection system I will have to double check using video recording (frame by frame analysis of 60fps record) to only validate the measures where the plate entry was detected correctly by the sensor. I think I will still do this double check anyway, even if I managed to improve the sensor detection accuracy, but with better accuracy I would have more valid tests to average the result of.I have attached a small animated gif to the post (idk if the forum will dislplay it animated though) of a 60fps record of the current detection. Being a 60fps record, each frame represents 16.6ms. But as you can see accuracy is better as you can see the ghost of the moving plate during the whole frame exposure, which mean you know the position at the begining and the end of each recorded frame. As you can see the end postion at frame i is also very close of the begining position of frame i+1, which mean accuracy for those start/end positions should be around a very few milliseconds, despite the 16.6ms length for each recorded frame.That was a bit long answer sorry. I hope some people still may find this stuff interesting if they need to compare fans airflow too, which from my various experiments is not easy task to get reliable results. Any idea to improve entry point detection is very welcome ofc

author: neel
author_rank: Contributor
timestamp: April 02, 2014, 06:38:36 pm
content: So I began testing the airflow bench in benching situation.While trying several positions for the PIR sensor I managed to have this not that bad serie of measurements:Test 06 --> 132.915 msTest 07 --> 129.896 msTest 08 --> 142.902 msTest 09 --> 124.916 msThat sounds promising repeatability-wise, the average measurement being 132.657ms the most off value is only 8% off from average, and this was even without double checking the PIR detection with a video record analysis.Now I'm not really satisfied with the PIR detection of the moving plate at entrance of the tunnel. Despite having a tube cache to narrow the PIR sensor field of view (see picture in previous post) I get lot of false positive detections, or at the opposite no detection of the plate passing by the sensor despite heating it up to make it easier to detect. And being a plastic plate, heating it up makes it blend, not very welcome.So idk if I should try to improve the PIR detection system (I have tried to make a small lens by cutting a plastic CD case in a half circle but detection result was terrible), or go back to my initial idea of detecting the plate mechanicaly using very light contactors, or try something else.I had another idea I have not explored yet that was to use the IR sensors you can find in old mouse with a ball (those sensors at the encoder wheels. I already used one to make a RPM meter with a software analyzing the sensor signal plugged to the soundcard).I also have small photovoltaic panels that I saw on youtube someone was doing a detector with, using a laser pointing at it. That would certainly be very precise and probably perfectly fitting my needs, but I have no laser flashlightIf someone has any idea or comment I'm open to suggestionsIn the meantime I'm going to continue trying other positions and FOV cache for the PIR sensor to see if I can make the detection more reliable.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: April 02, 2014, 06:50:47 pm
content: So,Your putting your disk into the tube and then turning on the fan ?Then timing how long it gets to travel so far along the tube suspended on the wire ?Is that correct ?

author: neel
author_rank: Contributor
timestamp: April 02, 2014, 07:01:28 pm
content: Yes, but I put the fan ON before approching the disk to the tunnel entrance so that the fan get to its nominal RPM before starting measurement. With the airflow, at a few centimeters of the tunnel entrance the disk is sucked in and I measure the travel time.I just thought maybe I could use the sensor of a computer mouse. It may be precise enough to detect the disk passing by very well if I manage to make the mouse sensor close enough of the disk. Then I would just have to monitor mouse mouvement in the time meter software to trigger the start of the timer.

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: April 02, 2014, 07:06:05 pm
content: How far does the disk travel, is it a fixed distance, is it from the outside to the inside of the tube ?

author: neel
author_rank: Contributor
timestamp: April 02, 2014, 07:28:51 pm
content: Ofc it is a fixed distance... as long as you manage to get an accurate detection of when the disk pass by the tunnel entranceThis is the problem I'm try to solve.Monitoring the end of travel accurately is easy but at tunnel entrance it is a bit more difficult.Also as you can see typical travel time should be below 200ms, which means I need to get the best accuracy for the starting point detection. With a video recording analysis, being able to make a 60fps recording at best, but the "ghost" of the moving disk during frame exposure being visible, I would get a few millisecond accuracy (below 5ms I'd say). But this kind of detection would make difficult to have an automatic measuring bench, it would require a frame by frame video analysis done by hand for each test, which is laborious if you need to repeat the test a lot of time.Hence why I'm trying to find any electronic way to detect precisely (a few millisconds) when the disk pass the tunnel entrance. That way my software receive a start/stop signal and I can easily repeat the test of lot of times (to average values for a better accuracy, and doing this for the various fans I want to compare between each others).

author: Mr Smiley
author_rank: Frequent Contributor
timestamp: April 02, 2014, 08:21:37 pm
content: Do you have access to a hall effect sensor. you can find them on old pc fans or those cheep door open alarms ( though some use reed switches, not fast enough for this though ) place a small magnet on the rim of your disk, the weight will cause the magnet to sit at the bottom, unless the travel causes it to spin. One sensor at start and end of travel.Also if the led and receiver from the mouse are separate you could angle them at 45', place them at the entrance of the tunnel, paint the rim of the disk white, feed the output of the sensor through a cap so you just get the reflected pulse from the edge of the passing disk.Or, if you have some very fine flexible strand cable, glue the 45' opto sensor to the disk pointing at the support string, put a thin black band on the string at the start or your timing and a thin black band at the end of your timing and you will get a pulse as it passes the first mark and a pulse as it passes the second mark.You don't need a laser for everything, it's only advantage is it is a thin specular source. An alternative is a led in a drinking straw, and a sensor in another drinking straw, point them at each other and you'll have a defined field of detection.There are actually quite a few solutions, and i think the PIR one is the worst because of the uncertainty’s it gives.

author: neel
author_rank: Contributor
timestamp: April 02, 2014, 08:51:18 pm
content: Hehe lot of new ideasI also thought about hall sensor. I have one but in an expensive product I won't salvageI didn't knew we could find them in old fans too (to monitor RPM I guess ?).Monitoring at the string is an option I considered too. The cylindric guide holding the disk on it is metalic so I imagined adding thin wires on the string that would close the circuit when the metalic guide pass by. Your suggestion with the opto sensor would be an option tooI will try the mouse sensor and if it doesn't work I'll try the above options, as I agree the PIR sensor is not very reliable, especially when you need a fast and precise detection.Thank you for your help, I will update if I manage to get good results