To simulate a PID loop in Tinkercad, we need a system that changes over time based on our input. A classic example is a or a filtered PWM analog output acting as a pseudo-temperature system.
To simulate PID, we need a system that can move and a way to measure that movement. A popular choice in Tinkercad is using an to control a DC Motor with an Encoder (or a simple Potentiometer to simulate a sensor). The Components: Arduino Uno R3 L293D Motor Driver (to handle the power) DC Motor with Encoder (to provide feedback) Potentiometer (to act as our "Setpoint" dial) Breadboard and Jumper Wires The PID Code Structure
// PID Control Simulation Code for Tinkercad // Pin Definitions const int setpointPin = A0; // Potentiometer input const int feedbackPin = A1; // Measured system state const int outputPin = 3; // PWM output pin // PID Tuning Parameters double Kp = 2.5; // Proportional Gain double Ki = 1.0; // Integral Gain double Kd = 0.1; // Derivative Gain // PID Variables double setpoint = 0; double input = 0; double output = 0; double error = 0; double lastError = 0; double integral = 0; double derivative = 0; // Timing Variables unsigned long lastTime = 0; const double sampleTime = 0.05; // 50 milliseconds sample rate void setup() pinMode(outputPin, OUTPUT); Serial.begin(9600); lastTime = millis(); void loop() unsigned long now = millis(); double timeChange = (double)(now - lastTime) / 1000.0; // Convert to seconds // Execute PID calculations at regular intervals if (timeChange >= sampleTime) // Read Setpoint (0-1023) and scale to 0-255 setpoint = analogRead(setpointPin) / 4.0; // Read Current System State (0-1023) and scale to 0-255 input = analogRead(feedbackPin) / 4.0; // Calculate Error error = setpoint - input; // Calculate Integral component with windup protection integral += error * timeChange; if (integral > 255) integral = 255; if (integral < -255) integral = -255; // Calculate Derivative component derivative = (error - lastError) / timeChange; // Compute PID Output output = (Kp * error) + (Ki * integral) + (Kd * derivative); // Constrain output to valid PWM range (0-255) if (output > 255) output = 255; if (output < 0) output = 0; // Write PWM to the circuit analogWrite(outputPin, (int)output); // Debugging out to Serial Plotter Serial.print("Setpoint:"); Serial.print(setpoint); Serial.print(","); Serial.print("Input:"); Serial.print(input); Serial.print(","); Serial.print("Output:"); Serial.println(output); // Save state for next iteration lastError = error; lastTime = now; Use code with caution. 4. Visualizing PID Behavior in Tinkercad
: Connect your sensor (input) and motor/servo (output) to the Arduino pins. tinkercad pid control
While Tinkercad has limitations (it’s not real-time hardcore control), it’s perfect for learning the logic of PID before touching physical hardware.
): If your current temperature settles a few degrees short of the 60°C setpoint, increase Kicap K sub i
Here’s how to build a simple using a virtual Arduino, a temp sensor (TMP36), and a heater (simulated as an LED). To simulate a PID loop in Tinkercad, we
// Save for next loop previous_error = error; last_time = now;
// Limit output (0-255 for PWM) if (output > 255) output = 255; // Anti-windup: Stop integrating if output is saturated if (error > 0) integral = integral - (error * dt);
Increase Kd to "dampen" the oscillations. This acts like a shock absorber, smoothing out the movement. A popular choice in Tinkercad is using an
double Kp = 2.0, Ki = 0.5, Kd = 1.0; // These are your "tuning" parameters double setpoint, input, output; double error, lastError, cumError, rateError; void loop() input = readSensor(); // Get current position setpoint = readPotentiometer(); // Get desired position error = setpoint - input; // Calculate the gap cumError += error; // Integral: Sum of errors over time rateError = error - lastError; // Derivative: Change in error // The PID Formula output = (Kp * error) + (Ki * cumError) + (Kd * rateError); driveMotor(output); // Apply the correction lastError = error; // Save for next loop delay(10); Use code with caution. How to Tune Your PID in Tinkercad
Because Tinkercad does not natively include a "PID block," implementation typically happens through Arduino C++ code or block-based logic. Closed-Loop Architecture:
The controller calculates its output using three distinct mathematical terms:
Proportional-Integral-Derivative (PID) control is the backbone of modern automation. It keeps drones stable, maintains 3D printer nozzle temperatures, and guides self-driving cars.
is the gold standard for automation, used to precisely regulate temperature, speed, and position in robotics and industrial systems. Simulating a hardware PID loop used to require physical components, but Autodesk Tinkercad Circuits allows you to build, code, and tune a virtual PID controller completely free in your web browser.