n Lesson 6, we’re really starting to get our hands dirty with real hardware control. Today we dive into the core fundamentals of physical computing on the SunFounder Fusion AI Hat — learning how to use Digital Outputs, control Servos, read Analog Inputs, and generate PWM signals.
This is a big lesson because it bridges the gap between writing simple Python scripts and actually making the Raspberry Pi interact with the physical world. You’ll learn how to turn LEDs on and off using digital outputs, precisely control the position of a servo motor, read values from a potentiometer using the Analog-to-Digital Converter, and smoothly adjust brightness using PWM (Pulse Width Modulation).
I take my time in this video to explain not just how to do these things, but why they work the way they do. Understanding PWM is especially important because it’s a technique we’ll use heavily later in the class when controlling motors, adjusting LED brightness, generating audio tones, and more.
By the end of this lesson, you’ll have a solid foundation in hardware control using the Fusion HAT. These skills are critical as we move forward in the AI on the Edge journey — because no matter how smart your AI code is, it eventually has to do something useful in the real world, whether that’s moving a camera, turning on lights, or controlling a robot.
This lesson marks the point where we shift from just blinking LEDs to building real, useful control systems. The combination of reading sensors (Analog In) and controlling actuators (Servos + PWM) is exactly what intelligent edge devices need to sense and act.
So grab your Fusion AI Hat, hook up an LED, a servo, and a potentiometer, and let’s start giving your Raspberry Pi real physical superpowers!
As always, I strongly encourage you to code along with me in the video. Try different servo angles, change the PWM frequency, and experiment with mapping the potentiometer to different outputs. That hands-on practice is where the real learning happens.
You’re doing great — we’re building something special here. Let’s keep going!
The schematic for the circuit we will be using in today’s lesson if below. We describe it in more detail in the video. The schematic is:

In the video lesson we demonstrated the following programs:
Digital output to blink an LED:
|
1 2 3 4 5 6 7 8 9 10 |
from fusion_hat.pin import Pin, Mode import time LEDPin=17 redLED = Pin(LEDPin,mode=Mode.OUT) while True: redLED.high() time.sleep(.1) redLED.low() time.sleep(.1) |
PWM Example to Control RGB LED Color and Brightness.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
from fusion_hat.pwm import PWM from time import sleep redPin = 5 greenPin = 6 bluePin = 7 redLED = PWM(redPin) greenLED=PWM(greenPin) blueLED=PWM(bluePin) redLED.freq(200) greenLED.freq(200) blueLED.freq(200) while True: for bright in range(0, 101, 1): redLED.pulse_width_percent(bright) sleep(0.01) print(bright) for bright in range(99, 0, -1): redLED.pulse_width_percent(bright) sleep(0.01) print(bright) |
Reading Analog Voltages on the Pi 5 Using the Fusion HAT+
|
1 2 3 4 5 6 7 8 9 10 11 |
from fusion_hat.adc import ADC from time import sleep potPin=0 myPot = ADC(potPin) # A0–A3 on HAT while True: analogIn = myPot.read() voltage=analogIn*(3.3/4095) print("Analog In: ",analogIn,"Voltage: ",round(voltage,2)) sleep(0.1) |
Controlling Servos With the Fusion AI HAT+
|
1 2 3 4 5 6 7 8 9 |
from fusion_hat.servo import Servo # Import the Servo class for controlling servos import time # Import sleep for timing delays panPin=2 tiltPin=3 servoPan = Servo(panPin) servoTilt=Servo(tiltPin) servoPan.angle(0) servoTilt.angle(0) |