Delivery throughout Europe

Ordered before 16:00 = Shipped today

Fast delivery with DHL

XNUMX days return *


Country

In this project you let an LDR light on or off, depending on whether more or less light shines.

We use an LDR for this project. LDR stands for light depending resistor. Which means that the resistance depends on the amount of light shining on it. The more light shines on the LDR, the lower the resistance.

We can read a value from the LDR with the Arduino. In this project we hang different values ​​on the LED lights. We do this in such a way that when more light shines on it, more LED lights come on. We do this with if else logic gates and the analogread function. In the programming part I explain what these functions mean.

ammer.

  • Level - Beginner 30% 30%
  • Duration - 10/15 Min 30% 30%
  • Costs - € 31,24 euros complete 30% 30%

Step 1: Requirements

1X Arduino UNO

1X breadboard

15X Jumper wires

5X LED light

1X LDR

6X 220 ohm resistor

Step 2: Building and Wiring

Now that you have collected all the parts, you can start to assemble the project. The first thing you do in terms of wiring is connect the 5v from the Arduino to the plus of the breadboard† Then connect the GND to the minus of the breadboard at. Then place the LED lights in the breadboard† It doesn't matter what color lights you use. The plus side of the LED light is defined with the longest pin. Place a 220 ohm resistor here. Place a jumper wire on the other side of the resistor. This goes to the I/O pin of the Arduino. The left LED goes to I/O pin 2, the next to I/O pin 3 and so on. Now connect the minus of the LED light (shortest pin) to the minus of the breadboard Then connect the LDR. Connect one of its pins to the plus of the breadboard† It does not matter which one this is because you cannot connect an LDR the wrong way round. Once you've done that, grab a resistor and make sure it's on the other pin. Then put a jumper wire in the breadboard in the same place where the resistor is. Put this in the A0 pin of the Arduino. Finally, connect a jumper wire from the other side of the resistor to the negative of the breadboard.

Step 3: Programming

 

Once you have connected everything correctly, you can start programming.

The code for this project is quite short. In the code we use the analog read function and if else logic gates.

We use the analogread function to read the value of the analog pin. This is the value of the LDR. Then we use the if else logic gates.
The moment the value matches (so if is) the light will come on with us. If the value does not match (so is else), the light is not lit.

 

//hier zetten we alle componenten op een pin
int sensor = A0;
int led1 = 2;
int led2 = 3;
int led3 = 4;
int led4 = 5;
int led5 = 6;
int Value = 0;

void setup(){
  //hier zorgen we dat die pinnen een puls geven
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT);
  pinMode(led4, OUTPUT);
  pinMode(led5, OUTPUT);
}

void loop(){
  //nu zorgen we ervoor dat hij A0 leest
  Value = analogRead(sensor);
  delay(100);
  //nu laten we het lampje aangaan 
  //als de waarde 110 of hoger is
  if(Value >= 110){
    digitalWrite(led1, HIGH);
  }else{
    //anders gaat hij uit
    digitalWrite(led1, LOW);
  }
  if(Value >= 125){
    digitalWrite(led2, HIGH);
  }else{
    digitalWrite(led2, LOW);
  }
  if(Value >= 140){
    digitalWrite(led3, HIGH);
  }else{
    digitalWrite(led3, LOW);
  }
  if(Value >= 155){
    digitalWrite(led4, HIGH);
  }else{
    digitalWrite(led4, LOW);
  }
  if(Value >= 170){
    digitalWrite(led5, HIGH);
  }else{
    digitalWrite(led5, LOW);
  }
}
The rating of www.elektronicavoorjou.nl at WebwinkelKeur Reviews is 9.3/10 based on 4991 reviews.