• 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

This Article Has Been Shared 557 Times!

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

  • Choosing The Correct LCD Display For Arduino Like Boards

    Choosing The Correct LCD Display For Arduino Like Boards Is Crucial For Budget, For Compatibility With Wider Range Of Board & Microcontroller.

  • 7 Segment LED Display Tutorial For Dummies

    Here is Step By Step 7 Segment LED Display Tutorial For Dummies On How To Light Up With Battery To Control With Arduino Without Library.

  • Arduino 2 Push Button One LED : Switch On/Off

    Here is Circuit Diagram and Code For Arduino 2 Push Button One LED to Switch On/Off Project. It is Very Easy Yet Important Basic Behind Using Sensors to Switch On/Off an Event.

  • Arduino Stepper Motor Buying Guide (Driver IC Included)

    Here is Arduino Stepper Motor Buying Guide Including Needed Basics on Driver IC. Stepper Motor is Much More Complicated From Buying Point Than Servo Motor.

  • Breadboard Fuse Holder and Fuse For Arduino Projects

    Here is Basic Details on Breadboard Fuse Holder and Fuse For Arduino Projects. It Prudent to Use Fuse When Basic Matter Around Fuse is Known. Without Knowing Using Fuse Provides False Sense of Security.

Additionally, 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 (22.1K 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

  • How Artificial Intelligence (AI) Is Changing The Way We Play Bingo May 16, 2022
  • Why You Need A Big Data Consultant May 15, 2022
  • The Connection Between AI And Online Slots May 13, 2022
  • How To Choose Your Niche As An Instagram Influencer May 12, 2022
  • How to Choose a Powerful Domain Name for Your New Venture May 12, 2022

About This Article

Cite this article as: Abhishek Ghosh, "Control Multiple LED Depending on the Level of Light With Arduino," in The Customize Windows, June 6, 2018, May 16, 2022, https://thecustomizewindows.com/2018/06/control-multiple-led-depending-on-the-level-of-light-with-arduino/.

Source:The Customize Windows, JiMA.in

This website uses cookies. If you do not want to allow us to use cookies and/or non-personalized Ads, kindly clear browser cookies after closing this webpage.

Read Privacy Policy.

PC users can consult Corrine Chorney for Security.

Want to know more about us? Read Notability and Mentions & Our Setup.

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

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