Ive tried using ct_clamp, but had similar resultâŚ
Since my last update Ive been messing with just going the Arduino route to prove that ESP32-Wroomâs ADC pins are just bad⌠but now I dont know what to think⌠it seems to be working through Arduino IDE in C.
No load, then putting on ~5 Amps, reading isnt precise but thats because I have no calibration done to it. But at least it senses that there is a load⌠with yaml ESPhome route it wouldnt sense it at allâŚ
So it seems ESP32-Wroom is perfectly ok for this purpose? I am at a loss why it wont work through ESPhome.
I am completely new to ESPhome, so hope my next statement doesnt offend people. But is there any chance that ct_clamp and ADC libraries (I dont know if esphome uses libraries during compile but it seems to?) for this specific chip ESP32-Wroom are buggy? D1 Mini seems to be #1 choice for ESPhome, any chance ESP32-Wroomâs implementation needs work to fix this ADC stuff?
Or am I just using it incorrectly? It tried the most simple code to get it to work (what I originally posted). D1 Mini and Arduino IDE seem to point to my circuit being correct⌠so I just need to figure out the software bit?
#define SENSOR_PIN 34
#define ADC_MAX 4095 // 12-bit ADC resolution for ESP32
#define VREF 3.3
#define SENSOR_RATIO 30.0 // CT 30A/1V
#define BIAS_VOLTAGE 1.54
const int numSamples = 500;
void setup() {
Serial.begin(115200);
delay(1000);
}
void loop() {
float sumSquares = 0;
for (int i = 0; i < numSamples; i++) {
int adc_value = analogRead(SENSOR_PIN); // Read ADC value
float voltage = (adc_value * VREF) / ADC_MAX;
float acVoltage = voltage - BIAS_VOLTAGE; // Remove DC bias
sumSquares += acVoltage * acVoltage;
delayMicroseconds(200); // Short delay to sample AC wave properly
}
float meanSquare = sumSquares / numSamples; // Mean of squared values
float rmsVoltage = sqrt(meanSquare); // RMS voltage
float currentRMS = rmsVoltage * SENSOR_RATIO; // Convert to RMS current
// Output readings
Serial.print("RMS Voltage: ");
Serial.print(rmsVoltage, 3);
Serial.print("V | RMS Current: ");
Serial.print(currentRMS, 3);
Serial.println("A");
delay(1000);
}
Being new to ESPhome, Id appreciate it if someone could give me some code to try and get it to work? But I have tried the following (from this project) with no luck:
sensor:
- platform: ct_clamp
sensor: adc_sensor
name: "Dryer Current"
unit_of_measurement: "A"
icon: "mdi:lightning-bolt-circle"
id: dryer_current
update_interval: 20s
filters:
- calibrate_linear:
- 0.0 -> 0.0
- 0.058 -> 4.20
on_value:
then:
- sensor.template.publish:
id: dryer_code
# codes: 0 Idle, 1 Door Open, 2 Drying
state: !lambda |-
if (x > 5) return 2;
return 0;
- platform: template
id: dryer_code
internal: true
on_value:
then:
- text_sensor.template.publish:
id: dryer
state: !lambda |-
if (x == 2) return "Drying";
return "Idle";
- platform: adc
pin: GPIO34
id: adc_sensor
text_sensor:
- platform: template
name: "Dryer"
id: dryer
icon: "mdi:tumble-dryer"
Perhaps its something as silly as the header (top portion) of the yaml? Maybe im pulling in wrong âlibrariesâ for lack of a better term? This is what I have at the top⌠is it correct for ESP32-Wroom?
esphome:
name: esp32_wroom_device
friendly_name: ESP32 WROOM Device
platformio_options:
board_build.flash_mode: dio
esp32:
board: esp32dev
framework:
type: esp-idf
and this is the board I have in case it makes a difference (I have 2 of them and they behave the same):