In AI on the Edge Lesson 16, we take a big step forward by combining voice recognition with physical motion. In this project, you will build a voice-controlled pan/tilt camera system. Using simple spoken commands such as “right,” “left,” “up,” “down,” and “quit,” you can move the Raspberry Pi camera in real time. This lesson brings together the Fusion HAT+ servo control, the Speech-to-Text (STT) capabilities we explored earlier, live video streaming with picamera2 and OpenCV, and multithreading to keep everything running smoothly.
The hardware setup is straightforward. We connect two servos to the Fusion HAT+ — one for pan (horizontal movement) on pin 2 and one for tilt (vertical movement) on pin 3. The Raspberry Pi Camera is mounted on a pan/tilt mechanism so it can physically follow your voice commands. We start the camera at a neutral position (pan = 0°, tilt = -20°) and define step sizes so the movement feels responsive but controlled.
The Python code uses two main threads: one for continuous voice listening and another for displaying the live video feed. In the listening thread, we create an STT object and continuously wait for voice input. When a command is recognized, we adjust the pan or tilt angle accordingly and immediately send the new position to the appropriate servo. The main loop captures frames from the Pi Camera, flips them for correct orientation, displays them in an OpenCV window, and checks for the ‘q’ key to exit gracefully.
This project demonstrates several important concepts working together: real-time voice command processing, servo motor control, camera streaming with picamera2 at 1280×720 resolution and 60 fps, and proper use of threading so that listening and video display do not block each other. You will also notice how we use global variables carefully to share the current pan and tilt positions between the threads.
By the end of this lesson, you will have a working voice-controlled camera that you can point anywhere you want just by talking to it. This is an excellent foundation for more advanced projects such as voice-controlled object tracking, security cameras, or interactive AI assistants that can both see and move.The complete code is provided below, along with explanations of the key sections. Feel free to experiment with different step sizes (xDelta and yDelta), starting angles, or even add new voice commands once you are comfortable with the basic version.
Hey everyone, welcome to Lesson 15 of the AI on the Edge series!
In today’s lesson, we take a very important step forward. We finally bring the Raspberry Pi Camera into our OpenCV world so we can capture live video and start building real computer vision projects. Today we learn how to pull live frames directly from the official Raspberry Pi camera using picamera2 and display them smoothly with OpenCV.
This lesson is all about building a clean, reliable foundation. I walk you through how to properly configure the Pi Camera with the modern picamera2 library — setting the resolution to 1280×720, choosing the right format, and pushing the frame rate up to 60fps. Then we bring those frames straight into OpenCV so we can see live video in a window. You’ll also learn why we use RGB888 format and how to organize your code so it stays clean as our projects get more complex.
Getting reliable live video from the Pi Camera is one of those foundational skills that opens the door to everything we’re going to do in this class — face detection, object tracking, color tracking, motion detection, and all the exciting AI projects still ahead. Once you have solid camera access, the real fun begins.
I kept this lesson straightforward on purpose. I want you to have a rock-solid base that you can build upon without fighting technical problems later. By the end of this video, you’ll have a clean, responsive live video stream running from your Raspberry Pi Camera, ready for all the computer vision magic we’re about to add in the coming lessons.
So fire up your Raspberry Pi, grab your camera module, and let’s get that live video rolling! As always, I encourage you to type the code along with me and experiment with it. Change the resolution, try different frame rates, and make it your own.
Are you ready? Let’s dive in!
In today’s lesson, this is the code which we developed:
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
importcv2
frompicamera2 importPicamera2
piCam=Picamera2()
W=1280
H=720
RES=(W,H)
piCam.preview_configuration.main.size=RES
piCam.preview_configuration.main.format="RGB888"
piCam.preview_configuration.controls.FrameRate=60
piCam.preview_configuration.align()
piCam.configure("preview")
piCam.start()
whileTrue:
frame=piCam.capture_array()
#frame=cv2.flip(frame,-1)
cv2.imshow("Camera",frame)
cv2.moveWindow("Camera",0,60)
ifcv2.waitKey(1)==ord('q'):
break
cv2.destroyAllWindows()
print('Program Terminated')
This is the schematic we are using in these lessons:
This is the circuit we will use moving forward in the class
Hey everyone, welcome back to the AI on the Edge series!
In today’s lesson, we’re taking another big step forward in building truly interactive AI projects that run right on our Raspberry Pi 5. We’re going to give our hardware a voice — literally. You’ll learn how to control the brightness of an LED using simple voice commands like “low”, “medium”, “high”, “on”, and “off”.
This lesson builds directly on the speech-to-text skills we learned earlier. Using the Fusion Hat’s microphone and the excellent STT library, we create a system where you can speak naturally to your Pi and it responds instantly by changing the LED brightness. We also bring in Python threading so the voice listening doesn’t block the main program — which is a critical skill as our projects get more complex.
One of the things I really like about this project is how it shows the power of combining AI with real hardware. You’re not just making the LED turn on and off anymore — you’re giving it smooth, adjustable brightness control using nothing but your voice. It’s a perfect example of the kind of interactive, intelligent edge computing we’re working toward in this class.
By the end of this lesson, you’ll have a solid understanding of how to use voice commands to control hardware, how to manage multiple things happening at the same time with threading, and how to create a much more natural and user-friendly interface for your projects.
This is the kind of thing that makes your Raspberry Pi projects feel alive and responsive. Whether you eventually want to control motors, lights, robots, or entire systems with your voice, the techniques you learn in this lesson will serve as a strong foundation.
So grab your SunFounder Fusion AI Hat, hook up that red LED, and let’s get your Raspberry Pi listening and responding to your voice commands like a proper smart device!
As always, I encourage you to type the code along with me in the video, then play around with it. Try adding more commands, change the LED color, or combine it with other sensors. That’s where the real learning and creativity happens.
I’m really excited to see what you build with this one!
This is the schematic we are using, from LESSON #5.
This is the circuit we will use moving forward in the class
In the video, this is the code we developed:
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
fromfusion_hat.pwm importPWM
fromfusion_hat.stt importSTT
importthreading
fromqueueimportQueue
fromtimeimportsleep
redPin=5
redLED=PWM(redPin)
redLED.freq(1000)
stt=STT(language="en-us")
brightness="off"
bNumb=0
running=True
brightQ=Queue()
defblinkBright():
print("Input Thread is Running")
globalrunning
whilerunning:
print("What Brightness: (off, low, medium, high, on or quit: )")
Hey everyone, and welcome back to the AI on the Edge series!
In today’s lesson, we’re tackling one of the most important programming concepts you’ll need as we build more advanced AI and robotics projects — Python Threading.
Up until now, our programs have been pretty linear — they do one thing at a time. But as our projects get smarter and more interactive, we often need several things happening at the same time. That’s exactly where threading comes in. In this lesson, I give you a gentle, practical introduction to threading by creating a program that blinks an LED while simultaneously listening for your commands to change the blink speed — all without one task blocking the other.
You’ll see how to create a separate thread that handles user input while the main program continues blinking the LED smoothly. We also use a Queue to safely pass data between the threads. This is a foundational skill that becomes incredibly valuable later in the class when we need to run voice recognition, camera processing, sensor reading, and motor control all at the same time.
I designed this lesson to be very beginner-friendly. If you’ve never used threading before, don’t worry — I walk you through every line of code and explain why we do things the way we do. By the end of this video, you’ll have a solid understanding of how to launch background threads, manage shared variables safely, and keep your main program responsive.
This lesson is a big stepping stone in our AI on the Edge journey. The ability to run multiple tasks concurrently is what separates simple scripts from real-world intelligent systems that can listen, think, and act at the same time.
So grab your SunFounder Fusion AI Hat, hook up an LED, and get ready to take your Raspberry Pi programming skills to the next level. Once you understand threading, a whole new world of possibilities opens up!
As always, I strongly encourage you to code along with me in the video and then experiment on your own. Try adding more LEDs, change the commands, or combine it with things we’ve learned in previous lessons. That hands-on practice is where the real learning happens.
I’m really excited for you to learn this one — it’s going to make the rest of the class a lot more fun and powerful!
In today’s lesson, this is the code we developed.
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fromfusion_hat.pin importPin,Mode
importthreading
fromqueueimportQueue
fromtimeimportsleep
redPin=17
redLED=Pin(redPin,Mode.OUT)
redLED.low()
blinkDelay=1.0
running=True
blinkQ=Queue()
defblinkTime():
print("Input Thread is Running")
globalrunning
whilerunning:
cmd=input("Input Blink Time in Seconds, or Q for Quit: ")
In Lesson 6, I gave you a homework challenge: build a dimmable LED using a potentiometer. In today’s Lesson 7, we go through the solution together step-by-step.
This lesson is all about taking analog input from a potentiometer and converting it into smooth PWM output to control the brightness of an LED. It’s a very practical project because it teaches you how to read real-world analog values and turn them into useful control signals — skills we’ll use again and again as we build smarter AI-powered projects.
In the video, I walk you through the complete working code. You’ll see how we read the potentiometer value (0 to 4095), convert that raw number into a proper brightness percentage using a bit of math (with a nice logarithmic curve so the brightness feels natural to the human eye), and then send that value to the LED using PWM. The result is a very smooth, responsive dimmer that feels professional.
Even though this seems like a simple project, it’s actually an important stepping stone. Understanding how to read sensors and smoothly control outputs is fundamental to building real AI on the Edge systems — whether you’re controlling motors, adjusting screen brightness, or varying the speed of a robot based on sensor input.
By the end of this lesson, you should have a solid understanding of how to combine the ADC (Analog to Digital Converter) with PWM output, and more importantly, how to think about mapping real-world inputs to useful outputs.
So if you did the homework, great job! If you got stuck, don’t worry — we go through the full solution together. And as always, I strongly encourage you to take the code and make it your own. Try changing the response curve, add multiple LEDs with different colors, or combine it with things we’ve learned in earlier lessons.
This is the kind of foundational hardware skill that will serve you well as we continue moving deeper into the AI on the Edge class. You’re doing great — keep going!
We are still using the schematic from our earlier project.
This is the circuit we will use moving forward in the class
In this lesson, this is the code which we came up with:
Python
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#!/usr/bin/env python3
fromfusion_hat.adc importADC
fromfusion_hat.pwm importPWM
fromtimeimportsleep
importmath
potPin=0
myPot=ADC(0)
redPin=5
redLED=PWM(redPin)
whileTrue:
potVal=myPot.read()# 0 to 4095
writeVal=100**(potVal/4095)-.005
redLED.pulse_width_percent(int(writeVal))
print(potVal,writeVal)
sleep(0.1)
Making The World a Better Place One High Tech Project at a Time. Enjoy!
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.