# Category Archives: Action 7: Arduino make a photoresistor control LED light

In this experiment, we will use a Arduino board to make a controllable LED light, which let LED light bright and/or dark by the strength of light. This experiment is very usable. For example, when night is coming, we should let the street lamp light, and the lamp should be dark in the daytime for the energy saving. So, with respect to this experiment, we can make a light controllable lamp in our home. Similarly, we can also make voice controllable LED light.

# Seg 5: Schematic diagram and experiment of LM35

1. Schematic circuit

By the connection diagram shown in Figure 8-2, this experimental schematics is easily draw in Figure 8-3. Note that, we should design the circuit by the pin connection of temperature sensor.

Figure 8-3 Schematic circuit

8-4 Circuit diagram

1. Code

Run Program 8.

 01 // Program 8: use sensor to measure your environmental temperature 02  03 void setup() { 04   05   Serial.begin(9600);         //set the baud for serial communication 06 } 07   08 void loop() { 09   10   int n = analogRead(A0);    //read the voltage from A0 11   12   float vol = n * (5.0 / 1023.0*100);   //computation of temperature 13   14   Serial.println(vol);                   //output temperature 15   delay(2000);                           //wait for 2s for display 16 }

Open the serial monitor on the Arduino software platform, we can see the Celsius temperature sensed by the temperature sensor LM35. Note that, the baud of monitor should be the same as the above code, which can be seen in Figure 8-5.

Figure 8-5 the temperature value on the Arduino monitor

From Figure 8-5, we know that the environmental temperature is about 24.44 in this experiment.

1. Key points and summaries
2. We should know the features about the temperature sensor. For example, in such experiment, the temperature of LM35 is linearly proportional to the voltage. By this relationship, we can get the formula about the temperature and voltage.
3. We should the connection about the sensor logs. As for LM35 in this experiment, let the full-face having characters facing us. Then the left is connected to 5V port on the Arduino board, the right leg is a GND port, which should connect to the GND port on Arduino board, and the middle leg should connect to the analog port on the Arduino board, which can output the concrete value about temperature.
4. The output temperature value can be seen on the serial monitor. But, the baud for the monitor should be unanimous with the baud set in the experimental code.

# Seg 4: Experimental principle of LM35

1. Experiment and code
1. Experimental principle

The principle of such experiment is very simple. The voltage data is sensed by the temperature sensor LM35, which would be sent to the analog port (A0 is used in this experiment) on the Arduino board. Then the Celsius (Centigrade) temperature can be output by the linear relationship between the voltage and temperature. For example, in this experiment, we know the linear relationship for the temperature LM35 by one Celsius temperature/10mV. Thus, we can get the voltage value n from the analog port A0 connected LM35 on the Arduino board. Not that, the data n is discrete and located on the range of 0~1024. So, we should change the discrete data n into a continuous voltage to get the Celsius temperature. In fact, the computation is simple. We know that, as for the analog ports A0~A5, the value range is 0~1024, and 1024 is corresponding to 5V. Therefore, if we know the value in A0 port, then we can obtain the discrete voltage value within 0~1024; i.e., the value is n. Then, we can compute the Celsius temperature. Assume that the continue voltage in port A0 on Arduino board is denoted by U. Then, we have the following compute formula by the principle A0 and the linear relationship between Celsius temperature and the continuous voltage.

,

where vol is the Celsius temperature we should compute, n can be achieved from analog port A0 on the Arduino. Therefore, we can compute the continuous voltage in A0 by equation (1). Then, we substitute the U into equation (2), the Celsius temperature can thus be obtained. In addition, the value of vol (i.e., Celsius temperature) could display on the serial monitor on the Arduino software platform.

# Seg 3: Diagram of LM35

 model package Temperature range Deposit temperature LM35CZ TO-92 -40℃~+110℃ -60℃~+150℃ LM35CAZ TO-92 -40℃~+110℃ -60℃~+150℃ LM35DZ TO-92 0℃~+100℃ -60℃~+150℃ LM35H TO-46 -55℃~+150℃ -60℃~+180℃ LM35AH TO-46 -55℃~+150℃ -60℃~+180℃ LM35CH TO-46 -40℃~+110℃ -60℃~+180℃ LM25CAH TO-46 -40℃~+110℃ -60℃~+180℃ LM35DH TO-46 0℃~+100℃ -60℃~+180℃ LM35DM SO-8 0℃~+100℃ -65℃~+150℃
1. Parameters and shapes (top view)

1. Mental package (b) molded package

(c) plastic package (d) plastic package

Figure 8-1 Top view of temperature sensor

Limited parameters

 Power voltage Output voltage Output current +35V~0.2V +6V~1.0 100mA

1. Temperature sensor physical shape and connection

Figure 8-2 Physical shape for temperature sensor

Before connected to the circuit, we should know the connection to the pins on the Arduino board for the temperature sensor LM35, seen in Figure 8-2. Firstly, let the full-face (having characters) facing us. Then, the left log is Vcc and should be connected to the 5V port on the Arduino board; the right log is GND, which can be connected to the GND on the Arduino, and the middle one is output voltage, which is connected to the analog port on the Arduino board, A0 is chosen in such experiment.

