Analog Read to Control LED Light - TANN THONA

Department of Telecommunication and Electronic Engineering

Hot

Post Top Ad

Wednesday, December 5, 2018

Analog Read to Control LED Light

Analog Read Control LED Light

1. Objective

The objective of this project is talk about, how to use analog read to control LED light colors. We use voltage divider input to analog pin and read value to control LED with digital pin.

2. Electronic Requirement

  • Arduino Uno
  • USB Cable
  • Breadboard
  • LED (or RGB)
  • POT-HG (Variable Resistor)
  • Resistor 330Ohm or 220Ohm (Digital pin --> Resistor --> LED)
  • Electronic Wire

 3. Build Circuit

The first build circuit like Fig1.1.


Fig1.1 Analog read to control LED lights.

 Arduino Code:
// Coding by Tann Thona (26/03/2017), Adviser: Chann Tola  
float x=0;
float y=0;
int t =300;
void setup()
{
pinMode(13,OUTPUT);
pinMode(1,OUTPUT);
pinMode(2,OUTPUT);
pinMode(3,OUTPUT);
//pinMode(10,OUTPUT);
}
void loop()
{
y = analogRead(A0);
x=(5*y)/1023;
if(x>3)
{
digitalWrite(13,HIGH);
}
else
{
digitalWrite(13,LOW);
}

// LED Three color (RGB)

digitalWrite(1,HIGH);
digitalWrite(2,LOW);
digitalWrite(3,LOW);
delay(t);
//-------------------------
digitalWrite(1,LOW);
digitalWrite(2,HIGH);
digitalWrite(3,LOW);
delay(t);
//-------------------------
digitalWrite(1,LOW);
digitalWrite(2,LOW);
digitalWrite(3,HIGH);
delay(t);
//-------------------------
}


4. Result

When we run this code in Arduino software and output to circuit, LED has light or dark is depend on value of POT-HG that we change. While we change POT-HG value power supply in put voltage to Pin Analog (A0) of Arduino and Pin Digital (13) red from A0 and output to LED. Whereas RGB is change color one by one of the three color with delay time in code.



Royal University of Phnom Penh
Faculty of Engineering
Dep. Telecommunication and Electronic Engineering

Group Member:
1. Tann Thona

2. Thach Soveasna
3. Chhoy Noreath
4. Neth Channa
5. Mok Vira

Instructor: Prof. Chann Tola
Date: 26 March 2017

No comments:

Post a Comment

Post Top Ad