An ambient light meter

For our first example using analog inputs, I'd propose that you build an ambient light meter: a device that indicates the amount of ambient light it can sense from its environment in some way and shows it in a visual manner, which is a perfect beginning for your next burglar detector.

For the purpose of this example, we will use a very interesting electronic device called a photocell or light-dependent resistor. A photocell is simply a specific type of resistor that varies the resistance it offers according to the amount of light it receives from its environment, exhibiting a photoconductive behavior, that is, lowering its resistance as the light increases and vice versa, commonly ranging between a few ohms when exposed to a bright light and up to some mega ohms when totally in darkness.

In the following picture, you can see a typical photocell and the usual schematic symbols you can find to refer to it:

An ambient light meter

A real photocell and its most common schematic symbols

Unlike any other resistor, a photocell doesn't have a polarity, which means that you don't have to observe the way you connect it in your circuit. It does its job equally in one way or the other, but being a variable device it makes us give some considerations when connecting it to our Arduino board.

Connecting a variable resistor to Arduino

As mentioned previously, a photocell can decrease its internal resistance up to only a few ohms when exposed to a bright light and theoretically, it could even reduce it to zero when in the presence of a very bright light; in this case, it acts like just a simple wire with 0 ohms resistance.

With this in mind, we need to modify our circuit to prevent a short circuit in case this situation arrives.

Given that connecting variable resistors as analog input sensors to Arduino is a very common case, let's see a simple circuit that will ensure we will never damage the Arduino board.

A general variable resistor circuit to connect to Arduino can be like what is shown in the following diagram:

Connecting a variable resistor to Arduino

A typical circuit to connect a variable resistor to an Arduino analog input

As you can see, in some way, the circuit is very similar to the one used when connecting a digital input to Arduino. It also uses a 10K ohm load resistor to prevent a short circuit in case the photocell internal resistance decreases down to zero.

This is not a typical situation but it could happen, especially when connecting other types of variable resistors.

Voltage divider

This kind of circuit is commonly known in electronic jargon as a voltage divider, because it splits the provided voltage in two steps according to the proportion of the value of the first resistor to the other. We should keep this in mind when selecting the resistance we are going to use as protection.

We should always try to select a protection resistor of a value lower than the main variable resistor; this way, the main voltage drop will be placed just in the variable resistor acting as a sensor, that is, the photocell in our case.

This way, we allow Arduino to sense what is happening in the variable resistor with greater precision and use only the load resistor as protection.

In Chapter 8, Communicating with Others, we will revisit this special circuit to test and try different load resistor values, but for the moment, let's leave aside the theory and begin to work hands on with our next project: a device to measure the light surrounding Arduino.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset