Web Enabled Temperature and Humidity Using Spark Core

I posted a while ago about the kick starter I backed the Spark Core. I finally got around to making it useful.  Stick with me this is a long post.

The Problem:

Over the last few months one of my filament spools kersploded

20140607_104703Turns out that humidity causes PLA to become brittle and break apart like this especially when its on a small diameter spool.  I always new that PLA was susceptible to humidity but I generally ignored it so I guess I deserve this.  Now based on a suggestion on how better to store my PLA. https://groups.google.com/d/topic/makerbot/Rdx2ZnJeQzs/discussion

long story short I am now using this http://www.westmarine.com/buy/iris-usa-inc–62-8-qt-water-tight-storage-box-clear–14018642

20140706_114102I also put two of these in the box http://amzn.com/B000H0XFCS 

20140706_114125And to monitor the humidity levels one of these http://amzn.com/B0013BKDO8 20140706_114113

Not bad.  The box started out at a startling 45% humidity and quickly dropped to 20-22%.  Since I was monitoring the levels manually I though why not make a wireless sensor to monitor the levels auto-magically.

The Solution

This brings me back to my spark core I mentioned earlier. I went bought one of these https://www.sparkfun.com/products/10167dht22

For the sensing part and quickly and easily plopped it on a breadboard. 20140706_113030I connected this to a 10 ah battery I have to make it wireless. 20140706_113015Then uploaded some code.


// This #include statement was automatically added by the Spark IDE.
#include "idDHT22/idDHT22.h"
#include ;

// declaration for DHT11 handler
int idDHT22pin = D4; //Digital pin for comunications
void dht22_wrapper(); // must be declared before the lib initialization

// DHT instantiate
idDHT22 DHT22(idDHT22pin, dht22_wrapper);

char message[50];
double Humidity =0;
double degF = 0;
double degC = 0;
double DewPoint = 0;
double DewPointSlow = 0;
int result;
int led = 0;
void setup()
{

	pinMode(led, OUTPUT);
	Spark.variable("message", &message, STRING);
	Spark.variable("Humidity", &Humidity, DOUBLE);
	Spark.variable("degF", &degF, DOUBLE);
	Spark.variable("degC", &degC, DOUBLE);
	Spark.variable("DewPoint", &DewPoint, DOUBLE);
	Spark.variable("DewPointSlow", &DewPointSlow, DOUBLE);
}
// This wrapper is in charge of calling
// mus be defined like this for the lib work
void dht22_wrapper() {
	DHT22.isrCallback();
}
void loop()
{

	digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)

	DHT22.acquire();
	while (DHT22.acquiring());
	
	result = DHT22.getStatus();
	switch (result)
	{
		case IDDHTLIB_OK:
			//Serial.println("OK");
			break;
		case IDDHTLIB_ERROR_CHECKSUM:
			//Serial.println("Error\n\r\tChecksum error");
			break;
		case IDDHTLIB_ERROR_ISR_TIMEOUT:
			//Serial.println("Error\n\r\tISR Time out error");
			break;
		case IDDHTLIB_ERROR_RESPONSE_TIMEOUT:
			//Serial.println("Error\n\r\tResponse time out error");
			break;
		case IDDHTLIB_ERROR_DATA_TIMEOUT:
			//Serial.println("Error\n\r\tData time out error");
			break;
		case IDDHTLIB_ERROR_ACQUIRING:
			//Serial.println("Error\n\r\tAcquiring");
			break;
		case IDDHTLIB_ERROR_DELTA:
			//Serial.println("Error\n\r\tDelta time to small");
			break;
		case IDDHTLIB_ERROR_NOTSTARTED:
			//Serial.println("Error\n\r\tNot started");
			break;
		default:
			//Serial.println("Unknown error");
			break;
	}
     
    Humidity = DHT22.getHumidity();
    degF = DHT22.getFahrenheit();
    degC = DHT22.getCelsius();
    DewPoint = DHT22.getDewPoint();
    DewPointSlow = DHT22.getDewPointSlow();
    
    sprintf(message, "{\"Humidity\":%f,\"degF\":%f,\"degC\":%f,\"DewPoint\":%f,\"DewPointSlow\":%f}", Humidity, degF,degC,DewPoint,DewPointSlow);
       
     digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
    
	delay(30000);
}

Ok great now to get the data.  This is where the Spark Core is cool. The Spark.variable makes that var available via the web api.

Very cool.  Now to the logging part.

Initially I tried using google docs per this post https://community.spark.io/t/example-logging-and-graphing-data-from-your-spark-core-using-google/2929 but I was having problems.  I will continue to make this work as I like the idea of making the data available anywhere.

In the mean time I setup my pc to log the data using powershell

#put you id and access token in the url string
$url = "https://api.spark.io/v1/devices/xxxx Core ID xxxxxx/message?access_token=xxxx Access Token xxxxx"

while($true){

    # First we create the request.
    $HTTP_Request = [System.Net.WebRequest]::Create($url)

    # We then get a response from the site.
    $HTTP_Response = $HTTP_Request.GetResponse()

    # We then get the HTTP code as an integer.
    $HTTP_Status = [int]$HTTP_Response.StatusCode

    If ($HTTP_Status -eq 200) { 
        Write-Host "Site is OK!" 
    }
    Else {
        Write-Host "The Site may be down, please check!"
    }


    $requestStream = $HTTP_Response.GetResponseStream()
    $readStream = new-object System.IO.StreamReader $requestStream
    $wrs = $readStream.ReadToEnd()
    $readStream.Close()



    $data = $wrs|ConvertFrom-Json

    $data = ((($data.result.Split(",")).replace("}","")).replace("{","")).split(":")

    $Humidity = $data[1]
    $degF = $data[3]
    $degC = $data[5]
    $DewPoint = $data[7]
    $DewPointSlow = $data[9]

    $object = New-Object –TypeName PSObject
    $object | Add-Member –MemberType NoteProperty –Name date –Value (Get-Date)
    $object | Add-Member –MemberType NoteProperty –Name Humidity –Value $Humidity
    $object | Add-Member –MemberType NoteProperty –Name degF –Value $degF
    $object | Add-Member –MemberType NoteProperty –Name degC –Value $degC
    $object | Add-Member –MemberType NoteProperty –Name DewPoint –Value $DewPoint
    $object | Add-Member –MemberType NoteProperty –Name DewPointSlowC –Value $DewPointSlow

    $object |Export-Csv "C:\TempatureData.csv" -Append

    # Finally, we clean up the http request by closing it.
    $HTTP_Response.Close()

    Start-Sleep -Seconds 600
}

This code logs the date and the data into a csv.

date Humidity degF degC DewPoint DewPointSlowC
7/6/2014 11:48 38.700001 73.4 23 8.177205 8.207732
7/6/2014 11:58 38.700001 73.4 23 8.177205 8.207732
7/6/2014 12:08 39.599998 73.76 23.2 8.694606 8.725507
7/6/2014 12:18 39 73.76 23.2 8.469035 8.499937
7/6/2014 12:28 38.599998 74.3 23.5 8.583681 8.615134
7/6/2014 12:38 38.599998 73.76 23.2 8.31695 8.347849
7/6/2014 12:48 37.5 73.76 23.2 7.89145 7.922324
7/6/2014 12:58 31.299999 73.58 23.1 5.177949 5.207903

Now I just need to place this in the box and I can remotely monitor and log the conditions in my filament storage box.20140706_124116

Build of Materials

Item Location Price
Spark Core /u.fl connector https://www.spark.io/ $39
2.4GHz Antenna – Adhesive (U.FL connector) https://www.sparkfun.com/products/11320 $4.95
Humidity and Temperature Sensor – RHT03 https://www.sparkfun.com/products/10167 $9.95
Breadboard – Self-Adhesive (White) https://www.sparkfun.com/products/12002 $4.95
10k ohm resistor
small led (optional)
470 ohm resistor (optional)
Jumper wires

There you have it.  This is just a quick and dirty solution.  I am sure it can be done cheaper and easier.  This was done with the items I already had on hand with the exception of the DHT22.

Busy Busy Busy

Been a while since I posted but I have been busy.  My printer has been busy also.

20140622_172717

These are just some of the recent part I have been printing.  I got the largest order I have ever had from makexyz.  I did some design an a prototype of a guy a few weeks ago and now he wants 50 of each of the two design (100 items total).  That is over 40 hrs of printing wow!

 In other news I have heard some buzz about this kickstarter

I backed it because it looks promising.  I print on blue painters tape and it works great.  I don’t really need a new solution but this one is interesting and only cost $39.  I need the 12×12 custom one since my printer has the jetguy heated build plate http://bctechnologicalsolutions.com/hbp/index.html.  Delivery is not until Oct 2014 so I will wait patiently.

Trilobular Screws for Printed parts

I was tired of taping holes in the prints that I was making so I decided to go out and get some self taping screws. I did some research and came across these http://www.microfasteners.com/lpp0206-2-x-3-8-thread-forming-screws-trilobular-for-plastic.html screws.

Trilobular screw

I have never heard of Trilobular screws before and they are claimed to be specific for soft material such as plastics. I rolled the dice and picked some up.

Drum roll please …….

They work great. They have great holding strength (not imperially tested). They screw in fine and do not seem to cause any issue with repeated screwing and unscrewing. I did need to beef up my screw holes though. I previously had a 6mm cylinder with an 2.26mm hole (I am using a #4 screw) in the middle as a standoff. I found that this seem to have some deformities when the screw was inserted. I increased the cylinder to 8mm and it was much better. I would guess I can do some tests to compare the difference between tapped/machine screws vs. these Trilobular screws but I can tell you that the time saving eliminating the need for tapping is great.

Desk fan – Prototype 1

I have always wanted to make an electric motor from scratch and I finally got started. Here is the first prototype that I came up with.

20140322_181132 20140322_181206 20140322_181152

(Sorry the video is rotated apparently wordpress cant rotate a video)

I did not want to mess with brushes so this is a single coil brushless motor with a neodymium magnet in the rotor/fan blade.

I am using a Hall Effect sensor attached to an Arduino to sense the position of the rotor and time the switching of the coil connected to an H-bridge.  I also have a pot read as analog input on the Arduino to adjust the timing from when the Hall senses the magnet to when it pulses the coil.

As you can see it works. Albeit it’s a bit slower than I would like. In the next prototype I will make the rotor propeller shaped so it can move are in a useful manner and I will make the motor more powerful (somehow).

Evolution of a design

How do you do design when you are unsure of what the final product looks like?  In a word (or two or an acronym and a word or whatever) “3D printer”

The problem:

Child safety locks for drawers are quite limited when on drawer/cabinet design. Some cabinets do not have a cross member above the drawer to attack the latching part of the lock. So how do you lock these drawers you improvise with you 3D printer.

Getting to the solution:

I had some ideas on what I wanted the design to look like. There is room on the side of the drawer in this case to allow for a lock. In this case instead of thoroughly thinking through all the potential pitfalls in the design I just started testing ideas. Here is my iterative process of design.

20140510_162933-120140510_162907-1024x576

Step1: Rough out the idea on what I want it to be. This puts something physically in hand to see if the idea has any hope of working. This one seems like it could work and it has the flexibility that could work without breaking.

Step 2: The first prototype was way too short. It was not able to be depressed by hand when the drawer was closed.

Step 3: Wow I nearly tripled the length from step 1 to 2 but it’s still way to short. Also I question why it was so wide when clearly other locks are much skinnier.

Step 4: This is getting closer; I added the hook at the end. This is actually where something interesting and unexpected happened. The lock was behaving with an extra benefit. When locked (drawer all the way in) and the drawer was pulled on without releasing the lock by depressing it, the lock hook end actually deformed a bit to form a wedge that secured the drawer in place even more than just the hooking action I expected. This one was also a bit too tall.

interesting behavior

Step 5: Shortened the height to give a bit of wiggle room for the drawer. I also extended the shape on the wedge on the end to take advantage of the unexpected behavior.

Step 6: Final design. I made the long extension a bit thicker to increase rigidity and prevent de-lamination of the top and bottom.

Here is the final design installed in the cabinet.

20140510_16295820140510_162946

Well there you have it. The process of design with a 3D printer can be iterative because why not. To print successive designs takes only time and a few pennies of material.

Bi-Fold Door Lock

How do you lock a bi-fold door so a 2 year old cant get in?  You search the thingiverse and print what you find.  Duh!!

This is what I found: http://www.thingiverse.com/thing:263534 it was close but not quite right.  The width for the door was too big.  No worries I can re-spin it for my doors an 5 mins of work.

This is what I did:
http://www.thingiverse.com/thing:298054

20140413_100840 20140413_100857 20140413_100907 20140413_101028 20140413_101036 20140413_101054

large crayon sharpener for the thingiverse

I am not sure why there is not a large crayon sharpener (up until now) on the thingiverse.

http://www.thingiverse.com/thing:273589

I obviously have the need for one so I designed and printed it.  I am using a standard razor blade and a screw I had laying around.

20140316_183145 20140316_183154 20140316_183217

In case you are wondering… Nope, I don’t get it perfect the first time here is my first and second attempt.  The third one works great though.

Iteration 1 and 2

Iteration 1 and 2