Saturday, October 29, 2016

Launitor - Laundry Monitor

The LED and button on the left is for my washing machine, the LED and button on the right is for my dryer


Launitor - a combination of 'laundry' and 'monitor'...ok, so maybe it's a silly name, but it's nice to name your projects, and that's all I've come up with at the moment.

At the Jamreb household, our laundry machines are in our garage. They were purchased many years ago, and they were cheap. They don't give any kind of notification when they are done. Worse, our dryer is not working too well at the moment. We have to run it 3 times before our clothes are fully dry.

I don't know about other people, but sometimes we forget to move the laundry from the washing machine to the dryer. If you've ever done this, you know it's not pretty. The clothes get all nasty smelling and need to be washed all over again. We also forget about the clothes when they're in the dryer sometimes, which also ends with unpleasant results.

I remember seeing a few laundry monitor devices on one of my favorite sites, Hackaday.com. Well, I wanted to build one of my own and start saving water/energy/time/money! But first a little planning...


Requirements
As usual, there were some requirements I had:
  • It should be portable for if/when we get a new washer/dryer
  • No permanent changes/modifications should be made to the machines
  • Should be cheap
  • Should require as little user-intervention as possible
  • Easy to use, and have visual cues as to what's going on with them

1 of my challenges
When I first started this project, I was using an Arduino and trying to use some cheap piezo elements from Sparkfun to detect the vibrations of the washer/dryer. It seemed to have worked o-k, but the piezo wasn't quite sensitive enough. Also, I had problems with the wires breaking right off of the piezo too easily when working with them. And I had to tape them real tight to the washer/dryer to get them to pick up the vibrations of the washer/dryer. Lastly, when removing the tape from them (to bring back into my 'lab'), it tended to damage some of the film on the piezos.

After giving up on the piezos, I came across these cool little Adafruit triple-axis accelerometers. It took me a while to figure them out and how to use them. Thankfully there is a great little tutorial on Adafruit's website for them though. So I read through the tutorial several times, and finally was able to get them working.

Once I had the accelerometers working (enough), I then switched over from the Arduino to Adafruit's Huzzah ESP8266 breakout board. This would allow me to IoT-enable this project a lot simpler and a lot cheaper than using an Arduino and a Wi-Fi (or Ethernet) shield.

Throughout the course of development, I ran into many issues/problems along the way and learned a lot. If you want to know about the challenges/problems that I ran in to (and how I overcame them), check out my Laundry Monitor challenges post.


So how does this thing work, anyway?
This is a very simple device to use - when nothing is going on, the LEDs are off. If it detects enough vibrations in a certain amount of time (both amount of vibrations and time are easily adjustable in code), it starts blinking the corresponding LED to visually show that the washer (or dryer) is running. When it realizes that the machine is done running, it turns the LED solid, and sends you an email. If you have the option enabled in the code, it will keep sending you an alert via email every X (also adjustable in code) amount of minutes. After you remove your clothes, just push the corresponding button to reset it so that it will start watching for the next load!

Just a quick note - if you decide to do this project, keep in mind that you will most likely have to 'calibrate' the sensitivity for your own washer/dryer. This involves adjusting 1 or both threshholds and testing. And maybe changing some of the counting/timer constants in the code. (I explain this more the code's comments)

Last photo - this just shows the final placement of the accelerometers on my washer and dryer:




Below are some links for you to use if you want to make your own Laundry Monitor. The various Fritzing files are so you can see how to hook everything up. The bill of materials gives you a complete list of parts, including pricing, and direct links to the items:

Arduino code on GitHub
Fritzing file (actual .fzz)
Fritzing file, exported to .png image
Fritzing file, exported to .jpg image
Fritzing file, exported to .pdf file
Bill of Materials (Open Office) 
Bill of Materials (Excel)

There's no proper schematic because I'm being lazy again. Between the 'Bill of Materials' file and the Fritzing file however, you should be able to make your own. ;)


Cool, I want to build one - what do I need, and what do I need to do?

