Pixy LEGO PID Block

The Pixy PID block allows you to implement a simple PID controller. Proportional Integral Derivative (PID) controllers are commonly used in feedback control systems. There is a feedback controller in your home’s thermostat and your car’s cruise control. The basic idea is you measure, then compare with a setpoint (the “goal”), then calculate how you should act so that the system reaches the goal. For example, your home’s thermostat first measures the temperature, then compares to the desired temperature, then calculates if it should turn on the heater or air conditioner. A PID controller works in the same way, but uses a special equation to calculate the “action” value. All the user needs to do is set the three gain values, one for proportional, one for integral, and one for derivative.

For example, if you wanted your robot to chase a ball, you could use a PID controller to keep your robot facing the ball. Here, the “goal” is to keep the ball in the center of Pixy’s camera image and therefore facing the ball. The “action” is controlling the motors such that the ball is kept in the center of Pixy’s camera image. In other words, the PID controller calculates the velocity of the motors needed to keep the ball in the center of Pixy’s camera image.

There is a good explanation of PID control here.


  1. Mode Selection: currently there is a single mode, so this isn’t used for now.
  2. Instance: instance of the PID block. Up to 8 instances of the PID block can be used independently in the same program. If you need more than one PID block, be sure to give them different instance IDs, otherwise the two PID blocks will share the same memory.
  3. Value In: this is the input for the measured value. For Pixy, you would typically input the X or Y outputs, but really any measured value can go here, even from sensors other than Pixy, like the IR proximity sensor.
  4. Set Point: this is the “desired value”. In other words you want to “drive” the sensor value (Value In) to this value.
  5. Proportional: proportional gain input.
  6. Integral: integral gain input.
  7. Derivative: derivative gain input.
  8. PID Multiplier: this is a multiplier for the final output. It is especially useful if you need to invert the output (you do so by setting to -1). This value is 1 by default.
  9. Control Output: this is the output of the controller. This is typically connected to your “action”, which is almost always one or more motors (for LEGO Mindstorms). You could (in theory) connect this to your furnace if you wanted to build a home thermostat, and you had a temperature sensor connected to Value In, but that’s a project for another day!