Please include the following information, in order for us to help you as effectively as possible.
- What product do you wish to discuss? RAK4631, RAK3372, RAK11200, RAK11310, RAK11722?
Rak4631
- What firmware are you using? (RUI3 or Arduino BSP or other IDE (e.g. STM32CubeIDE
Rui3
Sensor RAK5811
We are trying to read analog information from the stc-013 sensor but I want to know if this type of sensor is supported by the rak5811 or if they should be put before the analog input resistance and Capacitor As indicated by the manufacturer Or just connect the white wire to gnd and analog output A0.
test code
#define PIN_PWR_1 WB_IO1 // RAK5811 power pin 1
#define PIN_PWR_2 WB_IO2 // RAK5811 power pin 2
#define ANALOG_PIN WB_IO4 // Analog input pin
const float VREF = 3.0;
const float DIVIDER = 0.6;
const float BIAS = VREF / 2.0;
const int NUM_SAMPLES = 200;
void setup() {
Serial.begin(115200);
while (!Serial) delay(10);
pinMode(PIN_PWR_1, OUTPUT);
pinMode(PIN_PWR_2, OUTPUT);
digitalWrite(PIN_PWR_1, HIGH);
digitalWrite(PIN_PWR_2, HIGH);
pinMode(ANALOG_PIN, INPUT);
analogReference(AR_INTERNAL_3_0); // Solo si tu placa lo soporta
delay(1000);
}
void loop() {
float sum_sq = 0;
for (int i = 0; i < NUM_SAMPLES; i++) {
int raw = analogRead(ANALOG_PIN);
float voltage_adc = raw * VREF / 1024.0;
float ac_component = voltage_adc - BIAS;
float sensor_voltage = ac_component / DIVIDER;
sum_sq += sensor_voltage * sensor_voltage;
delayMicroseconds(1000);
}
float voltage_rms = sqrt(sum_sq / NUM_SAMPLES);
Serial.print("Voltaje RMS: ");
Serial.print(voltage_rms, 3);
Serial.println(" V");
delay(1000);
}