raspberry pi

Raspberry Pi and Alexa Based Home Automation Project


Raspberry Pi and Alexa Based Home Automation- In this article, we will be making a home automation system using Raspberry Pi 3 and Alexa. A relay module will be interfaced with the Raspberry Pi which will be controlled with the help of a voice command. In this project we will be controlling a single relay using voice commands, the code can be modified easily to control more relays. The whole system is connected with the WiFi. There is no physical connection between the Raspberry Pi and Alexa device, this makes the Alexa Echo Dot completely portable. You can keep the Alexa device near to you on a table, or somewhere else. Then all you need is to say the desired command and then the Raspberry Pi will do its job. The same concept can be used to control a Robot using Raspberry Pi and Alexa.

Let’s have a look at the component that we will need for making this project.

Material required for Raspberry Pi Alexa home automation:

Amazon Purchase Links:

12v SPDT type 4-channel relay Module:

8 channel Relay Module

Echo Dot or Echo, Alexa

SD Card Module

8GB Micro SD Card

Micro SD Card Adaptor

Micro usb card cable

Micro USB Cable

Raspberry Pi

raspberry pi 4 4gb kit

Wireless Keyboard and Mouse for raspberry pi:

Night vision Camera for Raspberry Pi:

Oled HDMI touch display for raspberry pi:

TOP10 Best Raspberry Pi Kits

Raspberry Pi and Alexa


Other Tools and Components:

Super Starter kit for Beginners

Digital Oscilloscopes

Variable Supply

Digital Multimeter

Soldering iron kits

PCB small portable drill machines

*Please Note: These are affiliate links. I may make a commission if you buy the components through these links. I would appreciate your support in this way!


Steps for getting started with our home automation:-

  • Download and Install Rasbian on SD card
  • Enable SSH and Wi-Fi without a monitor
  • Download Putty and access pi3 over SSH.
  • Download putty and access pi3 over SSH
  • Download and run IoT program from link in description.
  • Control Pi attached relay with voice command from Alexa.

 Connection of Raspberry PI3 and Relay:

  1. 5v power of pi3 which is pin four on the board is connected to the relay power pin.
  2. GND pin which is pin six on the board to the ground pin of the relay.
  3. GPIO 4 pin which is pin seven on the board to the relay signal pin.
Raspberry Pi and Alexa
Fig#2 Raspberry pie interfacing with relay module

Getting Started with Raspberry pie and Alexa Project:-

  1. Take mini SD card and connect it to your pc to format and flash it with Rasbian. So we will take the SD card and put it in the SD card reader
  2. After putting in the computer go to SD card drive right click on it to format the SD card in the FAT (default) as shown below.
Raspberry Pi and Alexa
Fig#3 Formatting SD card
  1. Now the formatting is successful press ok and now we are good to go for installing Rasbian.
  2. Now we will go to the website and download Rasbian as per your system. The file will be downloaded in the zip file.
Raspberry Pi and Alexa
Fig#4 Raspberry pie Website


  1. Next is to install win32 disk imager click on the link and wait for few second then save it locally.
Raspberry Pi and Alexa
Fig#5 Win32 disk imager
  1. Once both files are download go to the windows download folder and unzip the Rasbian folder.
  2. Next is to open the unzip folder and search for the image file with the .img extension.
  3. We will install the win32 disk imager software in our pc.
  4. When successfully installed Click the Disk imager and open the Rasbian img file in it as shown below.
Raspberry Pi and Alexa
Fig#6 Rasbian Image


  1. It will take 20-30 minutes and then when the image is extracted in to the sd card then we need to add file named “ssh” and “wpa_supplicant.conf”.
  2. In wpa_supplicant.conf add the password and SSID Wi-Fi name.
  3. Don’t worry the file is in the description you can simply download both files and copy it in the SD card drive and you are good to go.
Raspberry Pi and Alexa
Fig#7 SH and WIFI Password File
  1. Take the SD card out of the adopter insert it in your raspberry pie 3
  2. Now we are going to connect our raspberry pie to the power source. And boot in for 10 second.
  3. In windows go to run and type run or simply press window key + R.
  4. Type cmd and press enter as shown below.
Raspberry Pi and Alexa
Fig#8 Command Prompt

  1. When the command prompt is open type in “arp –a”. This will show up several Ip address on the screen the one physical address that starts with b-28 usually for raspberrypie3 note it down because it is our raspberrypie3 Wi-Fi Ip address on your network and we will need these to login into our pi3.
Raspberry Pi and Alexa
Fig#9 IP Configuration for Raspberrypie3
  1. Next step is to download the putty software on your system from this link.
Raspberry Pi and Alexa
Fig#10 Putty Software Website
  1. When the software is downloaded open it and install it which will show us this interface.

Raspberry Pi and Alexa

  1. Enter your Ip address in the putty software as shown and press ok.
Raspberry Pi and Alexa
Fig#12 Putty Interface


  1. Now in command prompt write down the default username as pi and default password that is raspberry.
  2. Congrats now you are logined in the raspberry pie and form this command prompt you can do whatever you want to do.
Raspberry Pi and Alexa
Fig#13 raspberry pie login
  1. Write down “sudo raspi-config” in the prompt and then move to “Interfacing options” and allow VNC setting as shown in below steps.


Raspberry Pi and Alexa

Raspberry Pi and Alexa
Fig#14 Interfacing with VNC

  1. At this point VNC is enabled as shown by command prompt.
  2. Now it is your choice to download and install client VNC which will allow you to have a look at the raspberry pie interface. To download this click here in your system.
  3. Attach VNC client to Raspberry pi3 device by using address copied earlier.
  4. Now Login VNC user pi and password raspberry as used before.
Raspberry Pi and Alexa
Fig#15 VNC Viewer
  1. It will give you a warning but continue and we are in to raspberry pie 3 desktop and we can turn on and off various setting without command prompt.
  2. Now press sudo apt-get update it will ask for permission press y or yes. It will update and upgrade your raspberry pie with latest data using sudo apt-get upgrade  this will take some while so be patient after running these two commands the raspberry pie is at its best to work.
  3. You will need to download the IOT-Pi3-Alexa-Automation-master. you will see that the software will download the zip file and to un zip in press command “unzip nameofile.zip” and press enter.
  4. Next press cd and folder name of the image and press enter “cd IOT-Pi3-Alexa-Automation-master” as the command is completed.
  5. Now enter “sudo pip install virtual env” command prompt to install virtual env on your raspberry pie.
  6. Press in “virtualenv ipaa-env” into your command prompt to make a virtual background for your project
  7. Press in ipaa-env/bin/activate into your command prompt to trigger your project’s virtual environment,
  8. Insert command “sudo python3 RPi_name_port_gpio.py” to execute Pi IOT program. What’s in this python code, I will share it below.

Raspberry Pi and Alexa

Raspberry Pi and Alexa
Fig#15 command execution
  1. Power up the Alexa and give voice command to Alex to discover devices “Alexa discover devices” it will find your system and notice your Raspberry Pi 3 as an IoT device.
  2. “Turn on the office” give this command to turn on the load or simple relay
  3. Turn off the office” give this command to turn off the load or simple relay
Raspberry Pi and Alexa
Fig#15 Raspberry pie with Alexa

IMPORTANT:- You can change the code and say anything for switching relay simply make changes in python code provided in zip file. Below are the files and the codes they have.