# ESP8266 getResetReason() - wrong result

**URL:** <https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689>\
**Category:** Networking, Protocols, and Devices\
**Created:** [December 12, 2016, 11:44pm UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689 "2016-12-12T23:44:20Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![sevenOFnine](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sevenOFnine](https://forum.arduino.cc/u/sevenOFnine)\
**Post date:** [December 12, 2016, 11:44pm UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/1 "2016-12-12T23:44:20Z")

</div>

Hello friends of excited electrons,

I’m using the ESP8266-07 with the Arduino library.

I would like to distinguish between a power-on reset and an external-reset with a button.  
Reset (RST) pin of ESP8266 is pulled up to VCC with 10k. If the button is pressed it’s tied to GND.

So I searched for a while in the web and found following solution:

```cpp
#include <Arduino.h>
extern "C" {
#include <user_interface.h>
}

void setup() {

  rst_info *resetInfo;
  Serial.begin(9600);  
  resetInfo = ESP.getResetInfoPtr();
  Serial.println((*resetInfo).reason);

}

void loop() {
  // put your main code here, to run repeatedly:
}

```

However I get always reset code 6, independent of if I unplug (and replug) power or push the button.  
I've awaited, that I get reset code 0 if the device is powered up.

```cpp
https://github.com/esp8266/Arduino/blob/master/tools/sdk/include/user_interface.h

enum rst_reason {
 REASON_DEFAULT_RST = 0, /* normal startup by power on */
 REASON_WDT_RST = 1, /* hardware watch dog reset */
 REASON_EXCEPTION_RST = 2, /* exception reset, GPIO status won’t change */
 REASON_SOFT_WDT_RST   = 3, /* software watch dog reset, GPIO status won’t change */
 REASON_SOFT_RESTART = 4, /* software restart ,system_restart , GPIO status won’t change */
 REASON_DEEP_SLEEP_AWAKE = 5, /* wake up from deep-sleep */
 REASON_EXT_SYS_RST      = 6 /* external system reset */
};

```

Now I'm sad 😭  
What am I doing wrong?

_Software Versions:_  
_Arduino IDE: 1.6.13_  
_Board: ESP8266 version 2.3.0_

EDIT: sry for misleadig title. "getResetReason()" is also a method which returns a human readable representation of reset code. However its derived from rst\_info and yields the same wrong result.

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [December 13, 2016, 12:34am UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/2 "2016-12-13T00:34:42Z")

</div>

```cpp
  Serial.println((*resetInfo).reason);

```

Most people would have used

```cpp
  Serial.println(resetInfo->reason);

```

Why didn't you? Just curious.

---

<div class="post-metadata">

**Author:** ![sevenOFnine](https://avatars.discourse-cdn.com/v4/letter/s/a88e57/32.png) [@sevenOFnine](https://forum.arduino.cc/u/sevenOFnine)\
**Post date:** [December 13, 2016, 10:59am UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/3 "2016-12-13T10:59:13Z")

</div>

In short: I dont know.  
Think its a personal style and sometimes I forget that there is an arrow operator. But I will change it for bette readability.

Unfortunately this wont solve the problem ... 🙁

---

<div class="post-metadata">

**Author:** ![sts](https://avatars.discourse-cdn.com/v4/letter/s/958977/32.png) [@sts](https://forum.arduino.cc/u/sts)\
**Post date:** [August 15, 2017, 1:10pm UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/4 "2017-08-15T13:10:38Z")

</div>

Search in electrical circuit

![reason.jpg](https://europe1.discourse-cdn.com/arduino/original/4X/0/0/e/00eacba5bc5b7cb3f7a111f07d22a1c913d6b7ff.jpeg)

---

<div class="post-metadata">

**Author:** ![thomascoope](https://avatars.discourse-cdn.com/v4/letter/t/aeb1de/32.png) [@thomascoope](https://forum.arduino.cc/u/thomascoope)\
**Post date:** [October 15, 2017, 7:33pm UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/5 "2017-10-15T19:33:08Z")

</div>

Did you ever resolve this issue? I have a similar issue. I'm not using a pull-up resistor & the reset works fine, but I'm finding that I get a response of 5 when I do an external system reset when the chip is in deepsleep.

---

<div class="post-metadata">

**Author:** ![msraynsford](https://avatars.discourse-cdn.com/v4/letter/m/a183cd/32.png) [@msraynsford](https://forum.arduino.cc/u/msraynsford)\
**Post date:** [January 14, 2018, 5:55pm UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/6 "2018-01-14T17:55:28Z")

</div>

I think the usb-\>serial device resets the controller when it connects to the device. So you think you're power cycling but once the power has come back on again, the PC connection then resets the device and actually gives you a code 6.

You could write some code that turns on the LED if you have reason 6, then reset the device without the PC connection (obviously you'd need some kind of LCD to get the exact number or even a webpage giving you the reason).

I'm just starting out on the same functionality, I'll let you know how I get on.

It is possible to disable the auto reset function too.  
[https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection](https://playground.arduino.cc/Main/DisablingAutoResetOnSerialConnection)

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [May 6, 2021, 11:03am UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/7 "2021-05-06T11:03:16Z")

</div>



---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [February 19, 2022, 10:53am UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/8 "2022-02-19T10:53:28Z")

</div>



---

<div class="post-metadata">

**Author:** ![salaiaungmyintmyat](https://avatars.discourse-cdn.com/v4/letter/s/6f9a4e/32.png) [@salaiaungmyintmyat](https://forum.arduino.cc/u/salaiaungmyintmyat)\
**Post date:** [February 19, 2022, 11:11am UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/9 "2022-02-19T11:11:46Z")

</div>

Hi @sevenOFnine,  
I found a solution to get reset code 0. It needs **"EN" pin** to connect **RC delay circuit**. I think because of current surge and power instability at boot, it gets reset code 6 instead of 0.

In datasheet, R = 10KOhm and C = 0.1uF are recommended but I have to change capacitor value to 1uF because 0.1uF didn't work for me.  
I tested with ESP-01 module. Hope it works out for you. 😃

REF:  
[CH\_EN and RST pin connection](https://bbs.espressif.com/viewtopic.php?t=646)  
([https://www.espressif.com/sites/default/files/documentation/esp8266\_hardware\_design\_guidelines\_en.pdf](https://www.espressif.com/sites/default/files/documentation/esp8266_hardware_design_guidelines_en.pdf))

---

<div class="post-metadata">

**Author:** ![vlad\_bg](https://avatars.discourse-cdn.com/v4/letter/v/d26b3c/32.png) [@vlad\_bg](https://forum.arduino.cc/u/vlad_bg)\
**Post date:** [November 4, 2025, 9:45am UTC](https://forum.arduino.cc/t/esp8266-getresetreason-wrong-result/424689/10 "2025-11-04T09:45:22Z")

</div>

My solution

 ![deepsleep solution](https://europe1.discourse-cdn.com/arduino/original/4X/1/b/f/1bfd232d3f2dcfa019a1b47c6bff97568c47ed6e.png)
