Phototransistor cable for twilight detection

Go To Last Post
19 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello!

 

I'm using a phototransistor (SFH - 3711) to detect day/night transitions with a simple circuit:

Rss = 1Meg, CL = 100nF.

The phototransistor current is 60uA for 1000lux.

This connects to an ATmega328P ADC pin.

The voltage goes from 0V: total darkness, to Vdd(3V): daylight.

 

The problem here is that  this circuit must be placed 20 cm far from the MCU and with mains and switching power supplies near.

If the cable was only to connect to the phototransistor - Rss and CL would be next to the MCU - the situation would be more sensitive to noise.

 

I can admit 5% to 10% error in the measurement.

 

What cable (shielded, coaxial, ...) and what connection type should I use in such application?

Or I shouldn't worry about it?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Well, I'm no expert, but 20 cm doesn't seem very far. Maybe a few turns of the cable around a ferrite core is enough to block the interference?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why not just put a comparator or schmitt trigger at the sensor end to give you a simple digital signal to the micro ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:

Why not just put a comparator or schmitt trigger at the sensor end to give you a simple digital signal to the micro ... ?

I've thought about that too, bit I need to have hysteresis, some debouncing and also be able to calibrate it. That would be easier to do it in the MCU.

Besides, I don't have too much space in the phototransistor side, so I was trying to avoid adding more electronics to it...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

This is not so good, since the impedance is way too high for the adc ...you need something like 10k...so maybe add a simple opamp buffer.

The adc pin will have a +/bias current that must come from somewhere (the circuit)

 

If the detector is performing like a true current source, it's equiv impedance is infinite (so you just have your 1 meg resistor)

 

Rss and CL would be next to the MCU - the situation would be more sensitive to noise.

I disagree---You can move the cap right to the processor, so it will do a better job of filtering the incoming noise along the line.

 

If you only want to detect whether it is day or night (binary) , you might still be able to live with the setup

 

you might also consider a pin photododiode...or perhaps a photoresistor (though cds cadmium might be banned).

 

Sunrise/sunset takes hours so you have plenty of time to take the average of 100 million samples...probably will filter out any noise you throw at it

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yeah, there is not enough current to feed the sample capacitor for the ADC, unless you wait a long time between samples, so that capacitor CL has time to charge. The time constant is 0.1s, so the cap takes about half second to charge. Probably you shouldn't take more than 1 sample per second. But for this application it's enough, I suppose.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A microamp or 2 of ADC bias current is enough to wreak havoc if you only have 10 to start with...the +/- bias current is magnified by a million if you are using 1 megohm...that means your reading could be  +/-1 volt off

Bias currents can vary wildly with temperature--so don't allow yourself to be fooled into thinking all is well (and then mysteriously it stops working in the winter/summer).

 

something like an LMC series opamp has very low bias  (again, temperature sensitive)

LMC6482 .......Ultra Low Input Current: 20fA    not micro, not nano, not pico.....FEMTO!    ...that's 0.00000002 uA

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

20 cm isn't very far, but as noted above if the noise level is very high putting one of the new Tinies with an ADC right at the sensor and sending the signal digitally would be a good approach, especially if the number of devices being built is small.

 

If you want to Keep It Simple, put a small RC filter at the ADC input, and use a twisted wire pair inside a shield for the connection to the sensor.

 

There are entire papers and App Notes written on the science of optimally grounding shields.

I'd be inclined to leave the shield unconnected at the sensor, and connect it to Ground at the PCB end near the ADC's LPF.

 

Day / night isn't usually an exact science when using an optical sensor.

 

I'd, as suggested above, take a fair number of samples before making any decision based thereupon.

 

JC 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Having the capacitor greatly reduces the need for 10K or less source resistance. The whole reason for that (10K max source resistance) is so that the input voltage won't "sag" while the sample/hold cap (inside the ADC input) is being charged. With the cap, there, there is a big charge storage that will absorb the the effect of charging the 10pf or so (guess) S/H C.

 

I would add a second cap (another 100nf  should  do) close to the ADC input.

 

And, yes, 20cm is not very long (8 inches for us non-metric folks) but it is certainly enough to be subject to stray coupling including mains. I would use, at the very least, a twisted pair. Shield does not protect you from magnetic coupling, much, but it won't hurt and could reduce other stray couplings.

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

Last Edited: Fri. Apr 7, 2017 - 07:23 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm using a simple LDR w. 15m twisted phonecable, and have no problems.

