Brownout detector was triggered , rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)

Hi All,
I'm Naveen Kumar. Actually, I'm a full-stack developer specializing in software development, but currently, I'm working on the ESP32 controller along with an LDR sensor and an IR sensor. I already managed to get the output, but I'm still facing the issue where the brownout detector was triggered . Can you explain the error and provide solutions?

the code is
`
#include <WiFi.h>
#include <PubSubClient.h>
#include <DHT.h>
#include <ArduinoJson.h>
#include <Wire.h>

// WiFi credentials
const char* ssid = "Quantanics";
const char* password = "Quantanics2018";

// MQTT Broker
const char* mqtt_server = "broker.emqx.io";
const int mqtt_port = 1883;
const char* mqtt_topic = "quantanics/industry/locker_system";
const char* client_id = "2c0134e9-f475-45e0-a175-a9e93bca2366";
const char* mqtt_user = ""; // Add your MQTT username
const char* mqtt_password = ""; // Add your MQTT password

// Ultrasonic sensor 2
#define TRIG_PIN2 17
#define ECHO_PIN2 16
#define BUZZER_PIN 21
#define LDR_PIN 36
#define SMOKE_PIN 23

const int thresholdDistance = 30;
const int ldrThreshold = 2000;
const int smokeThreshold = 100;

long duration2;
int distance2;
int ldrValue;
int smokeValue;

// WiFi and MQTT clients
WiFiClient espClient;
PubSubClient client(espClient);

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

pinMode(TRIG_PIN2, OUTPUT);
pinMode(ECHO_PIN2, INPUT);
pinMode(SMOKE_PIN, INPUT);
pinMode(BUZZER_PIN, OUTPUT);

// Connect to WiFi
setup_wifi();

// Set the MQTT server and callback function
client.setServer(mqtt_server, mqtt_port);
}

void publishData(int distance,int ldr_value,int smoke_value){
StaticJsonDocument<300> doc;
doc["distance"] = distance;
doc["ldr_value"] = ldr_value;
doc["smoke_value"] = smoke_value;

char jsonBuffer[512];
serializeJson(doc, jsonBuffer);
if (client.publish(mqtt_topic, jsonBuffer)) {
Serial.println("Data published successfully");
} else {
Serial.println("Failed to publish data");
}

}

void loop() {
if (!client.connected()) {
reconnect();
}
client.loop();

// Measure distance using the second ultrasonic sensor
digitalWrite(TRIG_PIN2, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN2, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN2, LOW);

duration2 = pulseIn(ECHO_PIN2, HIGH);
distance2 = duration2 * 0.034 / 2;

// Read the LDR value
ldrValue = analogRead(LDR_PIN);

smokeValue = analogRead(SMOKE_PIN);

if((distance2>30) && !(ldrValue>4090)){
digitalWrite(BUZZER_PIN, HIGH);
Serial.println("Buzzer ON");
}else{
digitalWrite(BUZZER_PIN, LOW);
Serial.println("Buzzer OFF");
}

Serial.print("Distance: ");
Serial.print(distance2);
Serial.println("CM");
Serial.print(" cm, LDR Value: ");
Serial.println(ldrValue);

Serial.print("Smoke Value:");
Serial.println(smokeValue);

publishData(distance2, ldrValue, smokeValue);
delay(1000); // Adjust delay as needed
}

void setup_wifi() {
WiFi.begin(ssid, password);

while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}

}
void reconnect() {
while (!client.connected()) {
Serial.print("Attempting MQTT connection...");
if (client.connect("ESP32Client")) {
Serial.println("connected");
// Remove or comment out the line below to prevent publishing "ESP32 connected"
// client.publish(mqtt_topic, "ESP32 connected");
} else {
Serial.print("failed, rc=");
Serial.print(client.state());
Serial.println(" try again in 5 seconds");
delay(5000);
}
}
}`

Learn how to use the forum first, then provide more information.
https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum/679966

1 Like

Besides what @sonofcy has suggested (mainly how to post your code), you need to provide datasheets for these parts/modules and show a wiring diagram of how you have them connected.

You most likely have a power supply issue

1 Like

I assume you understand the importance of clear and concise documentation. As others have suggested, please follow the forum guidelines and use code tags when posting code. Without proper formatting, it’s difficult to follow and provide effective assistance.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.