sheen.bot Logo

2.12 Potentiometer and Fan Module

A potentiometer is an analog input device that changes its resistance based on how much the knob is turned. This change is measured as an analog value between 0 and 4095. It is commonly used to control other components such as LEDs or motors in a gradual, user-controlled way.

A fan module is an output device that uses a small DC motor to generate airflow. It can be turned on, off, or have its speed adjusted using a digital or PWM signal, making it useful in interactive electronics and smart cooling systems.

Example Applications:

  • Adjusting LED brightness
  • Controlling motor or fan speed
  • Building user-controlled interfaces

2.12.1 Example Code for the Potentiometer

The light sensor outputs an analog value (typically between 0 and 4095) based on the surrounding light. In this example, we check if the brightness exceeds a threshold (4080) to turn on a yellow lamp.

  • Hardware Setup:
    • Connect a potentiometer to analog pin P0.
    • Attacha Piranha LED to P15, and a fan module to P16.
  • Programming Steps (Block-Based):
    • LED Brightness: Set the LED intensity on P15 using the potentiometer value (set LED on P15 output read POTENTIOMETER on P0).
    • Fan Speed: Adjust the fan speed on P16 proportionally to the potentiometer reading (set Fan on P16 output read POTENTIOMETER on P0).
    • Display Value: Map the raw potentiometer range [0, 4095] to [0, 100] and show it on-screen (screen display text map...).
  • Key Notes:
    • The potentiometer’s 12-bit analog input (0–4095) is scaled to 0–100% for readability.
    • All outputs (servo, LED, fan) react simultaneously to the potentiometer’s position.
Figure 2.12.1a: Potentiometer control logic for LED and fan (block-based)