Triggering via AIN

 

/Bingo

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

El Tangas wrote:

Yeah, there is not enough current to feed the sample capacitor for the ADC, unless you wait a long time between samples, so that capacitor CL has time to charge. The time constant is 0.1s, so the cap takes about half second to charge. Probably you shouldn't take more than 1 sample per second. But for this application it's enough, I suppose.

That's right, there's no hurry for this kind of measurement.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ka7ehk wrote:

Having the capacitor greatly reduces the need for 10K or less source resistance...

Jim

Yes, I'm using the capacitor to avoid that problem. I guess the 10k or less, is for impedance, so the capacitor will do the trick.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Using this 20 cm (8 in) cable, should I put a small resistor - 10R - in series next to ADC input?

Something like this:

 

3V----PH-T-----+--------------+------+                     +------10R-------+------------ADC pin

                       |                  |          \                    /                         |

                    1MR            100nF       CABLE(UTP)                       100nF

                       |                  |          /                    \                         |

GND-------------+-------------+------+                      +------------------+-----------GND

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A daylight/dusk or dawn/daylight event is something that happens pretty slowly, seconds if not minutes, so a low freq low pass filter using h/w or done in software should handle any high frequency noise you encounter quite well.  And as stated above, you will need to add an opamp to drive your ADC input properly. 

Another possibility, use a fiber optic light pipe to bring the daylight to the photo sensor placed near the mpu!

Good luck with the project.

 

Jim

 

 

 

 

 

 

Last Edited: Mon. Apr 10, 2017 - 01:18 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

ki0bk wrote:
A daylight/dusk or dawn/daylight event is something that happens pretty slowly,

I was wondering about the "accuracy" requirement stated earlier.

 

I guess if it were me, I'd calibrate in strong moonlight to avoid that false hit.  And also calibrate in full cloud/rainstorm to avoid that false hit.

 

Perhaps with an "accuracy" requirement it is a trickier proposition than e.g. sun tracking.  I remember outdoor floodlights with a sensor that would turn on during a gray day period, and turn off in strong moonlight.

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The varying leakage currents through the pin must be accounted for in your accuracy distribution.  If the ADC pin has a 0.5 uA  DC variance in leakage (say over temperature)...that 0.5 uA will be multiplied by your 1meg resistor in parallel with the phototransistor output impedance, giving a change.  If the variance is small, it will be calibrated out when you do your initial cal.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

The varying leakage currents through the pin must be accounted for in your accuracy distribution.  If the ADC pin has a 0.5 uA  DC variance in leakage (say over temperature)...that 0.5 uA will be multiplied by your 1meg resistor in parallel with the phototransistor output impedance, giving a change.  If the variance is small, it will be calibrated out when you do your initial cal.

You're right, I must use an opamp to prevent the leakage from MCU ADC from interfering with the measuring.

 

That said, if I want to put the phototransistor alone remotely and the opamp circuitry next to the MCU, what are the cable requirements?

Shielded Twisted Pair (STP)?

Like this, grounding only the MCU side cable shield?

 

     C                              --------------------- ... ------------------                                  |

   /    \----------------------\                                                     \--------------------------| OPAMP circuitry

B                                    )             STP cable                         )                                |

   \    /----------------------/                                                     /--------------

     E                              --------------------- ... ------------------                  \--GND

PhotoTransistor                                                                \--GND

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You probably don't need shielding, since you have minutes of filtering time available at the opamp (a big cap there gives a lot of averaging)...you don't want a bunch of "strong" noise going into the opamp where it might become rectified.  In the micro you can further filter/avg your samples.

 

http://www.kennethkuhn.com/students/ee431/phototransistors.pdf    not in fig 4, VR is a negative voltage, since the servo point  (- & + input terminals) must swing around zero 

 

Note, instead of an opamp, you might get away with adding a darlington  transistor config ....this extra gain greatly reduces the circuit output impedance

http://mech.vub.ac.be/teaching/info/mechatronica/finished_projects_2009/groep1/images/SFH%20303%20elektrisch%20schema.PNG

 

 

some other generally worthwhile info:

http://www.nutsvolts.com/magazine/article/light-sensitive-circuits

 

 

 

 

 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

avrcandies wrote:

some other generally worthwhile info:

http://www.nutsvolts.com/magazine/article/light-sensitive-circuits

I might use the circuit in Figure 14.d with an opamp in unity gain.