当前位置:首页 > 科学研究 > 电子编程 > 正文内容

Arduino Project 014 - Light Sensor

RonWang4个月前 (08-20)电子编程51

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
}

Arduino Light Sensor Circuit

Arduino Light Sensor Schematic

版权声明:本文为原创文章,版权归donstudio所有,欢迎分享本文,转载请保留出处!

本文链接:http://www.donstudio.cn/?id=264

标签: Arduino

相关文章

Arduino Project 030A - Dual Motor Driver L298N

Arduino Project 030A - Dual Motor Driver L298N

L298N Dual Motor Driver Project Description  The L298N Motor Driver is a control...

Arduino UNO Mp3音乐播放代码

Arduino UNO Mp3音乐播放代码

Arduino UNO Mp3音乐播放代码今天我们将使用Arduino UNO 和SD卡制作音乐播放器。这个播放器不需要添加多余的模块,只需要SD读卡器和Arduino UNO开发板就可以播放音频文件...

Arduino Programming Basic - Funcation

Arduino Programming Basic - Funcation

Arduino 程序基础,介绍Arduino程序的基本组成,第一部分编写了10个例子,关于变量及变量名称,串口监视器,if循环,for循环,while循环等。第二部分介绍了函数,全局变量,局部变量和静...

Arduino Project 028A - Basic Stepper Control (Bipolar)

Arduino Project 028A - Basic Stepper Control (Bipolar)

In this very simple project, you will connect up a stepper motor and then get the Arduino to control...

C语言调试运行环境TurboC的安装

C语言调试运行环境TurboC的安装

上大学时学习《C语言程序设计》(第二版)作者谭浩强,大部分编程时间是在学校机房度过,每次点开桌面的TurboC图标,就开始在里面敲代码,然后保存程序Abc.C,下一步进行编译,如果编译成功的话,就可以...

Arduino Project 017 - Shift Register 8-Bit Binary Counter

Arduino Project 017 - Shift Register 8-Bit Binary Counter

In this project, you’re going to use additional ICs (Integrated Circuits) in the form of shift regis...

发表评论

访客

看不清,换一张

◎欢迎参与讨论,请在这里发表您的看法和观点。