មេរៀនទី១៦៖​ Use LDR Sensor Control Three LEDs (RGB) - Tann Thona

Telecommunication and Electronic Engineering

Post

Post Top Ad

Sunday, December 20, 2020

មេរៀនទី១៦៖​ Use LDR Sensor Control Three LEDs (RGB)

LDR Sensor Control Three LEDs

 

1. Objective

The objective is talk about, Use LDR sensor to control digital pin.

2. Requirement

  • Arduino Uno x1
  • USB Cable x1 (No need in simulation)
  • Breadboard x1 (No need in simulation) 
  • LDR Sensor x1
  • LED x3
  • Resistor (220Ohm or 330Ohm) x3 *Note use to protect LED
  • Resistor 10K x1
  • Electronic Wire (No need in simulation) 
  • Virtue Terminal (For Proteus simulation) 

 

3. Build Circuit

Build circuit like Figure 1.

Figure 1. Arduino Connection


4. Coding

// Tann Thona
int x = 0;
void setup() {
// put your setup code here, to run once:
pinMode(A0, INPUT);
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
pinMode(11, OUTPUT);
Serial.begin(9600);
}

void loop() {
// put your main code here, to run repeatedly:
x = analogRead(A0);
if (x >= 0 && x <= 350)
{
digitalWrite(13, 1);
digitalWrite(12, 0);
digitalWrite(11, 0);
}
else if (x > 350 && x <= 700)
{
digitalWrite(13, 0);
digitalWrite(12, 1);
digitalWrite(11, 0);
}
else
{
digitalWrite(13, 0);
digitalWrite(12, 0);
digitalWrite(11, 1);
}
Serial.println(x);
}

Click Here to Download Code and Proteus Simulation File 

 

4. Result

According to code above, these three LEDs (RGB) switching bright depend on light shine on LDR sensor.

Watch Video Explain in Khmer



YouTube: ICT4D-KH
Copyright By Tann Thona


No comments:

Post a Comment

Post Top Ad