Value of variable stuck at 0

Hello everyone. i want to read data from a humidity sensor, but the variable 'val' that is suposed to have the data from the sensor is allways stuck at 0.
this is my code:

/*
  Sketch generated by the Arduino IoT Cloud Thing "Untitled 2"
  https://create.arduino.cc/cloud/things/56d9394e-9ef0-43f1-9e0f-d922ec934975

  Arduino IoT Cloud Variables description

  The following variables are automatically generated and updated when changes are made to the Thing

  int val;

  Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
  which are called when their values are changed from the Dashboard.
  These functions are generated with the Thing and added at the end of this sketch.
*/

#include "thingProperties.h"
#define sensorPin 15

void setup() {
  // Initialize serial and wait for port to open:
  Serial.begin(115200);
  // This delay gives the chance to wait for a Serial Monitor without blocking if none is found
  delay(1500);

  // Defined in thingProperties.h
  initProperties();

  // Connect to Arduino IoT Cloud
  ArduinoCloud.begin(ArduinoIoTPreferredConnection);

  /*
     The following function allows you to obtain more information
     related to the state of network and IoT Cloud connection and errors
     the higher number the more granular information you’ll get.
     The default is 0 (only errors).
     Maximum is 4
  */
  setDebugMessageLevel(2);
  ArduinoCloud.printDebugInfo();
}

void loop() {
  ArduinoCloud.update();
  // Your code here
  //get the reading from the function below and print it
  val = analogRead(sensorPin);
  Serial.print("Analog output: ");
  Serial.println(val);

  delay(1000);

}

Which MCU are you using that has a pin 15 as an analog pin?

A Uno?

im using a esp32

When you refer to the pinout of the ESP32 module you are using does GPIO_NUM_15 correspond to a Arduino Core A:D pin; such as A0 or A1 or A2 on ADC0?

Typically, I use GPIO_NUM_32 to GPIO_NUM_X where X is equal to the ADC0 ESP32 GPIO pins (refer to your ESP32 pinout).


im using this pinout

Why not use ADC1 GPIO pins which work under the Arduino ESP32's core? The GPIO pins attached to ADC2 require you to use the ESP32's API to access those pins for A:D.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.