Integrating Amazon Alexa with a Raspberry Pi allows users to create a voice-controlled assistant, automate smart devices, and interact with Alexa's AI capabilities.
This tutorial will cover:
- Installing Alexa on Raspberry Pi
- Setting up Alexa Voice Service (AVS)
- Using a microphone and speaker
- Controlling Raspberry Pi with Alexa
- Extending Alexa with custom skills
By the end of this guide, you will have a fully functional Alexa-powered Raspberry Pi.
1. Prerequisites
Before proceeding, ensure you have the following:
Hardware Requirements
- Raspberry Pi (Pi 3, 4, or 5)
- MicroSD card (16GB or larger)
- Microphone (USB or 3.5mm)
- Speaker (USB or 3.5mm)
- Internet connection (Ethernet or Wi-Fi)
Software Requirements
- Raspberry Pi OS (Latest version)
- Amazon Developer Account (Required for Alexa integration)
- Python 3 and Git installed
- Alexa Voice Service SDK
2. Setting Up Raspberry Pi
Step 1: Update Raspberry Pi
Ensure your Raspberry Pi has the latest software updates.
sudo apt update && sudo apt upgrade -y
Step 2: Install Dependencies
Alexa requires certain libraries and packages.
sudo apt install git python3-pip portaudio19-dev flac -y pip3 install pyaudio numpy requests
Step 3: Configure Audio
Check available audio input and output devices.
arecord -l # Lists microphones aplay -l # Lists speakers
If using a USB microphone, set it as the default:
sudo nano /etc/asound.conf
Add the following lines:
pcm.!default { type asym playback.pcm "hw:1,0" capture.pcm "hw:1,0" }
Save the file (CTRL+X → Y → Enter), then reboot:
sudo reboot
3. Register Your Raspberry Pi as an Alexa Device
Step 1: Create an Amazon Developer Account
- Go to Amazon Developer Console.
- Sign in or create an account.
Step 2: Create an Alexa Voice Service (AVS) Device
- Navigate to Alexa → Alexa Voice Service → Get Started.
- Click Create Product and enter:
- Product Name: RaspberryPi_Alexa
- Product Type: Application with Alexa built-in
- Product ID: raspberrypi-alexa
- Click Next and configure security settings:
- Allowed Origins: http://localhost:3000
- Allowed Return URLs: http://localhost:3000/authresponse
- Click Finish to save.
Step 3: Get API Credentials
- Go to Security Profiles.
- Click Create Security Profile and note:
- Client ID
- Client Secret
- These credentials will be used to authenticate your Raspberry Pi.
4. Install Alexa on Raspberry Pi
Step 1: Clone the Alexa SDK
git clone https://github.com/alexa/avs-device-sdk.git cd avs-device-sdk
Step 2: Run the Setup Script
sudo bash setup.sh
This script will install dependencies, configure settings, and initialize Alexa.
Step 3: Authenticate Alexa
Once the installation is complete, start the authentication process:
bash startauth.sh
Follow the on-screen instructions to log in with your Amazon account.
5. Running Alexa on Raspberry Pi
Once authenticated, start Alexa:
bash start-alexa.sh
Test it by saying:
Alexa, what’s the weather today?
You should hear a response.
6. Automating Alexa on Startup
To make Alexa start automatically on boot:
sudo nano /etc/rc.local
Add the following line before exit 0:
/home/pi/avs-device-sdk/start-alexa.sh &
Save the file (CTRL+X → Y → Enter) and reboot:
sudo reboot
Now Alexa will launch on startup.
7. Controlling Raspberry Pi with Alexa
Step 1: Install Flask and Flask-Ask
Flask-Ask is a Python framework for creating Alexa skills.
pip3 install flask flask-ask
Step 2: Create a Simple Alexa Skill
Create a Python script:
nano alexa_pi_control.py
Add the following code:
from flask import Flask from flask_ask import Ask, statement import os app = Flask(__name__) ask = Ask(app, "/") @ask.launch def launch(): return statement("Raspberry Pi is ready to receive commands.") @ask.intent("TurnOnLEDIntent") def turn_on_led(): os.system("echo 'LED ON'") return statement("Turning on the LED.") @ask.intent("TurnOffLEDIntent") def turn_off_led(): os.system("echo 'LED OFF'") return statement("Turning off the LED.") if __name__ == '__main__': app.run(debug=True)
Save and run:
python3 alexa_pi_control.py
This script allows Alexa to send on/off commands to Raspberry Pi.
8. Extending Alexa Capabilities
Adding Smart Home Devices
To control smart lights, plugs, or sensors, integrate:
- Home Assistant (home-assistant.io)
- MQTT broker (for IoT devices)
- IFTTT (for web automation)
Voice Recognition with Wake Word
To use “Alexa” as a wake word, install WakeWord Agent:
git clone https://github.com/alexa/alexa-avs-sample-app.git cd alexa-avs-sample-app bash automated_install.sh
9. Troubleshooting
Alexa Not Responding
- Check microphone and speaker:
arecord -l aplay -l
- Ensure AVS credentials are correct.
- Restart the service:
bash start-alexa.sh
Device Not Recognized in Alexa App
- Ensure the Amazon Developer Console has the correct security settings.
- Reauthenticate:
bash startauth.sh
By integrating Amazon Alexa with Raspberry Pi, you can create a custom voice assistant that controls smart devices, answers queries, and runs scripts.
Whether you're automating your home, developing voice-controlled projects, or enhancing Raspberry Pi functionality, Alexa provides a powerful and flexible solution.