# Seg 2: Features of temperature sensor LM35

1. Be familiar with temperature sensor

According to the output signal modes, it can be divided into 3 types: digital temperatures, logic output temperature, and analog temperature. In such experiment, the LM35 series sensors is a precise integrated circuit temperature sensor on the development of LM135. Its output voltage is proportional to the centigrade temperature linearly.

Thus the LM35 make interfacing to readout or control circuitry especially easy. The device is used with single power supplies, or with plus and minus supplies. As the LM35 draws only 60 μA from the supply, it has very low self-heating of less than 0.1°C in still air. The LM35 is rated to operate over a −55°C to +150°C temperature range, while the LM35C is rated for a −40°C to +110°C range (−10° with improved accuracy). The LM35 series is available packaged in hermetic TO transistor packages, while the LM35C, LM35CA, and LM35D are also available in the plastic TO-92 transistor package. The LM35D is also available in an 8-lead surface-mount small outline package and a plastic TO-220 package.

Features

Calibrated Directly in Celsius (Centigrade) temperature sensors, with an output voltage linearly

Linear + 10 mV/°C Scale Factor proportional to the Centigrade temperature. Thus the

0.5°C Ensured Accuracy (at +25°C) LM35 has an advantage over linear temperature

Rated for Full −55°C to +150°C Range sensors calibrated in ° Kelvin, as the user is not

Suitable for Remote Applications required to subtract a large constant voltage from the output to obtain convenient Centigrade scaling. The

Low Cost Due to Wafer-Level Trimming LM35 does not require any external calibration or

Operates from 4 to 30 V trimming to provide typical accuracies of ±¼°C at

Less than 60-μA Current Drain room temperature and ±¾°C over a full −55°C to

+150°C temperature range. Low cost is assured by

Low Self-Heating, 0.08°C in Still Air trimming and calibration at the wafer level. The low

Nonlinearity Only ±¼°C Typical output impedance, linear output, and precise inherent

Low Impedance Output, 0.1 W for 1 mA Load calibration of the LM35 make interfacing to readout or control

# Seg 1: how to use Arduino and temperature sensor to measure your environment temperature

8.1 Problem description: how to use Arduino and temperature sensor to measure your environment temperature

Temperature is closely associated with our lives, especially our journeys. In such experiment, we would use temperature sensor on the basis of Arduino board. In the later experiments, we would submit these sensed temperature data to the web server and then process. Then, we can look for many cities’ temperature. In fact, there are many similar sensors, like smoke sensor. The photoresistor is also a sensor in the 7th experiment.

8.2 Hardware and software

The required hardware is relative simple. we can replace the photoresistor by temperature on the 7th experiment, as shown in Table 8-1.

 Table 8-1: The required materials Number Name Quality Function Note 1 Arduino software 1 suit Provide ide New ver 1.05 2 Arduino UNO board 1 Control board Many 3 USB data line 1 Connect board distribution 4 Dupont line 2 Connect elements 5 Temperature sensor 1 Measure temperature 7 Bread board Connection

# Seg 7: Key points and summaries

Figure 7-6 Arduino photon control LED

Figure 7-7 Arduino serial monitor

If we let the outside is much stronger, the value of photoresistor would decrease rapidly. This would let the value of the distribution voltage decreases rapidly, which cannot trigger the Port 8 as a high voltage level on the Arduino board. Therefore, the LED light connected to Port 8 CANNOT be lightened, as seen in Figure 7-8. We can change the strength of the light by using our mobile phone.

Figure 7-8 LED is dark by photoresistor

7.5 Key points and summaries

1) The value of photoresistor would be changed to be small along with the stronger outside light. So the value of voltage is so small that it cannot trigger the Port connected to LED light a high voltage level, which leads LED to be dark.

2) By utilizing the principle of distribution voltage, the photoresistor can control the LED light or dark with Arduino board.

3) Generally speaking, the values of light and dark photoresistor are given out in the product description.

4) Photoresistor is widely applied to the automatic control.

# Seg 6: Experiment and code

Next, we will compute the threshold voltage for the photoresistor by Figure 7-3, where, A0 is denoted by the connection to Arduino board, and the positive end is connected to Port 5V on the Arduino board. Evidently, this is a serial circuit, which shows the principle of distribution voltage. V2 is denoted by the voltage of the photoresistor. By the principle of distribution voltage, we have V2=5V*R2/(R1+R2). We can get the voltage value of photoresistor, which is about 3.34V.

However, we can get the voltage value from the analog Port A0 on Arduino board. Its sentence is analogRead(A0). Note that, the output scope of this sentence is a integer within 0~1024 (which can be referred to the syntax of analogRead()). Thus, we should make the analog voltage 3.34V change into the value with 0~1024. We know that 5V is corresponding to 1024, then 3.34V is corresponding to the value 1024*3.34/5=683. This is the threshold voltage, which will be used in the code to control the LED lighten. In addition, the value of threshold voltage is much higher, the photoresistor is more sensitive to the outside light. Its schematic principle can be shown in Figure 7-5.

