Arduino Project 014 - Light Sensor
This project introduces a new component known as a Light Dependent Resistor, or LDR. As the name implies, the device is a resistor that depends on light. In a dark environment, the resistor has a very high resistance. As photons (light) land on the detector, the resistance decreases. The more light, the lower the resistance. By reading the value from the sensor, you can detect if it is light, dark, or anywhere between. In this project, you use an LDR to detect light and a piezo sounder to give audible feedback of the amount of light detected.
This setup could be used as an alarm that indicates when a door has been opened, for example. Alternatively, you could use it to create a musical instrument similar to a theremin.
项目Project 14 Light Sensor 光敏元件
/* Coding Ron Wang Aug.20th 2024 Autaba support for coding hardware */ // Project 14 - Light Sensor int piezoPin = 8; // Piezo on Pin 8 int ldrPin = 0; // LDR on Analog Pin 0 int ldrValue = 0; // Value read from the LDR void setup() { // nothing to do here } void loop() { ldrValue = analogRead(ldrPin); // read the value from the LDR tone(piezoPin,1000); // play a 1000Hz tone from the piezo delay(25); // wait a bit noTone(piezoPin); // stop the tone delay(ldrValue); // wait the amount of milliseconds in ldrValue }
版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!