ESP32 + analogRead() on Arduino

It works fine. I had it confused with analogWrite(). You can find the pins for analogRead in https://esp-idf.readthedocs.io/en/v2.0/api/peripherals/adc.html

On the esp32 devkit v1  GPIO’s 32, 33, 34, 35 are broken out.

/*
  Analog input, serial output on esp32

 Reads an analog input pin, prints the results to the serial monitor.

Cut down from AnalogInOutSerial by Tom Igoe for Arduino.
Modified for use with esp32 
This example code is in the public domain.
 */
// These constants won't change.  They're used to give names
// to the pins used:
const int analogPin = 32;  // Analog input pin , ours is connected to YL-83

int sensorValue = 0;        // value read from the adc
void setup() {
  // initialize serial communications at 9600 bps:
  Serial.begin(9600);
}

void loop() {
  // read the analog in value:
  sensorValue = analogRead(analogPin);
  // print the results to the serial monitor:
  //Serial.print("sensor = ");
  Serial.println(sensorValue);


  // wait 1 seconds before the next loop to minimise corrosion on the rain detector.
  delay(1000);
}

 

Leave a Reply

Your email address will not be published. Required fields are marked *