Note 1 - I'm not going to go into every little detail of what you need here. This list is basic and is just a high-level overview. It also assumes you have at least a little experience in soldering and necessary hardware to attach the sensors to your washer/dryer and the rest of the electronics to something (like a wall). Lastly, it assumes you have basic electronics stuff like wire and wire strippers.

Note 2 - This list isn't necessarily in chronological order

  1. About $40 depending on what you have already, and how you 'mount' the sensors to your washer/dryer. And how you 'mount' the enclosure if you use one.
  2. Check out the BOM (linked above), and figure out what you need to buy and what you already have. Note - if you don't have an FTDI cable (like this) to program the Huzzah, you'll need one of those too (or some other way of programming the Huzzah)
  3. Sign up for a free account at smtp2go
  4. Solder everything together if you're brave, or breadboard it 1st for testing/calibration and then solder everything together
  5. Update the sketch to use your own Wi-Fi, IP, email, (encoded) smtp2go credentials
  6. 'Calibrate' the sensitivity of the accelerometers you're using for your washer/dryer in the Arduino sketch

Of course, I'll be happy to answer any questions about it - just ask in the comments section!


Lastly, here's a quick video of mine in action:





Thanks for visiting!

Launitor - Laundry Monitor - Challenges

As I mentioned in my main post about my Laundry Monitor project, I had a lot of issues/problems  along the way. In this post, I'm sharing with you most of those problems.

Ok, let's jump in:


Challenge/problem #1 - I wanted to use just an ESP8266 module instead of an Arduino + ESP8266 with piezos
I learned that the ESP8266 has only 1 analog (ADC) pin, and if you have the ESP-01, it's 'hard to access'. I needed 2 analog pins because I needed to interface with 2 piezos (1 for the washing machine, 1 for the dryer). I did come across this cool little device, but it seemed like it would be a lot of trouble though. This whole challenge was going to be too much for me, so I abandoned the idea of just using a single ESP-01 module. I decided to go with an Arduino + ESP8266 (for Internet/network connectivity)



Challenge/problem #2 - Another problem with working with the piezos
If you read my main post, you'll know that I had a couple issues with the piezos. There was another problem that I didn't mention in that post. During the beginning of my developing this project, I would test things with my Arduino plugged into the USB port of my computer. However, when I would move everything to my washer/dryer to test without a computer (so when the Arduino ran 'standalone'), the piezos would behave strangely. They basically seemed like they weren't sensing any vibrations. If you want to know more, I posted about this problem on the Arduino forum:
http://forum.arduino.cc/index.php?topic=375935
In a nutshell, I tried several things - such as changing voltages, power supplies, using the AREF pin on the Arduino, etc with the help of the good people at the Arduino forum. Additionally, I was having problems also because of a loose resistor from moving things around too much. Eventually I just decided not to use piezos.



Challenge/problem #3 - 2 I2C devices with the same address?
Ok, this wasn't really a challenge or a problem so much, but I wanted to mention it briefly. When you're using I2C devices (like the accelerometers I used), you can't have 2 devices with the same address. With the particular accelerometers I was using (the Adafruit LIS3DH Triple-Axis accelerometers), you can change the address of it in hardware by connecting 'SDO' to 3.3V. This changes the address from 0x18 to 0x19.



Challenge/problem #4 - Button debouncing
There is some button debouncing of course because this project has buttons. However, when I had a delay(250); at the end of the sketch, the buttons didn't really seem to need debouncing strangely enough. In fact, when I did have debouncing code with that delay, the buttons became very unreliable. But, when I took out the delay completely, the accelerometers seemed to have been hyper-sensitive. So, I played with the delay some more, and found that 50 seems like a good number - good for the debouncing/button code, and for the accelerometer sensitivity.



Challenge/problem #5 - Text alerts
This one was a really annoying problem I had, and one I did not see coming. It should have been simple - having ATT for my cell provider, it should have just been a matter of sending an email to 5551234567@txt.att.net for example. Not!

