Alexa for Home Automation

Using a Wifi-connected IoT board and Amazon’s Alexa this project controls a series of lights and receive data from various sensors. This project requires programming in JavaScript for the Alexa skill and C++ for the Photon. The lights and sensors are connected to the IoT Photon board through a breadboard.

Name

Brandon L.

Area of Interest

Software Engineering

School

Leland High

Grade

Incoming Senior

Reflection

Reflection

At BlueStamp, I learned a lot from hands-on projects and documentation. Even with the highly trained faculty leading me through problems and issues in my modifications and milestones, there was a lot of room for me to decide the next step and fix my own issues. I learned subjects from Arduino programming to circuitry and using components on my breadboards. Learning to apply my own struggles to the world of engineering meant that my milestones came out more meaningful and exciting. I enjoyed connecting with my peers and listening to what they had to offer in terms of helping me advance my engineering career.

Main Project: Final Modification

Final Milestone

 

Since all of my previous milestones ended up being less hardware oriented, I decided to shift my project and take a more physical approach to my next modification. Using others’ opinions, I went for automated blinds. I wanted Alexa to be able to open the blinds to a certain degree and also tilt them from side to side with no user interference. To achieve this, I mounted a stepper motor onto the blinds and also created a spool for the blinds to wind around. I also had a servo motor to angle the blinds precisely. However, there were a lot of issues I unexpectedly ran into.
1. Mounting a Spool

The stepper motor is flat headed, which means that there is a way to screw on mounts. However, the motor never actually came with any mountable pieces. This difficulty led me to try and create my own spool which could be easily mounted with glue onto the stepper motor. I had to learn to drill and saw for this part, and with a lot of filing I came out with a slightly cylindrical spool that seemed to spin along with the motor with enough glue.

However, the mount still came out with issues. The hot glue was not enough to keep the weight of the blinds from tearing the spool off. Even worse, the filing meant that the spool became thin and brittle. This led to cracking and hot glue spilling out. Finally, my spool also had an issue regarding the string. The string would wind between the motor and spool, stopping any motion from actually happening. All these problems added up and came together, meaning that this wooden attempt was a bust.

2. Programming the Stepper Motor

The stepper motor also had a strange programming kink. To actually control the motor, 4 ports of my Photon were in use. Each one sent output signals in a pattern so that the stepper motor eventually spins. I did my best to program the motor to spin at 100 rpm, but it ended up spinning at around 10 or even 5 rpm. The spinning was barely noticeable, just like the issue.

The code shows the issue. The ports need to be ordered 1,3,2,4 instead of 1,2,3,4 like traditional human practice. This issue kept me busy for an entire day as I tried to find out what could be slowing down my stepper motor. This was probably one of the worst issues that eventually led to me not finishing this modification.

Main Project: Modification One

After Milestone 2, I had to think about additional features that I could add to Alexa’s skills. I thought about a wireless keyboard, an automated coffee maker, blinds, and a tv remote. For this particular milestone, I decided to create a TV remote. By using an IR light and receiver, I was able to read the different frequencies of each button on the original remote and then map them into my Particle code. The IR light then transmits a constant frequency of 38kz in certain time intervals listed in an array. Different arrays of time values are used to mimic different buttons on a TV remote(as shown in the first GitHub Gist), meaning that each button needs its own array.

IR Arrays

Circuiting/Wiring

Modified Photon Code to Transmit IR

Code
There were a lot of issues that had to be resolved when finishing this milestone. The first was the limitation of Particle libraries and the lack of working functions that I could use to transmit the IR codes in the first place. I tried to use only the encoded NEC code with a function sendNEC() which takes in one hex code and a bitrate to transmit an entire signal. However, I never got this function to work. I instead turned to sending raw array inputs which proved to take a longer time to send but eventually got my signal across. The only problem with the timing is the projector. For the projectors that I had to test my remote on, the turn off sequence required two taps of the off button. This meant that I needed to send two signals almost back to back(in the span of 1.5-2 seconds since the “Are you sure you want to turn off?” screen stayed there for that long). For my particle, sending one signal took a long time to cool down and therefore required at least 3-4 seconds between transmissions. I solved this through Amazon’s Web Services to make Alexa send two back to back signals which somehow fixed the issue. By sending multiple commands through, I tricked the Particle to start the transmission again one second after the first one went through. Overall, this milestone took a while to achieve, from brainstorming to getting parts to eventually running into IR light issues. After this, I plan to start tinkering with the servos and configure them for the blinds that I have coming in.

Main Project: Milestone Two

Milestone 2

temperature-board_bb
LED Circuit DiagramThere are two of these on the board, one red and one green.
Milestone 2 was a lot easier to achieve, mostly since the code was already uploaded to Alexa and the prompts were programmed in. All I really needed to do here was to plug in the temperature sensor correctly and update the libraries. Coming from checkpoint one, I thought that I’d need to test and change the firmware code entirely. However, the only problem that I found was a missing resistor connecting the ground and data pins. The given link gave a misleading diagram that I first used and might have been the reason behind my initial failure. However, using the circuit diagram that I found on the sensor website, the test program that prints temperatures through the serial monitor started to work. The next step was to include libraries. At the start, I only moved the DHT.h and DHT.cpp libraries into the same src folder. However, this only made the code more buggy. After reading the documentation surrounding the IDE and how to use it, I found out that the libraries can be downloaded using a tab in the Particle IDE that included numerous Arduino libraries. I then flashed the uncommented Alexa code and then got the entire circuit to work. Humidity and temperature can now be recognized by Alexa!

Source code for Milestones 1 & 2 can be found here.

Main Project: Milestone One

Milestone 1

screen-shot-2018-06-15-at-4.35.10-pm
LED Circuit DiagramThere are two of these on the board, one red and one green.
Checkpoint one was finishing the LED wiring and getting them connected to Photon and eventually Alexa. With a lot of work, I eventually got both lights to work. I used basic LED circuits to connect resistors and the diodes. I also used the code provided here. The Github file contained code for both Amazon Lambda and the Photon board. During this programming process, two big issues arose. The first problem focused on the Alexa intent files, which were outdated and needed updating. I had to recode the Node.js files which included the Sample Intent and then continued to individually type in each Sample Utterance. The other issue was about the Alexa to Lambda to Photon connection. At the beginning, I had to switch out all the ports in the firmware and the Lambda code. Even after that, I still had errors when trying to trigger the LEDs. It turns out that the code activating the temperature sensor was conflicting with my LED code. After deleting the DHT files and the Adafruit sensor libraries as well as the actual firmware code surrounding the temperature and humidity, everything worked smoothly.

Starter Project

My starter project was the MintyBoost phone charger. The charger works by taking 2 AA batteries and running them through multiple resistors, some ceramic and electrolytic capacitors, a diode, and a power inductor. The resistors decrease current while the capacitors store energy or charge. The diode and power inductor are mainly present for efficiency purposes. The PCB also includes a boost converter, which increases voltage while decreasing current in order to reach the 5V needed to charge up a phone(hence the name). Putting these all together took soldering work and the ability to read resistor/capacitor values. I had to replace one capacitor with another one of higher voltage limit, which ended up working fine.

Leave a Comment

Start typing and press Enter to search

Bluestamp Engineering