Something as simple as a photoresistor is kicking my butt!


#1

I know there is something amazingly simple that I am overlooking, but for the life of me, I cannot get a simple photoresistor to transmit a value to the dashboard. Verified wiring, tested on multiple ESP8266 units, tested a handful of light sensors, stand alone mode (non-cayenne, just serial monitor) works as expected, but no value change once connected to the server.

ESP8266-12E
Photoresistor
10k resistor
Wire

#define CAYENNE_PRINT Serial // Comment this out to disable prints and save space
#include “CayenneDefines.h”
#include “BlynkSimpleEsp8266.h”
#include “CayenneWiFiClient.h”
#include “ESP8266WiFi.h”
// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = “TOKEN”;
char ssid[] = “SSID”;
char password[] = “PASSWORD”;
void setup()
{
Serial.begin(9600);
Cayenne.begin(token, ssid, password);
}

void loop()
{
Cayenne.run();
}


#2

I am using this code.

Add Widgets:

-Add new: Device/Widget
-Custom Widgets
-Select a widget that you need
-Enter the name of the widget
-Select device, Virtual Pin, Pin number
-Select Data, Unit, Icon
-Add Widget

    //#define CAYENNE_DEBUG         // Uncomment to show debug messages
    #define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
    #include "CayenneDefines.h"
    #include "BlynkSimpleEsp8266.h"
    #include "CayenneWiFiClient.h"

    // Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
    char token[] = "token";
    // Your network name and password.
    char ssid[] = "ssid";
    char password[] = "password";



    void setup()
    {
      Serial.begin(9600);
      Cayenne.begin(token, ssid, password);
    }

    void loop()
    {
      Cayenne.run();
      int sensorValue = analogRead(A0);
      Cayenne.virtualWrite(V0, sensorValue);
    }

#3

I’ll give that another shot. When the canned sketch didn’t work, I tried setting it up as a virtual pin, but in hindsight, I may have had my virtuaWrite called out incorrectly. The only result I’d get was a “one shot” sample of the analog reading.
Thanks Tad.


#4

Mark this as helped! Thanks again Tad, I figured I’d try using the canned sketches for a change and was failing. Lesson learned: call out the virtualWrite early on in the loop to avoid one time sampling of data, and skip the example sketch all together.
Now to do some soldering, deploy the sensors to the room units, and push the updated code.
Time to collect some data…
:+1:


#5

this helped me too! thanks!