I am new to particle. I have connected soil moisture sensor to a particle relay board. I flashed the following code to the photon.
// Pin definitions
int moistureRead = A2;
int moisturePower = D2;
int led = D7; // The on-board LED
void setup() {
pinMode(led, OUTPUT);
pinMode(moisturePower, OUTPUT);
pinMode(moistureRead, INPUT);
}
void loop() {
digitalWrite(led, HIGH); // Turn ON the LED
digitalWrite(moisturePower, HIGH); // Turn ON power to moisture sensor
delay(2000); //Wait for 2 seconds
String sensor1 = String(analogRead(moistureRead));
Particle.publish("sensor1", sensor1, PRIVATE);
delay(5000); // Wait for 5 seconds
digitalWrite(led, LOW); // Turn OFF the LED
digitalWrite(moisturePower, LOW); // Turn OFF the moisturesensor
delay(15000); // Wait for 10 seconds
}
The program runs and in the particle events it reports the following
Event
The source event that triggered the webhook
{
"name": "sensor1",
"data": "3259",
"ttl": 60,
"published_at": "2020-02-02T10:55:51.753Z",
"coreid": "27004214234120b47353735"
}
This keeps updating. When I go to thingspeak I can see the connection but the data from the sensor is not coming through.
When I output the data to CSV I get the following.
|created_at|entry_id|field1|
|---|---|---|
|2020-02-02 10:37:31 UTC|850|sensor1|
|2020-02-02 10:37:53 UTC|851|sensor1|
|2020-02-02 10:38:15 UTC|852|sensor1|
|2020-02-02 10:38:37 UTC|853|sensor1|
|2020-02-02 10:38:59 UTC|854|sensor1|
|2020-02-02 10:39:21 UTC|855|sensor1|
|2020-02-02 10:39:43 UTC|856|sensor1|
|2020-02-02 10:40:05 UTC|857|sensor1|
|2020-02-02 10:40:27 UTC|858|sensor1|
Instead of outputting the data for sensor1 is simply reports the name sensor1.
Appreciate any insights to what I am doing wrong.
Thanks
John