CE 351 2020 Fall
Lab 5: PIDs
Nic Theobald

PID Control with LED and Photoresistor


PID control is a widely used method in control systems. It can be used to sample the current value, calculate the error between the current value and the desired value, and then attempt to correct the error. In this experiment, a LED and Photoresistor is used to maintain a constant light intensity. The experiment started with the framework of the system, with minimal tuning, and ended with a more refined version of the system. The final version of the system allows for custom setpoint tracking using a pushbutton, serial input, and a potentiometer.

Methods and Materials


Arduino IDE
Arduino UNO
Push Button
10k Pull down resistor
200 ohm resistor

The first step to developing a PID system is determining the boundary conditions of the systems. The high point of the system was determined by completely turning the LED on and measuring the voltage at the LDR voltage divider. The low point was determined using a similar process except turning the LED complete off. The setpoint was determined by finding the midpoint between the high and low value. The setpoint could also be manually set anywhere between the high and low values. The system was tuned in order to reduce noise and overshoot. A pushbutton, potentiometer, and serial input was used to manually set the setpoint and investigate the effectivness of the system.


Task 1: Basic PID System

A basic system was built and programmed. Minimal tuning was performed where the P coefficient was set to 0.03. I coefficient set to 1 to get the signal to oscillate around the set point. The video below demonstrates the system in real time. The High and Low lines in the plot are the systems high and low illumination values. The system automatically determines the setpoint every time it is reset and the plot is updated.

Figure 1: System automatically determining the setpoint and then oscillating around setpoint.
Task 2: Tuning the PID System

The system was better tuned and distrubences were introduced to test the systems correction abilities.

Figure 3: System reacting to outside disturbances.

Task 3: Custom set points

The system was tuned using realtime serial input by adjusting the coefficients and seeing how the system reacts. Similarly, serial input, a push button, or a potentiometer could be added for realtime setpoint setting.

Figure 4: Setting the setpoint in realtime using Serial Input.

Figure 6: Setting the setpoint in realtime using a Potentiometer.

Figure 7: Setting the setpoint in realtime using a pushbutton.

Finished Code:


This lab experimented with a basic PID system. The system was tuned in order to reduce noise and maximize the systems correction speed while reducing overshoot. A pushbutton, serial input, and a potentiometer was used to set the systems setpoint.