Week 6 – Alexa Skill – Josh Milkins & Richard Channing

In order to enable more advanced functions and voice commands other than “alexa, turn (on/off) (device_name)” We need to create a custom alexa skill.

This is done by saying a command to alexa which then gets processed by the amazon alexa cloud service through the wifi router. A request is then sent to a heroku app over http (internet), this app then forwards the request from a windows websocket server to a windows socket client on the Node MCU. When the  Node MCU recieves this  request, it will set the requested relay high.


The hardware and circuit diagrams are exactly the same as blog post 5

First I had to setup a heroku app, this gave me a URL that i could paste into the arduino code in order for the app to send requests to the Node MCU.


Here is the code;


I then needed to build an alexa skill,

first i gave the skill a name and invocation name (lightservice)

The invocation name is what will be said to alexa before asking it a command. For example “alexa, ask lightservice to turn on section one main lights” this is so alexa knows which skill it needs to use to request the command.


I then need to make an intent which is essentially a command and under the intent i need to type in some sample utterances which is what a person would say to alexa in order to request an action. Mine were “turn on all main lights” and “turn section one main lights on”


Because there are quite a number of possible commands that could be said to alexa, (6 sections, 2 states & 2 types of light) instead of listing all of these utterances, i can use slots to handle more than one option, they are parameters that get filled in automatically, when a command is given, it will look for the values of the slots and replace the variable words in the utterance’s.

The first slot is the different sections, the options are ‘one’ through to ‘six’  and ‘all’.

The second slot is the state, this is  either ‘on’ or ‘off’.

The third slot is the type of light, this will determine whether it’s a ‘main’ light or ‘wall’ light for that particular section.

By double clicking on a word in the utterance it’ll give you the option to change it to a slot. In this case i changed the word ‘one’ to ‘list_section’ the word ‘main’ to ‘list_type’ and the word ‘on’ to ‘list_state’


I then need to set an endpoint for the alexa skill. This is HTTPS and uses the heroku URL used in the arduino code.


The alexa skill is now finished, i just have to save and build it.

The next step is to test the skill using the Alexa skills kit built in alexa simulator. You just type of speak a command through a microphone and it’ll act just as a physical echo would, giving verbal and written feedback as well as the JSON code being input into the echo and output from the echo.

This however is where it failed giving me a ‘I am unable to reach the requested skill’ response and I did not find out how to fix this.


Week 5 – Controlling Multiple Devices – Josh Milkins & Richard Channing

Continuing the use the emulated WeMo device we used an 8 channel relay module in order to control the multiple lights that would need controlling in a pub/bar environment.

We were having some trouble with the NodeMcu Lua V3 as mentioned in the previous post so we bought a more expensive MCU which had a different breakout board but the same ESP8266 wifi module (pictured below). This proved to be much more reliable.



Home Automation Alexa NodeMCU_bb






Because the MCU took a 5v USB power source and regulated it to 3.3v on board, we couldn’t use the VCC pin to power the relay module which required 5v. In order to continue with the above experiment we had to use a laptop to power the MCU and an external 5v power supply to power the relay module.

Later we discovered we can use a bi-directional logic level converter which is a small device that safely steps down 5V signals to 3.3V and also steps up 3.3V to 5V at the same time.

We bought the sparkfun module where each level converter has the capability of converting 4 pins on the high side to 4 pins on the low side with two inputs and two outputs provided for each side. The board needs to be powered from the two voltages sources (high voltage and low voltage) that the circuit is using. High voltage (5V for example) to the ‘HV’ pin, low voltage (3.3V for example) to ‘LV’, and ground from the circuit to the ‘GND’ pin.


The Fritzing diagram now looks like this;


Week 3 – Integrating Alexa – Josh Milkins & Richard Channing

The Brains

The WIFI enabled MCU in question is the NodeMcu Lua V3 – pictured below


This is not an arduino board, nor does it use the same ATMega328 chip that arduino uno’s use. But it can be flashed (programmed) via the arduino IDE using the same version of Javascript. much like arduino, it has a built in serial FTDI interface to program the MCU. It has 9 GPIO (general purpose input/output) which are the pins that can be programmed via the arduino IDE. It runs at 3.3v as opposed to 5v and has built in esp8266 WIFI chip.


Alexa & The Internet of Things

In this project we are also using Alexaan intelligent personal assistant developed by Amazon Lab126 (amazon’s research and development department), made popular by the Amazon Echo and Echo-Dot.

Alexa is capable of voice interaction, music playback, making to-do lists, setting alarms, streaming podcasts, playing audiobooks, and providing weather, traffic, and other real time information. Alexa can also control several smart devices using itself as a home automation hub. We will use on this project, the Echo-Dot that allows users to activate the device using a wake-word such as “Alexa”.

In the home automation environment, Alexa can interact with several different devices such as Philips Hue, Belkin Wemo, SmartThings among a few more. In our case, we will emulate the WeMo.

What is WeMo?

WeMo is a series of products from Belkin International Inc. that enables users to control home electronics from anywhere. The product range includes a switch, motion sensor, Insight Switch, light switch, camera and app. The WeMo Switch can be plugged into any home outlet, which can then be controlled from an IOS or Android smartphone running the WeMo App, via home wifi or mobile phone network. We will be emulating the smart switch and will control it over wifi via alexa.


How the Emulation Works

Okay so this isn’t the most interesting of topics but it’s necessary to understand exactly how alexa talks to the arduino.

The WeMo devices use UPnP to perform certain functions over the network. The device detection function starts out with the Echo or Dot searching for WeMo devices using UPnP. The device then responds to the Dot with the device’s URL using HTTP over UDP. The Dot then requests the device’s description using that HTTP URL. The description is then returned as an HTTP response. The actual “on/off” functionality of the WeMo devices is simpler since the Dot already knows about the device. The Dot simply connects to the WeMo over the HTTP interface and issues a “SetBinaryState” command. The WeMo then obliges and returns a confirmation via HTTP. See the Echo/Dot Communication diagram below.

Glossary of terms;

UPnP – Universal Plug and Play is a set of networking protocols that permits networked devices to seamlessly discover each other’s presence on the network and establish functional network services for data sharing and communications.

URL – A Uniform Resource Locator is a reference to a web resource that specifies it’s location on a network and a mechanism for retrieving it.

HTTP – The Hypertext Transfer Protocol is the foundation of data communication for the World Wide Web.

UDP – With User Datagram Protocol, computer applications can send messages to other hosts on an Internet Protocol (IP) network.



Week 1 – Research – Josh Milkins & Richard Channing

The Our Idea

Our idea is to decrease energy usage in a pub/bar environment. We intend on doing this by using an interactive service to turn off lighting in unoccupied areas of the pub/bar.

In order to make the service interactive we would use an amazon alexa to communicate with a wifi enable MCU (micro controller unit)

Testing Out the Context

We visited the Warwick Arms, Clutton to test out how our idea would translate into a real word application. We looked at the user interaction (UI) and user experience (UX) to establish whether this would persuade people to conserve energy by turning off lights that aren’t needed. We also looked at how much energy this would save and what benefit this would have.

Different sections withing the pub:


Section 1 – Snug Room

Number of ceiling lights: 13

Number of wall lights: 4


Section 2 – Breakfast Area

Number of ceiling lights: 13

Number of wall lights: 5


Section 3 – Main dining area

Number of ceiling lights:20

Number of wall lights:4


Section 4 – Bar seating area

Number of ceiling lights:9

Number of wall lights:7


Section 5 – Main Foyer & drinking area

Number of ceiling lights:12

Number of wall lights:9


Section 6 – Pool room

Number of ceiling lights:4

Number of wall lights:7

Floor Plan;

Floor plan.png

All of these lights are on from open until close which uses quite a large amount of energy. In total there are:

Ceiling – 71 light

Wall  – 36

Below shows the current energy consumption:

Current Energy use chillwortharms

As you can see there is quite a large amount of energy being used each day, even without considering the cost of using this much energy it isn’t sustainable. Going forward we shall be aiming to make this much more cost and environmentally friendly.

Below is a video showing the user interaction of the concept and how it would work in reality.

Week 4 – Combining a Touch Sensor and a PIR Motion Sensor – Josh Milkins

We decided that the most logical and useful application of our two sensors was an intruder alarm.

The alarm consisted of a PIR sensor which was used to detect movement in a room, it also had a touch switch which could be used to reset the alarm once is had been tripped. When the alarm is tripped, LED’s flash and a buzzer is sounded to deter intruders from continuing.

This was the fritzing diagram which shows all of the components used;

fritzing combined

Photo Capture Alarm sys

And the code;

The debouce used in the previous weeks code was also used in this one and this code also used clock cycles to flash the LED instead of;

digitalWrite(LED_BUILTIN, HIGH);
digitalWrite(LED_BUILTIN, LOW);

We used;

if (alarm){
unsigned long currentMillis = millis();
if(currentMillis – previousMillis > interval) {
previousMillis = currentMillis;
if (ledState == LOW)
ledState = HIGH;
ledState = LOW;

This allows us to put more parameters into the if statement like seeing whether the led is currently high or low.

The video shows that when i put my hand in front of the sensor it will trigger although we found the motion sensor has a very wide detectable angle of 170 degrees and so it was hard to find position that didn’t trigger it.

Week 2 – Capacitive Touch Sensor – Josh Milkins

The sensor has two outputs, an analogue output that is dependent on how strongly a touch is detected, or a digital output that will go high if touch is detected above a threshold set by the modules potentiometer.

The example program below by hobbycomponents.com reads the status of both sensor outputs and outputs ‘TOUCH DETECTED’ to the serial port when the sensor detects it being touched.


I wired up the breadboard to work with the code with the digital output of the sensor going to pin 2 on the arduino and the analog output of the sensor going to pin A0 on the arduino


This is the flowchart for the Sudo code;

serial monitor flowchart


And the fritzing breadboard layout;

Touch fritzing

Week 1 – Capacitive Touch Sensor – Josh Milkins

I have been given the capacitive touch sensor to research.

The PCB components consist of:

  • 2x 100kohm resistors
  • 2x 1kohm resistors
  • 1x 10kohm resistor
  • 1x 150ohm resistor
  • 1x KSP13 Darlington transistor
  • 1x LM393 Dual differential comparator
  • 2x LED’s
  • 1x 100k Potentiometer

1 Analogue out
3 VCC (+5V)
4 Digital out


Above is a schematic of the PCB


When looking more in depth into the components I found the datasheets of the 2 main components;

The lm393 Dual differential comparator

The ksp13 Darlington transistor