Figure 7-5 Arduino photon control LED

We can connect the circuit by Figure 7-5, as shown in 7-6. After Program 7 is run, the LED would be lightened by the weak ourside light (or shelter by hand).

 01 //Program 7：How to photon control light and dark by Arduion 02 int n = 0;    //define n=0 as the read analog port 03 int ledPin8 = 8;   //define ledPin8=8 as the input port 04 int val = 0;       //initialize val 05 void setup() {  06   Serial.begin(9600);//set baud for the serial port 07   pinMode(ledPin8, OUTPUT);  // set ledPin8 as output mode 08 }  09   10 void loop() {  11   val = analogRead(n);  //read value from sensor 12    13   Serial.print(val); //open Arduino monitor 14   Serial.println(); //enter and return 15   if(val<=683){//683=23.34V， 16     digitalWrite(ledPin8, HIGH); //val less than 683(3.34V), lighten led 17   } 18   else{ 19     digitalWrite(ledPin8, LOW); 20   } 21 }

# Seg 5: Experiment and principle

7.4 Experiment and principle

Only when we understand the characteristics, we may feel that the principle of this experiment is very simple, which is simply interpreted as the distribution voltage between the photoresistor and the serial resistor. If the distribution of voltage for the photoresistor is less than a threshold voltage, it can trigger a high voltage level for the port 8 on the Arduino board in such experiment, which can light LED; or port 8 would be at a low voltage level, and thus the LED doesn’t be lightened. But, why should the voltage of photoresistor lower a threshold voltage, the LED would light. Let us analyze its principle. Assume that a photoresistor control lamp would be installed in our home. When the outside light is strong, we hope the lamp doesn’t be lightened for the energy saving. At the same time, the value of photoresistor is changed to be small. As shown in Figure 7-3, the photoresistor and a usual resistor are connected serially each other and powered by the energy source 5V provided by Arduino board. By the circuit principle, if the value of photoresistor is more smaller, the value of distribution voltage is more smaller. Therefore, we can draw a conclusion. If the outside light is more stronger, the value of photoresistor is more smaller, and it thus leads to a fact that the value of the distribution voltage is small. So, if the distribution voltage for the photoresistor is less than a threshold voltage, it cannot trigger the Port 8 a high level, which results in the LED dark.

However, we have another problem: how can we get the threshold voltage for the photoresistor? This is a key problem. As shown in Figure 7-3, R1 is the serial resistor, and R2 is the photoresistor (temporarily replaced of the photoresistor in this figure), where the value 20Ω is named as light resistor, which can measured by utilizing multimeter shown in Figure 7-4. The real measured value is 17.49Ω by multimeter, but for computation conveniently, it is 20Ω. Additionally, this value and dark resistor value are given out generally in the description of product.

Figure 7-3 Distribution voltage principle for the photoresistor

Figure 7-4 The measured light resistor value by using multimeter for the photoresistor

# Seg 4: Characteristics of photoresistor

1. Main parameters of photoresistor

1) Light resistor (kΩ): means the value of resistor by light irradiation.

2) Dark resistor (MΩ): means the value of resistor under no light irradiation.

3) High voltage (V): means the allowable highest voltage for the photosensitive resistor under the rated power.

4) light current: means the current when the photosensitive resistor by the light irradiation under the provisions of the applied voltage.

5) dark current (mA): means the current when the photosensitive resistor by no light irradiation under the provisions of the applied voltage.

6) time constant (s): means the time when the current of photoresistor is 63% of the stable current from the start by the light irradiation.

7) resistor temperature coefficient: means the change of the resistor value when the environment temperature changes 1 c.

8) Sensitivity: means the change for the photosensitive resistor when no light and light irradiation.

2. Application for photoresistor

It is widely used in various automatic control circuit (such as automatic lighting control circuit, automatic alarm circuit, etc.), household electrical appliances (such as TV automatically adjust the brightness, the automatic exposure control of the camera, etc.) and all kinds of measuring instruments.

# Seg 3: Characteristics of photoresistor

1. structure of photoresistor

As for the photoresistor, there are main three structures: snake, comb, and carved structures. Usually, it is compose of photosensitive layer, the glass substrate moistureproof film (or branch) and the electrode.

1. photo consitution (b) snake

(c) carved structure (d) comb

Figure 7-2 constitution and structure of photoresistor

1. classification

1by the materials: polycrystalline and single crystal silicon photosensitive resistor, CdS, PbS, PbSe, InSb, photoresistor, and so on.

2by the property of photon spectrum:

● Visible light resistor: which is mainly used in all kinds of photoelectronic automatic control system, electronic camera, photon alarm, and so on.

●Ultraviolet light photoresistor: which is mainly Uv detection instrument.

●Infrared photosensitive resistor: which is mainly used in astronomy, military and other fields related to automatic control system.

1. characteristics of photoresistor

Photosensitive resistor is a special resistor by the use of the photoconductive semiconductor effect, which is sensitive to light. Its resistance value can be changed as the outside light intensity (shade). If in the light irradiation, it would show a high impedance state; While a light irradiation, the resistance decreases rapidly.