Soil sensor data publish


I found a tutorial from sparkfun! And read the documents about analog and publishing.
But still no data showing.

With this code:

 /*  SparkFun Inventor's Kit for Photon
    Experiment 3 - Part 2: Internet Houseplant Monitor 
    This sketch was written by SparkFun Electronics
    Joel Bartlett <>
    August 31, 2015

    This application monitors the moisture level of your houseplant 
    and exposes that data to be monitored via the Internet. 
    Development environment specifics:
    Particle Build environment (
    Particle Photon RedBoard
    Released under the MIT License(
int val = 0;//variable to store soil value
int soil = A2;//Declare a variable for the soil moisture sensor 
int soilPower = D6;//Variable for Soil moisture Power
//Rather than powering the sensor through the V-USB or 3.3V pins, 
//we'll use a digital pin to power the sensor. This will 
//prevent oxidation of the sensor as it sits in the corrosive soil. 

void setup() 
Serial.begin(9600);   // open serial over USB

pinMode(soilPower, OUTPUT);//Set D7 as an OUTPUT
digitalWrite(soilPower, LOW);//Set to LOW so no power is flowing through the sensor

//This line creates a variable that is exposed through the cloud.
//You can request its value using a variety of methods
Spark.variable("soil", &val, INT);

void loop() 
Serial.print("Soil Moisture = ");    
//get soil moisture value from the function below and print it

delay(1000);//take a reading every second
//This time is used so you can test the sensor and see it change in real-time.
//For in-plant applications, you will want to take readings much less frequently.

    //If your soil is too dry, turn on Red LED to notify you
    //This value will vary depending on your soil and plant
    if(readSoil() < 200)
      // take control of the RGB LED
      RGB.color(255, 0, 0);//set RGB LED to Red
      // resume normal operation
//This is a function used to get the soil moisture content
int readSoil()
    digitalWrite(soilPower, HIGH);//turn D6 "On"
    delay(10);//wait 10 milliseconds 
    val = analogRead(soil);
    digitalWrite(soilPower, LOW);//turn D6 "Off"
    return val;

I then go look at my dashboard where it says it goes online.

=> {“data”:“online”,“ttl”:“60”,“published_at”:“2016-03-29T22:30:03.051Z”,“coreid”:“mycoreid”,“name”:“spark/status”

and then when I look where the Json is showed I get

=> [
“id”: “myid”,
“name”: “beetlgeuze”,
“last_app”: null,
“last_ip_address”: “MyIp!!”,
“last_heard”: “2016-03-29T22:30:48.895Z”,
“product_id”: 0,
“connected”: true,
“platform_id”: 0,
“cellular”: false
with id and acces token
“ok”: false,
“error”: “Variable not found”
I don’t see what I did wrong? I hope I am specific enough now! (no condescending on the reply whatsoever!!)
FYI= I changed the real ID’s with the myid or similar because I don’t know if it is vulnerable to security.
And I’m not using a Sparkphoton but a real particle photon (maybe for the powering of the sensor) and this with this sensor but except for a rain I use a Soil. In the future I want the rain module as well.

Seeing as you’re rather new, might I advice you to go through the documentation (the guide section for starters) an then through some of the examples in the tutorial section here on the forums. Both sources contain a wealth of information and are quite likely to clarify a lot of your questions.

“it clearly doesn’t work” is not that great of a description. It certainly not ‘clear’ that it doesn’t work, nor is it ‘clear’ why it doesn’t work. Trying a more scientific approach wouldn’t be a bad thing here. Hypotheses, observation, conclusion.
“It should do this. In actuality it does this. That’s wrong/right for this and this reason”. Please try to be as descriptive as possible. The only reasonable answer I can provide for “it doesn’t work”, is “too bad”, if you don’t give me info to work with.

What data to what ‘sort of terminal’? Again, the description is a bit vague. Let’s assets you’re talking about the sensor data and a Serial terminal, which would make sense in this scenario. The data is being printed over Serial, which can be accessed with a Serial terminal. Depending on your OS, there are several options. Googling for it should suffice.

In the code I see you deviding by 1024, which should probably be 4096, considering this is not an Arduino, and the resolution is higher.

There is more than one way to get data from the device. Listing them here while they’re documented perfectly makes little sense. With that in mind, please do give the docs a try, they’re there for a reason :wink:

Best of luck, and let us know if you have further specific questions.

1 Like

You can look at to watch the published events as well.