HELP ME esp8266 and read analog

hello what read info fron analog 0 in cayenne …no detect pin a0
// This example shows how to connect to Cayenne using an ESP8266 and send/receive sample data.
// Make sure you install the ESP8266 Board Package via the Arduino IDE Board Manager and select the correct ESP8266 board before compiling.

//#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid = “Hostal las Ventas”;
char wifiPassword = “xxxxx”;

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username =
char password = "
char clientID = "
unsigned long lastMillis = 0;

void setup() {
Serial.begin(9600);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}

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

// Default function for sending sensor data at intervals to Cayenne.
// You can also use functions for specific channels, e.g CAYENNE_OUT(1) for sending channel 1 data.
CAYENNE_OUT_DEFAULT()
{
// Write data to Cayenne here. This example just sends the current uptime in milliseconds on virtual channel 0.
Cayenne.virtualWrite(A0, millis());
// Some examples of other functions you can use to send data.
//Cayenne.celsiusWrite(1, 22.0);
//Cayenne.luxWrite(2, 700);
//Cayenne.virtualWrite(3, 50, TYPE_PROXIMITY, UNIT_CENTIMETER);
}

// Default function for processing actuator commands from the Cayenne Dashboard.
// You can also use functions for specific channels, e.g CAYENNE_IN(1) for channel 1 commands.
CAYENNE_IN_DEFAULT()
{
CAYENNE_LOG(“Channel %u, value %s”, request.channel, getValue.asString());
//Process message here. If there is an error set an error message using getValue.setError(), e.g getValue.setError(“Error message”);
}

which esp8266 device you are using? you need to start this if using a wemos D1_mini_Examples/ReadAnalogVoltage.ino at master · wemos/D1_mini_Examples · GitHub

nodencu v3 i copy script and cayenne no detect

what are you trying to do with nodemcu and analog input. Do you want to display the analog input value on the cayenne dashboard? which sensor you have connected to analog pin?

yes for all aswers

1 Like

read water conductivity

@luisvaljun8 you need to provide more detail if you want some help. kindly provide some link to the sensor you are using.

this sensor

thank you. now follow this tutorial and see if you can get the reading from the sensor. once you get reading we will move to cayenne code. first try this Interface Moisture Sensor With NodeMCU : 7 Steps (with Pictures) - Instructables

yes read data

can you share the serial monitor output and code, so accordingly i can suggest the next step.

com4 9600

code is up post friend

i wanted to see the sensor value output in the serial monitor.

Next, you have add a new device to cayenne dashboard using Adding a New Device using MQTT
Once you device is connected, upload the below code,

#define CAYENNE_DEBUG
#define CAYENNE_PRINT Serial
#include <CayenneMQTTESP8266.h>
// WiFi network info.
char ssid[] = "ssid";
char wifiPassword[] = "wifiPassword";

// Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
char username[] = "MQTT_USERNAME";
char password[] = "MQTT_PASSWORD";
char clientID[] = "CLIENT_ID";

int sense_Pin = 0; // sensor input at Analog pin A0

int value = 0;
void setup() {
  Serial.begin(9600);
  Cayenne.begin(username, password, clientID, ssid, wifiPassword);

}
void loop() {
  Cayenne.loop();
  Serial.print("MOISTURE LEVEL : ");
  value = analogRead(sense_Pin);
  value = value / 10;
  Serial.println(value);

}
CAYENNE_OUT_DEFAULT()
{
  Cayenne.virtualWrite(1, value, "analog_sensor", "null");
}