- Hands-On Robotics Programming with C++
- Dinesh Tavasalkar
- 366字
- 2021-06-24 15:30:32
The LDR sensor and the way it works
An LDR sensor is an analog input sensor that consists of a variable resistor whose resistance varies depending on the amount of light falling on its surface. When there is no light in the room, the resistance of the LDR sensor is HIGH (up to 1 M ohm) and in the presence of light, the resistance of the LDR sensor is LOW. The LDR sensor consists of two pins. These pins do not have positive and negative polarity. We can use any pin as a data or ground pin and because of this, the LDR sensor is sometimes referred to as a special type resistor. The image of the LDR sensor is shown in the following photo:

Since LDR is an analog sensor, we cannot connect it directly to the RPi as this does not contain an analog to digital converter (ADC) circuit. Because of this, RPi cannot read incoming analog data from an LDR sensor. So, instead of an LDR sensor, we will use an LDR digital sensor module, which will provide digital data to the RPi:

An LDR sensor module will read the incoming analog data from the LDR sensor and provide digital data in the form of HIGH or LOW as output. The LDR sensor module consists of 3 pins: D0 (data output), ground, and Vcc. D0 will provide digital data as output, which is further provided as input to RPi pins. The D0 pin will be HIGH in low light and will be LOW in the presence of light. The sensor module also consists of a potentiometer sensor, which can be used to vary the resistance of the LDR sensor.
Practical uses of the LDR sensor module is seen in street lamps, which automatically turn off during day time and turn on during night time. The smart light program that we are going to write is somewhat similar to this application, but instead of a street lamp, we are going to use an LED to keep things simple.
Now that we've gained an understanding of the basic way in which an LDR sensor works, next let's connect the LDR sensor module to Raspberry Pi.
- Android和PHP開發最佳實踐(第2版)
- 計算機圖形學編程(使用OpenGL和C++)(第2版)
- 架構不再難(全5冊)
- 技術領導力:程序員如何才能帶團隊
- Mastering Articulate Storyline
- 編寫高質量代碼:改善C程序代碼的125個建議
- 精通Python設計模式(第2版)
- Mastering Drupal 8 Views
- Scala編程實戰(原書第2版)
- 劍指Java:核心原理與應用實踐
- 精通MATLAB(第3版)
- RabbitMQ Essentials
- Kubernetes進階實戰
- Scala Functional Programming Patterns
- 跟戴銘學iOS編程:理順核心知識點