Wednesday 10 September 2014

How to design a simple light dark detector

In order to write a tutorial for showing people how to use Eagle I needed a simple circuit to discuss.  I decided on a simple light dark detector using a light dependent resistor (LDR) and an LED.  This post discusses how we go about designing the circuit and which components we might choose to use.

If we want to detect light levels we need a suitable transducer (sensing device) which takes the real world signal we wish to measure (light) and converts it to electrical energy.  One such device for doing this is called a light dependent resistor or LDR.  

The wikipedia entry for LDR sensors is here: Photoresistor or LDR

The device basically changes it's electrical resistance when the light level applied to it varies.  If we have an LDR and combine that with a resistor we can make up a simple voltage divider.  We can then use the output of the voltage divider to change the state of a transistor from OFF to ON.  We can then use that change of state to turn a further transistor from OFF to ON and that controls whether an LED is biased on or off.  


The diagram above (a truly awesome piece of sketching) shows the way the electronic components are to be connected together in order to achieve the light dark detection and LED illumination we require.  The picture uses agreed symbols to denote the different electronic components and the amount of voltage that is applied to each component.  From this diagram we have all of the information we need in order to prototype the circuit and check the function.  The symbols used are defined below.  There are several different symbols for electronic components and variants...


There are many electronic components with specific symbols and some of those are available for viewing in the link below:

Electronic component symbols

The circuit works as follows: An absence of light present on the surface of the light dependent resistor (LDR) changes it's resistance value.  This change in resistance turns the first NPN transistor on, that then turns the second transistor on which turns the LED on.  The 330 Ohm resistor below the LDR makes up a voltage divider which ensures that when the LDR changes resistance, at least 0.7V is applied to the base of the first transistor.  The second 1k (1000) Ohm resistor limits the current going into the base of the second transistor.  The third resistor is a current limiting resistor for the LED - it prevents too much current flowing into the LED and sets the LED brightness.

If we look at the schematic diagram above we have decided to run our circuit on 6V. The components present are three resistors, two NPN transistors an Light emitting diode (LED) and a light dependent resistor (LDR).  The values of the components have been assigned after being calculated using mathematics and Ohms Law.  We work out the voltage and current present in each part of the circuit and use that to check that the function is correct...

I normally simulate all my circuits so that I don't have to calculate current draw and it also proves the circuit will work - I know this circuit works because this is one of the first circuits I ever made!

However if we use Ohms law and apply circuit theorems (Kirchoff's current law) we can calculate total circuit current and then we know how much power each component has flowing through it and then we can choose the type of component - power rating and footprint and tolerance.

This is important stuff - we need to make sure that the components we use don't get hot and damage themselves in normal use.  The circuit simulator is useful because it calculates all of this automatically.

We know the resistors present in the circuit but I didn't include the value for the LDR, lets set the resistance of the LDR at 10k Ohms maximum.

LEDS don't have a fixed resistance, they have a forward voltage drop and a fixed current draw.  Normally the forward voltage drop of a Red LED is 2 V.  We need to apply a version of Ohms law applied to the diode volt-drop to calculate the current flowing through the LED.  We also need to take the transistors into account finally, Transistors have a volt-drop at the base of 0.7 V. Now that we have all of that information we can calculate the total circuit current....this gets really complicated and involves a lot of simple mathematics and because I'm lazy I use a circuit simulator...Eagle does have an LT spice plugin which is a circuit simulator...more on this later.

Here is a datasheet for a standard 5mm LED - led datasheet

Here is the datasheet for the BC548 transistor - BC548 datasheet

We will need this information for our calculations and for later...

Circuit analysis is at the core of electronics design....it's much better to understand the physics and mathematics involved so that then we can make good decisions and even better gadgets!

We need to make this circuit easier to understand, let's redraw the circuit and split the circuit into sections or branches:

For the curent flowing in Branch 3:

Using Ohm's law, we can calculate the current flowing through the 330 Ohm resistor and the LED:
I=VRR

VR
VR
V=  Vs - Vd
Vs (supply voltage) = 6 V
Vd (LED Volt-drop) = 2 V
Applying those numbers give:
VR = 6 V - 2 V 
VR = 4 V
If we then find the current I:
VR = 4 V
R = 330 Ohms
I = 4 V / 330 Ohms
I = 0.012 A or 12 mA
Let's plug some numbers in. Say VS = 6 V, R = 330 Ohms, Vd = 2 V (a typical red LED).
VR
In the branch three part of the circuit with the 330 Ohm Resistor and the LED we have 12 mA of current flowing.

In the second branch of the circuit we have a 1000 Ohm resistor and a BC548 transistor.  The voltage applied to the base of the second BC548 transistor in order to turn it on is 0.7 V.  It's the same for any bipolar transistor.  If we apply the same calculations as before we can calculate the current flowing in this branch of the circuit:

I=VRR

VR
VR
V=  Vs - Vd
Vs (supply voltage) = 6 V
Vd (Transistor base Volt-drop) = 0.7 V
VR = 6 V - 0.7 V 
VR = 5.3 V
If we then find the current I:
VR = 5.3 V
R = 1000 Ohms
I = 5.3 V / 1000 Ohms
I = 0.0053 A or 5.3 mA
The current flowing in the second branch of the circuit is 5.3 mA

Finally we can calculate current flowing in the first branch of the circuit using standard Ohms law:

R1 = 330 Ohms
LDR = 10k Ohms or 10,000 Ohms

Total resistance = R1 + LDR

Total resistance = 330 + 10000

Total resistance = 10330 Ohms

Ohms Law: Voltage (volts) / Total resistance (Ohms) = Current (Amps)

Voltage = 6 V
Total resistance = 10330 Ohms

Current = 6 V / 10330 Ohms
Current = 0.00580 or 580 microAmps flowing in branch 1 of the circuit.


Next we can apply Kirchoffs current law and calculate the total circuit current.  If we add all of the currents flowing in each circuit branch together we get the total circuit current:

Total current = 0.580 mA + 5.3 mA + 12 mA
Total current = 0.01788 A or 17.88 mA

The total circuit current draw is 17.88 mA

Power consumption is another part of Ohms law and is found using the following formula:

Power (Watts) = Volts x Amps

Power (Watts) = 6 V x 0.01788

Power (Watts) = 0.10728 Watts or 107 mW

So from that we know that every component in the circuit must be capable of withstanding 107 mW of power flowing through them.

This information then allows us to choose the types of components we could use to physically build our circuit.  There are many different versions of electronic components with different characteristics and properties.  Lets choose ones which have the values we require or perform the function we want whilst still being able to withstand the 107 mW of power dissipated in them...

That's all for this post.  I'm going to talk about designing a PCB in eagle for this circuit in the next post:

That's all for now....Take care - Langster!

No comments :

Post a Comment