CODE | Light Sensor - Arduino Project 014

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

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

DIY T12 Soldering (Partial -Assembled Kits)

DIY T12 Soldering (Partial -Assembled Kits)

今天我们要自己动手做一台高性价比的T12焊台,我们通过DIY来体验T12的快速温升带给我们焊接的畅快。T12的焊台有什么让人着迷地方?为什么很多焊接达人,都希望拥有一台高品质的T12焊台,DIY一台T…

CODE | Ultrasonic Distance Display - Arduino Project 039

CODE | Ultrasonic Distance Display - Arduino Project 039

Ultrasonic sensors measure distance by sending and receiving the ultrasonic wave. The ultrasonic sen…

Setting Up an LNMP Environment on CentOS 7.9 64-bit

Setting Up an LNMP Environment on CentOS 7.9 64-bit

CentOS 7.9 64位 搭建 LNMP环境What is a LAMPLAMP is a free and open source software suite combines four po…

CODE | LED Dot Matrix Display Beat Heart - Arduino Project 020

CODE | LED Dot Matrix Display Beat Heart - Arduino Project 020

You’re going to use the same circuit, but with a slight variation in the code to create a multi-fram…

Centos Install OSCommerce 4.0

Centos Install OSCommerce 4.0

osCommerce is a Free shopping cart and open source Ecommerce software. You can choose to host your o…

Centos Install MemCached, Apcu and OpCache

Centos Install MemCached, Apcu and OpCache

This section provides instructions to install memcached on CentOS and Ubuntu. For additional informa…

Post a Comment

Anonymous

Feel free to share your thoughts and opinions here.