Hall effect sensor in the ESP32 with Arduino ide

Learning about the esp32 again. When looking at the adc documentation at this interested me

It is also possible to read the internal hall effect sensor via ADC1.

Digging in the code for the arduino-esp32 we find that we can read it using hallRead() from arduino-esp32/cores/esp32/esp32-hal-adc.h

Might be useful to someone.

//Simple sketch to access the internal hall effect detector on the esp32.
//values can be quite low. 
//Brian Degger 

int val = 0;

void setup() {
  Serial.begin(9600);
    }

void loop() {
  // put your main code here, to run repeatedly:
  val = hallRead();
  // print the results to the serial monitor:
  //Serial.print("sensor = ");
  Serial.println(val);//to graph
}

Strong magnets are needed to get a good response.

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);
}