CODE | Light Sensor - Arduino Project 014

RonWang2 years ago (2023-09-06)电子编程 COD4

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

Share with Friends:

Related Articles

CODE | LED Fire Effect - Arduino Project 009

CODE | LED Fire Effect - Arduino Project 009

Project 9 will use LEDs and a flickering random light effect, via PWM again, to mimic the effect of…

CODE | Dual Servo Control - Arduino Project 026

CODE | Dual Servo Control - Arduino Project 026

This project you’ll create another simple project, but this time you’ll control two servos using com…

CODE | LED Blink - Arduino Project 001

CODE | LED Blink - Arduino Project 001

Arduino 电子编程--灯项目及控制,主要使用Arduino编程控制LED灯,实现基本控制Project 1 LED闪烁,基本的应用Project 3和4红绿灯项目Project 1 …

CODE | Serial Controlled Mood Lamp - Arduino Project 010

CODE | Serial Controlled Mood Lamp - Arduino Project 010

For Project 10, you will revisit the circuit from Project 8 — RGB Mood Lamp, but you’ll now delve in…

Install PrestaShop 1.7 Version

Install PrestaShop 1.7 Version

现在很多国内的公司为了拓展对外业务,开始采用更先进的电子商务软件,如美国的Amazon,加拿大的Shopify,法国的PrestaShop等都有很多用户在使用,对于商业初期的低成本尝试,开源软件Pre…

CODE | RFID Servo and LED Control System - Arduino Project 045

CODE | RFID Servo and LED Control System - Arduino Project 045

Arduino Programming Basic -- RFID Servo and LED Control System Integrating RFID technology…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.