Sending an email to an address such as the above works just fine if you're actually in the Gmail interface, but never goes through when using the Huzzah/SMTP2Go combo. I'm not good enough to write my own code to send an email, so I was at the mercy of someone else's code which requires the free SMTP2Go service. It actually works great, but just has that issue of not being able to send through to addresses like I mentioned above for email-to-text. I looked into, and tried many different alternatives such as:

  1. Sending from a 'real' email address such as me@mydomain.com. The problem with this is the same as with the Gmail - it doesn't actually go through (no error message, the text message just never comes through)
  2. Using a distribution list such as Google Groups. I didn't fully try this - it was going to be too much of a hassle such as setting up a new account, the group, etc.
  3. Using a distribution list such as MailChimp. The problem with this is they don't accept recipients with texting domains (such as @txt.att.net).
  4. Set up an email forwarding address with my hosting company. Same problem - never went through.
  5. GMail filter/forward - this was the winner. It wasn't exactly simple/quick - you have to set up rules to forward, and create a new forwarding address, but it works. So when my GMail email account receives an email with certain words in the subject line, it forwards to my texting address. Again, not exactly ideal, but it wasn't complicated and it works.

I'd like to find a better/easier solution, but at least for now, it's working. Oh, by the way, I'm not sure why the texts never come through in the circumstances described above, but when I did some searching, it sounds like that it's a combination of the way that the code sends an email and the fact that I'm not really sending through a real domain - there's no proper reverse DNS, so the mail servers are rejecting it.


Challenge/problem #6 - Static IP
I had problems with the Huzzah not letting me assign a static IP, even though I had the code in there to set the IP (at least I thought I did). It would just keep using DHCP for assigning itself an IP. The fix was a bit strange - the line WiFi.config(ip, gateway, subnet); needs to be AFTER the line WiFi.begin(ssd, password).
I didn't even have the WiFi.config(ip, gateway, subnet); line in the code at all. Additionally, I had the one line in the function that sends the email so I wasn't getting the static IP until it would send an email. Priorly it just uses DHCP. I moved both of the aforementioned lines into the setup() loop and it started working - it gets the specified IP right off the bat.


Challenge/problem #7 - No 'CC' in the email function
This one wasn't a big deal really, but I thought I'd mention it. I thought that in order to send the email to a 2nd recipient, you just add a 'CC' line of code. Wrong. Just add another one of these lines:
client.print("RCPT To: email@domain.com");


Challenge/problem #8 - Bug!
For some reason, sometimes after sending the email notification, the LED would turn itself off. This is not supposed to happen - it's supposed to only turn off with the user pressing the 'reset' button. I tried changing all kinds of code all over the place but it wasn't helping.
It took a long time for me to figure it out. I posted the problem on the Arduino forums, and a very smart person said to add serial.print(); lines in EVERY location where the LED is turned off and/or on. So after more testing, I finally found the problem - there was a 'blinkLEDWhileMachineIsRunning' immediately after the 'notifyRepeatWasherOrDryerIsDone' line. Well, I never intended this line to run after sending the email, so I added a 'return' to jump out of the current 'if/else' block of code!
Moral of the story? Don't use serial.println(); sparingly - use them everywhere! And don't underestimate the power of those lines when writing/debugging code.


Challenge/problem #9 - Accelerometer orientation
Sometimes when in my 'lab' and also in the garage (where my washer/dryer is located), one or both accelerometers would go crazy sometimes and act like it's picking up very fast constant vibrations. I eventually figured out that it seemed to be dependent on their orientation. If it was leaning too much to 1 or more sides, it would go nuts. If it was orientated correctly (the top of it was actually the top, and not leaning too much to 1 side), it would be ok.


Challenge/problem #10 - Accelerometer sensitivty woes
This is the worst one I think because it took so long to figure out. During all my testing, I had problems with the sensitivity of the accelerometers. When adjusting the sensitivity on 1 or both, It was like I didn't adjust one of them. For example, if I adjusted the threshhold for the dryer, it seemed to have made no difference. I banged my head against the wall for a couple of months on this one, but you know what?! It turned out to be me - I was the problem! I had the accelerometers mixed up in code like a doofus. Once I had corrected it, the 'calibration' of sensitivity for both accelerometers went wonderfully!


