HOME


make use of Nutchip's analogic comparator

An intelligent photocell

Electronic eye | Basic schematic (1) | Adding histeresys | Breadboarding
Circuit evolution (2) | Braincells for photocells

Electronic eye

A photocell or light barrier is a useful circuit with a myriad of applications. Its electronic eye can switch porch lights on at dusk, hall lights when people traverse it, and even control car lights when entering tunnels. It can be used to detect presence of objects, like a car entering a garage or a park area, or to detect if a flame burns, and even to detect wheter a clear label is applied on a dark product or not, by carefully adjusting its trigger level. Industrial uses of optical detector include surprising applications, like selecting single rice beans or discarding burnt potato chips according to how much light they reflect.

Nutchips interface nicely to Light Dependant Resistors (LDR), the hear of many light barriers; Nutchip's brain adds the logic necessary to implement a variety of automation tasks, with very few other parts. Your fantasy is the limit: for instance, why not to design a burglar deterrent that switchs automatically the kitchen's light at dusk (no need for boring time setting, just keep an eye on ambient light to detect when dusk arrives!), then after an hour or so the dining room, and later the bedroom, just like humans do? Let's learn how to do this kind of tasks with a Nutchip!


1) Basic schematic

The basic schematic of the photocells makes use of the analog comparator input of the Nutchip. This special input shares the same input as IN4, and must therefore be explicitly enabled checking the respective box in Nutstation prior to programming the chip.

The analog comparator works comparing the Volts applied to input IN4 to the Volts applied to the AREF pin. If the potential on IN4 is greater than the potential on AREF, the the input IN4 appears to be at logic level 1; otherwise the pin behavel like a logic level zero.

For instance, imagine to set trimmer TR1 in order to give 2 Volts to pin AREF, while at the same time the ambient light makes the LDR to measure exactly 1 kiloohm. Since the LDR and R2 have the same resistance, the pin IN4 will get one half of the power supply potential, that is 5V / 2  = 2.5V. The Nutchip will then see input IN4 at logic level 1, because IN4=2.5V is greater than AREF=2V.

Whati if the LDR gets obscured? In such condition the LDR can easily get to 10 kiloohms and more, therefore the potential on pin IN4 will get well below the 2V threshold set by the AREF pin: the input will assume logic level zero.

photocell_exp.gif (7436 byte)

This photocell work well in the laboratory. When the LDR gets dark, the LED lights.

Try testing this schematic on a breadboard. In practice you will find easier setting the trimmer TR1 to adapt to ambinet light in place of the fixed setting of 2V described above. To find the best setting point for your environment, first measure how many volts are normally present on pin IN4 (be sure not to obscure the LDR doing this), then set TR1 to give something less on pin AREF. The closer the two voltages, the higher the sensitivity. When the two values are too close, circuit operation becomes tricky, as the slightest variation in luiminosity can change the circuit's output (including the light coming from its own LED...).

 

Adding hysteresis

Sometimes sensitivity is just too much. For instance, if you use the circuit to drive the garden lights, you don't want the circuit to react to a cloudy day! Even worse, you don't want the circuit continuosly switching on and off, as it might happen if the LDR receives some of the lights form the garden.

This is a behaviour common to most automatic control: you want to control the working point precisely, but once the device triggers you don't want the circuit to switch off again unless the variation from the setting point is significant. The usual way to work this out is adding hysteresis to the circuit.

To clarify with an example, you can set your photocell to maximum sensitivity, but once it triggers you can reduce the sensitivity changing the threshold level. In the case of a light activated switch, you can set the trigger point such that the lights operate early in the evening; after that, you may require to have a much greater illumination to turn it off again. This is the so-called level hysteresis, because it changes the threshold level that operates the device. One of the ways it can be done is by adding resistors between inputsa nd outputs.
When working with Nutchips, a more convenient way requiring no additional parts is to introduce a time hysteresis. If our ultimate goal is to avoid the circuit going on and off repeatedly as long as the ambient luminosity is around the trigger point, we can solve the problem keeping the output activated for an interval long enough for ambient luminosity do settle. For instance, if you can require that the output stays activated for at least half an hour before being controlled again by the LDR, allowing enough time at dusk for the ambient light to move away from the threshold point. The same rule can apply at sunrise; adding such timers to a Nutchip is just a click away!

 

Breadboarding

The basic circuit requires just a few parts, that can be assembled easily on a solderless breadboard. The photo below shows how we arranged our prototype

Photocell.jpg (22768 byte)

how to place theparts on a solderless breadboard

Parts lilst:

  • 1 x LED (red or any other color except white or blue)
  • 1 x 390 ohm resistor
  • 1 x 1000 ohm resistor
  • 1 x 100 kiloohm potentiometer (multiple turns trimmers are preferable)
  • 1 x cond. 100 nF = 0.1 uF
  • 1 x light dependant resistor (LDR), actual model isn't critical
  • 1 x 4 MHz ceramic resonator, 3-pin version
  • 1 Nutchip

 

2) Circuit Evolution

After you played around with the basic circuit for some time, it's time to dress it for its first day out of the lab. Photocells are expected to work for month without interruption, therefore reliability is a mandatory requisite. When a circuit works for long time, a power outage or a reduced power condition must be taken in account. To cope with them wee added a reset delay network (R3 and C2). You can also add a specilized reset IC like the MC34064 to the RESET pin.

Another annoyance that real life circuit must cope with is the electrical noise coming from other devices or from power lines. Additional noise can be captured by wire harnesses. Noise can find its way to the inputs and cause them to trigger. We added capacitors C3 and C4 to sink high frequency noise spikes to ground (capacitors exibit low impedance to spikes, but don't affect slow-changing signal like those coming from the LDR).

A LED is great for the lab, but to drive real-life charges a relay is more effective. When buying your relay, remember to ask for a device suitable for the final use, and remember to add a generous overload margin: for instance, a 100W lamp can get up to 1000W during its power-up, and your relay must withstand it. A rule of thunb is to double (at least) the continuos current required by your load.

I rel่ da 5 volt (come quelli utilizzati qui) sono comodi, ma talvolta sono difficili da reperire per le correnti maggiori: potete sempre modificare lo stadio di uscita per pilotare un rel่ a 12 volt, come indicato nella raccolta di circuiti base.
Queste protezioni basteranno per un utilizzo "casalingo" della nostra fotocellula.

photocell_pro.gif (9469 byte)

The improved version of the light-activated switch:

  • A relay is added to the LED. Note that its logic behaviour is reversed compared to previous circuit, so you need to reverse all zeroes with ones in the truth table's outputs.
  • The reset pin features it own delay circuit.
  • The analog inputs are filtered agains noise by means of capacitors C3 e C4.

 

Use the brain

The most intriguing feature of this photocell is it programmability, which is not usually available with standaard projects.
Here are a few application ideas: