Spark Core vs PlantSmart: Round 1

Overview

I’ve been using a PlantSmart for a few years to gather environmental data in various spots around my yard. It’s pretty good, but it doesn’t give me access to the raw data. That, and it’s not wireless! So, this weekend, I added a photo resistor to a Spark and put them side-by-side on my back deck for two days.

I polled the Core every minute and recorded the JSON output into a text file for later parsing. After manually removing some of the bad lines, I was able to parse the JSON into a CSV format using PHP. Once I had the data in CSV format, I imported it into a Google Spreadsheet to graph the data. After intense visual analysis (or a quick 2-second look), I realized that it was pretty much a 1-to-1 match.

The Setup

The electronic components of the setup is a pretty straightforward voltage divider setup with a photo resistor. I don’t have any fancy schematics off-hand, but the Using a Photocell article on Adafruit can help you out.

Here’s a picture of my setup. The photo resistor and 10K resistor were bent a little to squish them into a small tupperware container.

To poll the Core, I set up a cron job (scheduled task) on a Linux “box” at home. You can use your own computer at home, a server (physical or virtual) on the Internet, or even @kareem613’s atomiot.com project. There are many other online polling and graphing options available, but I’m a sucker for raw data at unnecessary intervals, so I did all this manually.

Once I stopped the polling, I used my PHP parser script to grab the light readings and timestamp and output them to a CSV format. I forgot to log the timestamp for each call, so I used the coreInfo.last_heard timestamp instead. It’s probably not the best case scenario, but I wasn’t going to throw away 2 days of data and start over again!

The Code

Spark Core

uint8_t snsLight;

void setup() {
    Spark.variable("snsLight", &snsLight, INT);
    
    pinMode(A0, INPUT);
}

void loop() {
    snsLight = getLight();
}

int getLight() {
    // This converts the analog readings into percentage readings (from 0 through 4095 to 0 through 100)
    return map(analogRead(A0), 0, 4095, 0, 100);
}```

#### Polling Script

This is called once per minute by a Linux cron job and appended to a `log.json` file.

#!/bin/sh
echo curl https://api.spark.io/v1/devices/DEVICE_ID/snsLight?access_token=WOULDNT_YOU_LIKE_TO_KNOW >> /home/garrett/log.json
echo ‘,’ >> /home/garrett/log.json


The contents of the `log.json` file look something like this:

[
{ “cmd”: “VarReturn”, “name”: “snsLight”, “result”: 83, “coreInfo”: { “last_app”: “”, “last_heard”: “2014-05-03T14:42:03.279Z”, “connected”: true, “deviceID”: “51ff6f065067545708350687” } }
,
{ “cmd”: “VarReturn”, “name”: “snsLight”, “result”: 83, “coreInfo”: { “last_app”: “”, “last_heard”: “2014-05-03T14:43:34.297Z”, “connected”: true, “deviceID”: “51ff6f065067545708350687” } }
,

]```

PHP Parser Script

Once the data was gathered, this script was used to extract the result and coreInfo.last_heard and return each reading in a CSV format.

#!/usr/bin/php
<?php
date_default_timezone_set('America/New_York');

$json = json_decode(file_get_contents('log.json'), TRUE);

foreach($json as $j) {
	if(!isset($j['result']))
		continue;

	echo date('Y-m-d H:i:s', @strtotime($j['coreInfo']['last_heard'])).','.$j['result'].PHP_EOL;
}
?>

The CSV output looks something like this:

2014-05-03 10:42:03,83
2014-05-03 10:43:34,83
...

The Results

I imported the CSV data into a Google Spreadsheet to generate an easy chart. It looks like the PlantSmart’s “very low light” readings correlate to the 75% mark from the Spark Core readings.

PlantSmart Chart

 

Spark Core Chart

What this means to me is that I can replicate the functionality of a commercial device that I have general faith in with a Spark Core, but I also have control of my own data, and it’s friggin’ wifi-enabled!

The next few rounds will be to wire up a quick soil moisture sensor and figure out how to deploy this into my yard against the elements either running on batteries or a solar setup.

6 Likes

Amen brother!

Awesome to see the spark core reliable enough to replace a commercial product. Nice project.

1 Like

I think I saw something in some other threads about some new low-power friendly features coming down the pipe in the future. That might help some (though you might have to switch your strategy and push values out from the spark to your server, instead of pulling). I’m sure you could rig up some solar cells and a lipo charging circuit in there somehow.

