We will build an automation System using Raspberry Pi to control a Lamp.

Components and Tools Required:

Raspberry Pi – Model A or B with power supply and SD card

Power Switch Tail II or Sugar Relay

Female to Male Jumper Wire

Raspberry Pi compatible microphone. Either a USB Webcam with mic or a USB sound card with a microphone will do

Speakers for sound output from your Raspberry Pi

Household Lamp

Flat blade screw driver

Hook Up the Components

Connect the microphone or webcam to the Pi USB port

Connect the external speakers to the Pi. You can use the audio out jack or use sound out through the HDMI connection

Connect a black female to male jumper to physical pin 6, a ground pin. Use this GPIO pinout diagram for help

Connect a red jumper to physical pin 16 of your Pi

Jumper Wires attached to Pi

Connect the male end of the red jumper to pin 1 on the PowerSwitch Tail II. Use the flat blade screw driver to loosen the screw and insert the pin into the hole in the side of the PowerSwitch. Then tighten the screw until the jumper pin is firmly attached.

Connect the male end of the black jumper to pin #2 on the PowerSwitch Tail II

PowerSwitch Tail II With Jumpers Attached

Setting-up the Raspberry Pi

There are several guides to purchasing and installing an OS on your Raspberry Pi. Install the latest Raspbian operating system.

You will be working from the command line and doing a bit of copying and pasting so ensure that sshd is enabled. Also ensure that you can ssh into your Pi from your favorite terminal program. Once your Raspberry Pi is configured and booted move on to the next step.

Install Wiring Pi

The script that controls the lamp relies on the Wiring Pi project to switch the GPIO pins high and low. Run the following commands to download and install Wiring Pi.

1

2

3

4

sudo apt-get install git-core

git clonegit://git.drogon.net/wiringPi

cd wiringPi

./build

Creating the light switch Script and Test

Now that the commands to turn pins high and low are installed with the Wiring Pi kit, the next step is to create a script called light switch. Light switch will be called from the Voice Command framework. It will receive a command line argument on or off depending on your instructions. The script evaluates the argument and sets the pin high or low appropriately.

Run the following commands to create a scripts directory

1

2

3

4

cd

mkdir scripts

cd scripts

create the following script as a file named lightswitch

1

2

3

4

5

6

7

8

9

10

11

12

#!/bin/bash

if[$# > 1 ]

then

/usr/local/bin/gpio mode4out

if[["$1"="on"]]

then

/usr/local/bin/gpio write4on

if[["$1"="off"]]

then

/usr/local/bin/gpio write4off

Set the script to be executable with the following command

1

chmodu+xlightswitch

Plug the PowerSwitch Tail II into mains power

Plug the lamp into the PowerSwitch Tail II

Test the script and your configuration by running the script to turn the light on then off

1

2

./lightswitch on

./lightswitch off

If everything is all hooked up correctly you should see your lamp turn on and off.

Install Voice Command

After hearing its keyword or name, the Voice Command will prompt for an instruction by default saying “Yes sir”. It will then attempt to process whatever you say depending on how its configured

At this step you’ll install the Voice Command software. When the setup script runs, it will ask if you wish to install several packages only say yes to dependencies and voice command.

To Install, Execute commands below.

1

2

3

git clonegit://github.com/StevenHickson/PiAUISuite.git

cd PiAUISuite/Install/

./InstallAUISuite.sh

After Voice Command installs it will prompt you to allow it to setup. Choose yes to allow the install script to auto setup. When the setup is complete it will prompt you to press Enter to edit the config file. Press Enter to edit the file and see the next section for configuration.

Configuring and Running Voice Commands.

After pressing Enter you will be offered a file editor to modify the Voice Command setup. Add the following line to the config file, save, and exit.

1

light==/home/pi/scripts/lightswitch...

This line means that when you say light on or light off Voice Command will execute the script /home/pi/scripts/light switch with the argument on or off. This will have the same result as when you ran the script manually.

Use the command line below to launch Voice Command. The -c means to run continuously, -k pi sets the name prompt you will say to get the Raspberry Pi’s attention. The -v causes the program to verify the prompt before going into voice recognition mode.

The -i causes voice command to only process explicit commands listed in the config file. Without this flag voice command searches for answers to words that are not defined as commands on Wolfram Alpha and reads the results out loud.

Finally, the -b0 argument forces voice command to not use filler text before its response.

Hello Ian
I rechecked the code, it does work.
Check if your GPIOS ARE WORKING ALSO TRY TYPING THE CODE INSTEAD OF COPYING.
yOU MIGHT BE GETTING SOME html CHARACTERS IN THE CODE.
iT SHOULD DEFINITELY WORK.