# 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 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