2 Likes

@dougal,

that’s really gonna revolutionize home gardening?! :smiley:

@dougal: That’s definitely the end game idea. Gotta do my due diligence research to make sure I have all the components spec’ed out and tested to my liking. Then I’ll work on deploying it to my yard.

Coffee please? :smiley:

Sure! You can grow your own coffee trees and use something like what I'm working on to monitor it!

However, if you want to grow your own, I recommend starting from an already-growing plant instead of starting from seed. Coffee seeds are notoriously difficult to get to sprout. It's possible that the seeds that ThinkGeek sells have already been put through the paces (de-chaffing, soaking, etc) and are ready to sprout.

1 Like

I imagine something like the “Micro experimental growing” project but open sourced. That would be really cool!

1 Like

There is a lot of gARDUINOs in the internet (instructables for example), but connecting this to the internet is the reason that i am jumping to SPARK CORE... still waiting mine :smile:

1 Like

Yes, totally right! And think about the opportunities of using smart statistics and building a plant database from that!
I’d help working on that :wink:

1 Like

Great project . I am currently using a similar set up . I am using all 8 analog in to measure two raised bed gardens.
Sunlight, outside air temp, east garden(moisture, soil temp, inside air temp) and west garden (moisture, soil temp, inside air temp)
And using google docs and a google script to collect and graph , but google fails on al lot of the collection attempts.
See my graphs and Picts here
https://sites.google.com/site/kzoogarden/

2 Likes

What sort of enclosure are you using?

i am using a JIF peanut butter jar with a hole cut in the lid and a plastic Dixie cup glued on the bottom. all the wires go in through the cup and there’s a few cotton balls jammed in there to keep bugs out.
i have not had any trouble so far it’s been working great since late March. the clear jar lets the light through to the photometer and the air probe is below out of the sun light but in contact with the outside air.
there is a picture of the jar here, but i can send more picts if it’s not clear.
https://sites.google.com/site/kzoogarden/home/tech

i wanted the water to run off and drip down that is why i used the cup on the bottom and ran all the wires down. i did not seal the lid, for easy maintenance.

Nice! How are you bringing back all 3 sensors using only 4 wires in your data wire? Is one for VCC and the rest of the wires come back into their respective voltage dividers? I like your JIF+Cixie cup setup. I’m always worried about moisture buildup in containers like that, especially since the humidity around here can get pretty high during the summer. I’ve actually been saving up some tea jugs for outdoor projects such as this. They’re a bit big for the Spark, but they’re transparent and pretty sturdy.

What sort of bolts are you using? I’ve had various mixed results with the different “probes” I’ve tried. I’ve had the best luck with 14-2 electrical wire, but the copper will eventually oxidize, and passing electricity through it increases the oxidization rate!

I used inox bolts, but until i find this article i am about to try this Free Electrolysis.

http://gardenbot.org/howTo/soilMoisture/#The_local_circuit_-_simple_voltage

I think is important too, that sample are not constant (sensor feeding from 5v) but from digital output where the sensor get the 5v like every hour.

Dallas DS18B20 temperature sensors can use 2 wire for many sensors in parallel.
I didn’t got my Core yet, but is there a library for this sensor ready for Spark core ?

1 Like

not yet, part of spark libraries ?

There is an “official” Spark one-wire library in the works right now, I believe. Until that comes out, @dave has put some code on a gist to share over here:

2 Likes

@wgbartley you are correct they all share a VCC. The 4 wires are: +3.3V, temp air, temp soil, moisture. I put the voltage dividers on the board, these picts might help. and I am using basic zinc machine screws. I know this is not a good long term solution. Also at some point I should free up my proto-board and solder this to a perf-board. :slight_smile:
Sorry for miss-labeling the photo it is 3.3V. ugh

1 Like

@peetersm Those pictures and labels are outstanding! Hopefully, I can learn a little something about implementing solar at the Maker Faire this weekend. That’s the only thing holding me back from going all out on the garden sensor.

One thing I’m curious about is how the PlantSmart is able to sample the “fertilizer” level of my soil. Have you come across anything like that in your searches?

Another outdoor enclosure option is a Stevenson screen. Once I’m ready to go “live” with a garden sensor, I’ll probably print one to use, although I still am kicking myself for recycling all those plastic jugs just last week! With our powers combined, I think we can be pretty dangerous. :wink:

1 Like