Turning an Analog Sensor into a Digital Sensor

advertisement
Winkler, Envision Art 01, Workshop 05, p.1
Envision Art 01: the responsive screen
Prof. Fabian Winkler
Spring 2007
Workshop 04
Turning the output of an analog sensor into a digital output
There are quite a few ways to electronically turn the output of an analog sensor, say a
photocell, into a digital output. In the following workshop I will focus on one of the
simplest solutions, using a transistor.
First a little recap of workshop 01 – a transistor is an electronic component that can be
used as an electronically operated switch. It has three contacts: the emitter (E), base (B)
and collector (C). A very small current on the transistor's base can control a much larger
current flowing through a passage between collector and emitter. The following drawing
shows the concept behind an NPN transistor using a water analogy (I found it in my old
Kosmos "Electronic Junior" book from Germany). If there is no water flowing down the
base channel, the gate between the collector and the emitter channel is closed, no water
can flow from the collector to the emitter. If there is water flowing down the base
channel it lifts the gate that normally blocks the collector/emitter channel. Once this
gate is open, water flows from the collector to the emitter.
We will use an NPN transistor which opens the collector/emitter channel when a small
current is present at the transistor’s base (remember that PNP transistors work in the
opposite way: when the transistor’s base is pulled to GND, it opens the collector/emitter
channel). The pin-out of this part is as follows:
Winkler, Envision Art 01, Workshop 05, p.2
In the following example, I use a standard PN2222 general purpose NPN transistor to
turn a photocell into a digital sensor. I will be working with a simple voltage divider
circuit connected to the transistor to set a threshold (i.e. specific light level/brightness)
for the transistor’s ON/OFF switching. For this, we need to keep in mind that the
base/emitter Junction will not conduct (i.e. open the collector/emitter channel) until the
forward voltage exceeds 0.6V. This means that the voltage divider circuit’s output on
the transistor’s gate needs to be at least 0.6V for the transistor to open the
collector/emitter channel. We could calculate the exact resistance needed but instead we
will just use a potentiometer as the voltage divider circuit’s R2 so that we can easily and
quickly change the sensor’s threshold.
Recap voltage divider circuit from workshop 02:
We will build the following circuit:
Winkler, Envision Art 01, Workshop 05, p.3
What is happening in this circuit? First of all, increasing brightness changes the
resistance of the photoresistor (the brighter it gets, the less the resistance) – you can
measure this with the multimeter. The less resistance the photoresistor (i.e. R1 ) has the
greater the voltage at the transistor’s base (based on the behavior of the voltage divider
circuit formed by the photoresistor and the potentiometer). If the voltage at the
transistor’s base exceeds 0.6V then electrons can flow from +5V through the current
limiting 1KΩ resistor and through the collector/emitter channel into the Arduion’s input
pin, pulling it high. If the voltage at the transistor’s base is less than 0.6V, electrons
cannot flow from the collector to the emitter and the Arduino’s digital input pin is pulled
low (to GND).
In order to fine-tune this circuit, turn the potentiometer’s knob so long until in darker
light conditions the Arduino input pin is just pulled to GND, then when you increase the
light shining onto the photoresistor only slightly the Arduino’s input pin should be
pulled high.
You can try out the above circuit without using one of the Arduino input pins with a
simple LED like this (remember still to power the circuit with the Arduino board
though!):
Now, after fine-tuning this circuit, the LED should light up whenever light hits the
photoresistor. If you would like to turn off the LED when the brightness increases, just
invert the order of photoresistor and potentiometer on the left side of the circuit.
Download