Challenge/problem #11 - Cramped space
I wish I had a larger project box because trying to stuff all the circuitry and wires into the box was not working too well. I ended up shortening several of the wires, and swapping out some of the wires with stranded (more flexible) wire. I originally used all solid core wire. In the future, I will probably use stranded wires for projects that need to fit in a box.


Well, that's about it. I hope this set of challenges/problems helps you for either duplicating this project or some other project you may have.


Sunday, October 2, 2016

My new RC Transmitter - FlySky FS-T6 - not exactly what I expected, but it is now



Recently I purchased an RC Transmitter - more specifically a FlySky FS-T6 on eBay. It was a killer price - less than $50, and it has 6 channels.

To my surprise however, I discovered that the left throttle stick does not bounce back when moving it up or down. Everything else springs back - side to side and the right stick springs back when moving up and down and side to side.

Here's a little demo of the transmitter. It shows that the left stick just stays put when you move it up/down. For my application, I was expecting/wanting it to bounce back to vertical center.


I started searching and reading about RC transmitters. Then I took my little question/issue to the appropriate section of the RC Universe forums. So apparently what I bought was a cheap (as in $$$ and quality) airplane/helicopter transmitter. The behavior of the left stick is by design - you don't want the left (usually throttle) stick to bounce back to center when flying a helicopter/airplane.

The smart people over at the forum though were kind enough to tell me I had a cheap-o transmitter (FYI I'm not being sarcastic) on my hands. So they told me that maybe I should buy a better transmitter. I almost sent it back, but then had some other good suggestions such as 'modifying' the transmitter to install a spring inside which will make that left stick bounce back.

Doing a little more research on this route, I came across this:
http://www.thingiverse.com/thing:927809
The problem is that I don't have a 3D printer (yet). It did give me the idea of designing/making my own part from scratch that could be laser cut.

What I did was remove the existing 'control arm' (the one for the right side), and scan it into my computer. However, it kept coming out terribly no matter what settings I used for the scanner. Then I realized that it was because the piece was black. So I took it outside and sprayed one side of it with some white spray paint, then scanned again...success!

Then with some sign software, I had it perform a 'vectorize' function on the image, and boom! I had a nice new vector file. I did modify it just slightly before I prepped the file for laser-cutting. A couple minutes later and boom! Now I had a nice shiny new part for my cheap RC transmitter:

Original spring, control arm (painted white) on the left; new spring, control arm on the left

The above image is showing the original control arm that I temporarily removed and spray painted white. The original spring is to the left of that. That was my other problem - I needed a spring to go with my new control arm, otherwise that piece is useless. So what I didn't mention yet, I took dimensions of the existing spring, and found a very very similar spring on McMaster.com (part# 9654K942.

When I received the springs (come in a package of 12), I excitedly put my new control arm and spring in there, and tried it out. I had to 'open' the little loop on one end to get it installed correctly, but that was no problem. When done, I was a little disappointed however - the spring is very strong/tight, so there is a lot of resistance when moving the left control stick up or down.

I took the spring back out, and tried to stretch it out a bit. I think I made it better, but it's still tight. I would like to find a better replacement, but I'm going to live with it for now. (I actually ruined 1 spring trying to do that - I stretched it way too much/far so now it's permanently very long)

You can see that it's now installed in the photo below (control arm circled):



Here's a video demonstrating the new behavior of the left control stick moving up and down thanks to the new parts:


Could you tell that the stick doesn't bounce back the same way as the other control stick? That kind of bugs me but I think it will be ok for what I'm doing.

One last thing - if someone wants to make their own custom control arm for this transmitter, here's the .ai file for cutting your own:

FlySky FS-T6 6 channel RC transmitter centering control arm

Well, I hope this helps someone out there. If you have any questions/comments, you know what to do!