Hi everyone.
I have been experimenting with publishing variables to the Particle cloud, and I have managed to get some events published. My setup is simple: One magnetic reed switch (door sensor) and one photoresistor.
I have managed to get a message published for the door sensor but I can’t really get any value out of the photoresistor. I am attaching this screenshot from the dashboard:
And below is my the code running on my Photon
// pin assignments
int lightPin = 0;
int lightReading=0;
int switchPin = 6;
int ledPin = 7;
void setup() {
// set the inputs and outputs
pinMode(lightPin, INPUT);
pinMode(switchPin, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
digitalWrite(switchPin, HIGH);
Particle.variable("Light Sensor", lightReading);
}
void loop() {
// read the data from the photoresistor and publish the result
int lightReading = analogRead(lightPin);
Particle.publish ("Light Sensor", lightReading);
// check to see if the door is open. if it is, publish a message
if(digitalRead(switchPin) == LOW)
{digitalWrite(ledPin, LOW);}
else{digitalWrite(ledPin, HIGH);
Particle.publish ("Door Sensor", "Door is open");
}
delay(5000);
}
I’d really appreciate it if someone could shed some light on this. Also, is it ok that I have declared the light sensor value as a particle variable as well here?
Particle.variable("Light Sensor", lightReading);
Many Thanks!
John