Capsicum

🫑 A retrofitted wired audio doorbell with added WiFi connectivity 🔔

power 16340
wireless WiFi
mcu ESP32-C3
ongoing since Oct 2023

Measure raw ADC value

esp32c3 adc measure medium

Measure raw ADC value using the ESP32-C3 ADC CH0


Details

This code outputs the reading of the raw ADC value using the ESP32-C3 ADC CH0 of GPIO0 pin.

Serial console

Serial output from the firmware.

Code

Download code
#define BATTERY_ENABLE_PIN 6
#define BATTERY_MEASURE_PIN 0  // ADC1_CH0, GPIO0

void setup() {
  Serial.begin(115200);
  Serial.println();

  pinMode(BATTERY_ENABLE_PIN, OUTPUT);
  digitalWrite(BATTERY_ENABLE_PIN, HIGH);
}

void loop() {
  digitalWrite(BATTERY_ENABLE_PIN, LOW);
  delayMicroseconds(10);
  int sum = 0;

  for (int i = 0; i < 100; i++) {
    sum = sum + analogRead(BATTERY_MEASURE_PIN);
  }
  float adcValue = sum / 100.0;
  Serial.print("Raw ADC Value: ");
  Serial.println(adcValue);

  delay(2000);

  digitalWrite(BATTERY_ENABLE_PIN, HIGH);

  Serial.println();
  delay(2000);
}

Makefile

# Description: Makefile for the demo code
# Usage: make [lint] [compile] [upload] [clean]
BOARD := esp32:esp32:esp32c3:CDCOnBoot=cdc
PORT ?= /dev/cu.usbmodem1410*
BUILD = build

.PHONY: default lint compile upload clean

default: lint compile upload clean

lint:
	cpplint --extensions=ino --filter=-legal/copyright,-runtime/int,-readability/todo,-whitespace/line_length *.ino

compile: clean lint
	arduino-cli compile --fqbn $(BOARD) --output-dir $(BUILD) ./

upload:
	arduino-cli upload --fqbn $(BOARD) --port $(PORT) --input-dir $(BUILD)

clean:
	rm -rf build

References