YourESP32 Sketch AnalogInput

From ArduinoInfo
Jump to: navigation, search

/* YourESP32 Example: Sketch - Analog Input
    SEE: https://ESP32Info.Info
  - WHAT IT DOES : Reads the voltage on a potentiometer and displays values
  - SEE the comments after "//" on each line below
  - CONNECTIONS:
   -
   -
  - V1.00 10/02/2018
   Questions: terry@yourduino.com */

/*-----( Import needed libraries )-----*/
/*-----( Declare Constants and Pin Numbers )-----*/
#define  potPin  34   // An analog input
/*-----( Declare objects )-----*/
/*-----( Declare Variables )-----*/
int potValue = 0;          // Value from the Analog-Digital Converter stored here
float voltageValue = 0.0;  // Voltage as converted from raw value

void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(115200);
  delay(1000);
  Serial.println("https://ESP32Info.Info Example: Analog reading: RAW and Voltage");

}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  potValue = analogRead(potPin);  // Read the value
  Serial.print("ADC Raw reading = ");
  Serial.print(potValue);       // Print the value to serial monitor
  voltageValue = ((float(potValue) / 4095.0) * 3.30); // Calculate the voltage
  Serial.print("  Voltage = ");
  Serial. println(voltageValue);
  delay(500);

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
//NONE yet

//*********( THE END )***********