0% found this document useful (0 votes)
58 views12 pages

Ambient Light Control: Using Software PID Controller

This document describes a project using a PID controller to maintain ambient light levels in a room using a light source and light sensor. A software PID controller is implemented on an Arduino to control a light-emitting diode (LED) based on input from a light dependent resistor (LDR) sensor. The PID parameters of proportional, integral and derivative control are explained. Results show the output value changing to achieve different light setpoints and maintaining a constant value once the setpoint is reached.

Uploaded by

USAMA TAHIR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views12 pages

Ambient Light Control: Using Software PID Controller

This document describes a project using a PID controller to maintain ambient light levels in a room using a light source and light sensor. A software PID controller is implemented on an Arduino to control a light-emitting diode (LED) based on input from a light dependent resistor (LDR) sensor. The PID parameters of proportional, integral and derivative control are explained. Results show the output value changing to achieve different light setpoints and maintaining a constant value once the setpoint is reached.

Uploaded by

USAMA TAHIR
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 12

AMBIENT LIGHT

CONTROL
Using software PID controller
Group Members Presented to
■ Syed Muhammad Ali Ashja Dr. Bilal Qureshi
FA16-BEE-102
■ Uzair Bukhari
FA16-BEE-046
■ Muhammad Usama Tahir
FA16-BEE-154
Introduction to PID

■ “Proportional Integral Derivative” (PID) Controller is based on a closed loop system


used for continuous control of a system instead of discrete logic.
■ Continuous feedback is performed by calculating error, e(t), as the difference between
system output and reference input.
■ The parameters controlled using PID are termed as: overshoot, delay, stability.
■ Proportional: The gain required to reach the system to set point.
■ Derivative: Controls how fast system reacts to reach set point.
■ Integral: Sums up the remaining previous error to reach set point.
Project Description
■ A model of Ambient Light control of a room:
■ We’ll use a light source and a sensor to Set the Ambient light of the room to a certain level, if the
Light varies due to some disturbance, the PID system will ensure that It maintains the fixed level.
Tools used
Tools Model No. Purpose

LED 5v white LED Light source


LDR sensor 2M ohm Light sensor

Motor Driver L298N Used as LED driver

Power source 3.3-5V source Supply Power


Arduino UNO Compute PID
Circuit Diagram
Code

■ We will use the Standard PID library for Arduino for this project.
■ The Code sets the default perimeters ,Read inputs from sensors and the compute PID value
with a sample time of 2mS.
■ The setpoint is adjusted using a POT.
■ The control Method has two Approaches to remove Error:
1. constant gains.
2. aggressive gains.
■ The Constant gains use lower gain value and if the gap between error and set point is High then
we use Aggressive gains.
■ Functional code Snippets are shown below:
Code
(contd)
Setpoint =150 ; Setpoint=255;
myPID.SetMode(AUTOMATIC);
myPID.SetOutputLimits(0, 255); double gap = abs(Setpoint-Input);
myPID.SetSampleTime(2); if (gap < 10){ myPID.SetTunings(consKp, consKi, consKd);
} }else
void loop(){ {
digitalWrite(in1, LOW); myPID.SetTunings(aggKp, aggKi, aggKd);
digitalWrite(in2, HIGH); }
Input=map(analogRead(0),0,1023,0,255); myPID.Compute();
Setpoint=map(analogRead(A1),0,1023,0,255); analogWrite(enA,Output);
if(Setpoint>250)
Code
(contd)
bool PID::Compute() f(outputSum > outMax) outputSum= outMax;
{ if(!inAuto) return false; else if(outputSum < outMin) outputSum= outMin;
unsigned long now = millis(); double output; if(pOnE) output = kp * error;
unsigned long timeChange = (now - lastTime); else output = 0;
if(timeChange>=SampleTime) {double input = *myInput; output += outputSum - kd * dInput;
double error = *mySetpoint - input; if(output > outMax) output = outMax; else if(output < outMin)
output = outMin; *myOutput = outputlastInput = input;
double dInput = (input - lastInput);
lastTime = now;
outputSum+= (ki * error);
return true; }
if(!pOnE) outputSum-= kp * dInput;
else return false;}
PID tuning

■ Normal convention for tuning a PID controller is to Set the Kp gain first and adjust Ki
and Kd according to it.
■ In our system as we are using a light source directly and not sunlight, so the reaction is
very fast so we cant use proportional gain as it gives negative response which results in
oscillations.
■ Same is the case for Derivative gain Kd which is used for future errors.
■ So our system is tuned with and integral gain that uses the past values of error to
remove it.
Results

■ As we change the setpoint (from time 925-1124) the PID changes the output value accordingly to
achieve the require setpoint.
■ Once the Setpoint is fixed (from time 1225-1425 ) the output value is constant.
Conclusion

■ The project implemented PID for Ambient light control.


■ The project worked fine for its given constraints and prototype version .
■ Further improvements can be implemented in the form of:
1. More sensors for additional feedback.
2. Different positions of light source that changes slowly with time for better results.

You might also like