• Home
  • Archive
  • Tools
  • Contact Us

The Customize Windows

Technology Journal

  • Cloud Computing
  • Computer
  • Digital Photography
  • Windows 7
  • Archive
  • Cloud Computing
  • Virtualization
  • Computer and Internet
  • Digital Photography
  • Android
  • Sysadmin
  • Electronics
  • Big Data
  • Virtualization
  • Downloads
  • Web Development
  • Apple
  • Android
Advertisement
You are here:Home » Control Multiple LED Depending on the Level of Light With Arduino

By Abhishek Ghosh June 6, 2018 9:07 am Updated on June 6, 2018

Control Multiple LED Depending on the Level of Light With Arduino

Advertisement

In our previous guides, we have shown how to control single LED depending on light with Arduino. Also, we have shown that without Arduino, can control LED depending on the level of light. The ways are different but essentially both involves a basic component – LDR. In this guide, we will show how to control multiple LED depending on the level of light With Arduino. It means – with increasing darkness higher number of LED will light up. In case of our Automatic LED Control Using LDR project, we had different logic. It’s practical usage can be indicator of luminescence or lighting up more light on increasing dark, which happens when sets.

 

Principal to Control Multiple LED Depending on the Level of Light

 

We can get an arbitrary value of light on serial monitor of Arduino IDE with LDR and Arduino. If we set each LDR to light up at different values with increasing darkness, our goal will be reached. Pin 13 is Arduino UNO’s board LED. With one LED, our code will become :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const int ldrPin = A0;
const int ledPin1 = 13;
 
int ldrValue = 0;
int ldrlevel1=800; // arbitrary value depending on serial monitor
 
void setup() {
  Serial.begin(9600);    
  pinMode(ledPin1, OUTPUT);
}
 
void loop() {
  ldrValue = analogRead(ldrPin);  
  Serial.println(ldrValue);
  if (ldrValue < ldrlevel1) {
    digitalWrite(ledPin4, HIGH);
  }
  else {
    digitalWrite(ledPin1, LOW);
      }
   }

Notice the value on serial monitor of Arduino IDE, note down values with dimming light of your room. Now, if we increase the number of LED and adjust the program, that will do the job. It is easy.

Advertisement

---

 

Code and Program to Control Multiple LED Depending on the Level of Light

 

We will use 4 LDR in this project. We need the following parts :

Arduino UNO or similar board – ONE
LDR – ONE
10K Ohm resistor – ONE
LED – FOUR
220 Ohm resistors for LEDs – FOUR
Breadboard – ONE
Jumpers – Few

This will be the circuit diagram (better to say connection) :

Control Multiple LED Depending on the Level of Light With Arduino

This is example code with 4 LED and serial output for debugging :

Vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const int ldrPin = A0;
const int ledPin1 = 12;
const int ledPin2 = 11;
const int ledPin3 = 10;
const int ledPin4 = 9;
 
 
int ldrValue = 0;
int ldrlevel1=600;
int ldrlevel2=700;
int ldrlevel3=750;
int ldrlevel4=800;
 
void setup() {
  Serial.begin(9600);    
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
}
void loop() {
  ldrValue = analogRead(ldrPin);
  Serial.println(ldrValue);
  if (ldrValue < ldrlevel1) {
    digitalWrite(ledPin4, HIGH);
  }
  else if (ldrValue < ldrlevel2) {
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin3, HIGH);
  }
  else if (ldrValue < ldrlevel3) {
    digitalWrite(ledPin3, LOW);
    digitalWrite(ledPin2, HIGH);
  }
  else if (ldrValue < ldrlevel4) {
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin1, HIGH);
  }
  else {
    digitalWrite(ledPin1, LOW);
      }
   }

Notice the logic :

Vim
1
2
3
4
5
6
7
8
9
...
  if (ldrValue < ldrlevel1) {
    digitalWrite(ledPin4, HIGH);
  }
  else if (ldrValue < ldrlevel2) {
    digitalWrite(ledPin4, LOW);
    digitalWrite(ledPin3, HIGH);
  }
...

5th pin is ledPin4 and ldrlevel is lowest. ldrlevel1 is second lowest, ldrlevel1 is third lowest and so on.

When ldrlevel1 value will be greater than ldrlevel, then glow LED number 4.
When ldrlevel2 value will be greater than ldrlevel1, then glow LED number 3.

And so on. Response will be slower, not superb. LDR just a component, the circuit is just easy.

Tagged With arduino logic to control multiple led
Facebook Twitter Pinterest

Abhishek Ghosh

About Abhishek Ghosh

Abhishek Ghosh is a Businessman, Surgeon, Author and Blogger. You can keep touch with him on Twitter - @AbhishekCTRL.

Here’s what we’ve got for you which might like :

Articles Related to Control Multiple LED Depending on the Level of Light With Arduino

  • Arduino and LED Bar Display : Circuit Diagram, Code

    Here is a Guide Explaining the Basics, Circuit Diagram, Code on Arduino and LED Bar Display. LED Bar Display is Actually Like Multiple LED.

  • Arduino : Turn On Particular Color LED Depending On Light/LDR

    With Arduino We an Turn On Particular Color LED Depending On Light/LDR With Simple Circuit and Easy Code. We Can Create The Same Logic With IC too.

  • How to Control Multiple Relays With Single Arduino ESP32?

    Before How to Control Multiple Relays With Single Arduino ESP32 Testing, You Need to Learn How to Create Multiple MQTT Channels & Fetch Data.

  • Arduino LDR/Photoresistor and LED Based Light Meter

    Exactly Like Basic Sound Meter With Microphone, We Can Build Arduino LDR/Photoresistor and LED Based Light Meter. Here is circuit & code.

performing a search on this website can help you. Also, we have YouTube Videos.

Take The Conversation Further ...

We'd love to know your thoughts on this article.
Meet the Author over on Twitter to join the conversation right now!

If you want to Advertise on our Article or want a Sponsored Article, you are invited to Contact us.

Contact Us

Subscribe To Our Free Newsletter

Get new posts by email:

Please Confirm the Subscription When Approval Email Will Arrive in Your Email Inbox as Second Step.

Search this website…

 

Popular Articles

Our Homepage is best place to find popular articles!

Here Are Some Good to Read Articles :

  • Cloud Computing Service Models
  • What is Cloud Computing?
  • Cloud Computing and Social Networks in Mobile Space
  • ARM Processor Architecture
  • What Camera Mode to Choose
  • Indispensable MySQL queries for custom fields in WordPress
  • Windows 7 Speech Recognition Scripting Related Tutorials

Social Networks

  • Pinterest (24.3K Followers)
  • Twitter (5.8k Followers)
  • Facebook (5.7k Followers)
  • LinkedIn (3.7k Followers)
  • YouTube (1.3k Followers)
  • GitHub (Repository)
  • GitHub (Gists)
Looking to publish sponsored article on our website?

Contact us

Recent Posts

  • Affordable Earphone/IEM for Audiophiles: HiFiMan RE-400 WaterlineOctober 2, 2023
  • What is Hardware Security Module (HSM)September 30, 2023
  • Transducer Technologies of HeadphonesSeptember 28, 2023
  • What is Analog-to-Digital Converter (ADC)September 27, 2023
  • Comparison of Tube Amplifiers and SemiconductorsSeptember 26, 2023
PC users can consult Corrine Chorney for Security.

Want to know more about us?

Read Notability and Mentions & Our Setup.

Copyright © 2023 - The Customize Windows | dESIGNed by The Customize Windows

Copyright  · Privacy Policy  · Advertising Policy  · Terms of Service  · Refund Policy