I need some help with a project.  - Page 1
Forum section: electronics / beginners

author: cvriv
author_rank: Frequent Contributor
timestamp: February 25, 2020, 09:43:31 am
content: I'm basically trying to create on of those interactive surfaces using IR sensors and LEDs. I actually built a prototype and wrote all the code. It didn't work and I'm not all that surprised.It's not the code that's troubling me, it's the hardware. This is what I originally designed:Each element of the matrix is a cluster of 3 x 5mm diodes; 1 x blue LED, 1 x IR diode (TX), and 1 x RX diode. Each row goes high to provide 5v for the LED, TX, and RX. There are two sets of 4 x columns, the first set of 4 x columns go low for the LED and TX. The second set of 4 x columns, each goes to an analog input for the RX. All of this is networked with a PIC16F883 running at 8Mhz.The way I'm expecting this to work, in short, is that when a polled IR sensor sees something, the associated blue LED turns on. The closer that something is to the sensor, the longer that associated LED is on. The longer that LED is on, the brighter it is.Now, everything technically works, it's just not working properly. When I was stepping the code (Assembly), MPLAB IDE v8.92, in simulation and debug mode, everything worked exactly the way I expected.The assembly basically has the MCU polling each RX twice for a final ADC value, once with the TX on and once with the TX off. The ADC value with the TX off is subtracted from the ADC value with the TX on. I'm hoping this will remove most of the ambient light seen by the RX, but if it doesn't that'll be an issue to deal with another time. The final ADC value is basically a multiplier or counter of how many times to check if the LED should be turned off. (ADC value) x (13 500ns instructions) = (LED pulse-width).It wasn't until I stepped the code in debug mode that I noticed that the ADC value with the TX on was pretty much the same as the ADC value with the TX off. After the subtraction I was basically left with no pulse-width at all, so none of the LEDs would turn on. Every once in a while I would land a pulse-width of no more than 1, and that LED would turn on for 13 500ns instructions, which are the instructions used to check if the LED should be turned off and if so turn it off.I found out that I was basically not capturing any IR light from the TX diode. That's when I learned that 5mm IR diodes operate at about 100mA. That's a lot more than I thought. I dont even know what I was thinking before now. That's way more than what the MCU can handle and I don't even know what they were running at before now, because I had 150 Ohm resistors in series with them and they were being pulsed.So this is where I'm at now... I have been messing around with switching one of the IR diodes on and off with a 2N3904 transistor. I was cooking the transistor at first but now everything runs without heating up. Im using a signal generator to provide a pulse train with 44us pulses at 5Vpp (0 - 5V) within a period of 16ms (60Hz). This pulse train with a series resistor switches the transistor on and off. The IR diode is connected directly to a 5V DC source and the collector. The emitter goes straight to ground. I setup the RX diode, as well, with a 4.7MOhm resistor going to ground. I connected my oscilloscope probe across the base-emitter PN junction and another across the 4.7MOhm resistor, associated with the RX diode, so I could watch the voltage rise.I was seeing some decent responsiveness with a voltage curve of less than 1V (nothing over the sensor) to a curve as high as 4V with my finger right on it. The curve looked weird though. Some how the pulse train was screwing with the RX voltage curve. The pulses were tied to the same ground as the DC source. I actually grounded them separately and the curve was beautiful, but I wouldn't know how to do that for the real thing so I reverted back to shared ground.Anyways, while the switching circuit was running I noticed that the PSU was showing me that no current was being pulled, or so little that I was seeing 0Amps and 0Watts. This I don't understand. I know it probably has something to do with the switching. I was seeing good responsiveness, which means the TX diode, as well as the RX diode, is working, yet no current? This is probably why nothing is heating up. Can someone explain this to me? How do I know how much current is flowing through something like that TX diode when being pulsed? Could I use a current meter in series?Assuming that the TX diodes are pulling the appropriate current, how can I switch all the TX diodes on and off like this? I thought that all I would need is 4 transistors, one for each column, but then realized that I can't ground the emitters to the MCU pins because of the current overload. The emitters would have to go straight to ground, but that would mean that each TX would need it's own transistor and each transistor would need it's own MCU pin. That sucks. What are my options here? I'm looking to try and keep this as simple as possible. No Arduinos.Thanks.

author: rstofer
author_rank: Super Contributor
timestamp: February 25, 2020, 10:55:03 pm
content: 44 us on time in 16 ms is only 0.275% on time. You should be able to draw out how much on time you have for the whole system and see if it would even be measurable. A DMM probably won't see it, the conversion time is too long. You might be able to see it on a scope by taking a differential measurement across some resistor in the path. Two channels, no ground clips, select MATH X-Y or MATH X+Y and Invert Y.You should probably post links to the datasheets. Somebody may be able to spot a 'gotcha'.

author: cvriv
author_rank: Frequent Contributor
timestamp: February 26, 2020, 06:42:03 am
content: Ok. I'm going tinker around with it some more, most likely this weekend though. I'll post my findings, I'm not going to kill myself trying to find out what the current is. I'm short on time seeing this is a project for school.I purchased some PIC16F884s to ise instead of the 883, because the 884 has more ports. I can dedicate two ports for switchng the transistors on and off.