NodeMCU ESP8266 resets itself when not powered by micro usb

I've put together a thermostat to be controlled wirelessly through Blynk with 90% success. My issue is when the set, or hold temperature becomes equal to room temperature (when heating), the board will reset on its own, resetting the hold temp to what is specified in setup(). The strange thing is this only occurs when the transistor gives ground to the coil on the relay (enabling it) AND when the board is receiving power only from the 12v to 5/3.3v power supply shown in the fritzing sketch. The power supply receives 12v 2a at the barrel jack. The 5v jumper powers Vin on the esp8266, and the 3.3v jumper powers the DHT11 and relay coil. However, with the micro-usb is connected to the esp8266 in addition with the power supply, everything works as intended. Am I missing something here? Any help is appreciated.

[code]
#define BLYNK_TEMPLATE_ID "TMPLw-PN3VEN"
#define BLYNK_DEVICE_NAME "wifiThermo"
#define BLYNK_AUTH_TOKEN            "sntZNNxaObtu--------UxTQrsSjP6Lz"
#include "DHT.h"
#define DHTTYPE DHT11
#include <DHT_U.h>
#include <Adafruit_Sensor.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
DHT dht(4, DHTTYPE); //D2
int setTemp;
int tempUp;
int tempDown;
int transistor; //D5
float temperature;
float humidity;
float fahrenheit;
float setFahrenheit;
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Attic";//for blynk
char pass[] = "BG8----QE";//for blynk
BLYNK_WRITE(V6) {
  tempUp = param.asInt(); // push button
  if (tempUp == 1) {
    setTemp++;
  }
}
BLYNK_WRITE(V7) {
  tempDown = param.asInt(); // push button
  if (tempDown == 1) {
    setTemp--;
  }
}
BLYNK_CONNECTED()
{}
void statUpdate() {
  fahrenheit = (temperature * 1.8) + 32;
  Blynk.virtualWrite(V15, fahrenheit); //gauge
  Blynk.virtualWrite(V14, temperature); //gauge
  Blynk.virtualWrite(V5, humidity);  //gauge
}
void setup()  {
  //Serial.begin(115200);
  Blynk.begin(auth, ssid, pass);
  WiFi.begin(ssid, pass);
  WiFi.mode(WIFI_STA);
  while ( WiFi.status() != WL_CONNECTED ) {
    delay(100);
  }
  setTemp = 18;
  temperature = 0;
  fahrenheit = 0;
  humidity = 0;
  transistor = 14;
  Blynk.virtualWrite(V11, 0); // readiness status
  Blynk.virtualWrite(V5, humidity); //gauge
  Blynk.virtualWrite(V15, fahrenheit); //gauge
  Blynk.virtualWrite(V14, temperature); //gauge
  pinMode(transistor, OUTPUT); // controls relay ground
}
void loop() {
  Blynk.run();
  static unsigned long thermoBuffer = millis();
  setFahrenheit = (setTemp * 1.8) + 32;
  Blynk.virtualWrite(V13, setTemp); //gauge
  Blynk.virtualWrite(V12, setFahrenheit); //gauge
  if (millis() - thermoBuffer > 10000) {
    temperature = dht.readTemperature();
    humidity = dht.readHumidity();
    statUpdate();
    thermoBuffer = millis();
  }
  if (temperature == 0)  { // prevents transistor from toggling relay, which turns on heating system on device startup
    digitalWrite(transistor, LOW);
  }
  else if (setTemp > temperature )  {  // trigger on condition
    Blynk.virtualWrite(V11, 2); // readiness status
    digitalWrite(transistor, HIGH);
  }
  else if (setTemp < temperature - 1) { // trigger off condition
    Blynk.virtualWrite(V11, 1); // readiness status
    digitalWrite(transistor, LOW);
  }
}
[/code]

Welcome!
Before looking into code, few questions about your power.
Your diagram shows a single supply to the NodeMCU at 5v but a 3.3v supply on the same connection to the DHT and relay?
The relay image claims to be a 12v relay but you are driving it with 3.3v? Is the image correct?
The relay coil presents an inductive load is there protection/suppression on the relay? Does the code run correctly without the relay coil connected?

I couldn't find the exact components used with my setup on fritzing, hence the reason it seems I'm using 2 different voltages on one line. I've attached an actual picture of my setup.

I’d suggest putting some temp code on NodeMCU with just a simple ‘Blinky’ driving the relay GPIO on and off (no wifi, temp etc). If that runs consistently without resetting then investigate your code. If it still fails and resets, then disconnect the relay and put in an LED in its position. This way you can eliminate/discover the root cause

The transistor must have a (330 ohm?) current limiting resistor between ESP pin and base.
Not having one will damage the pin and/or the transistor.

You should have used a 5volt relay (lower current draw), and power it from the 5volt pin of the NodeMCU. That relay coil must also have a diode across to protect the transistor and to prevent turn-off voltage spikes upsetting or resetting the NodeMCU.

With a 5volt relay a 5volt cellphone charger connected to the USB socket of the NodeMCU is a better and safer solution than a breadboard supply.

The DHT11 might need a (10k) pull up resistor between data pin and 3.3volt of the NodeMCU.
Leo..

So true. Without the fly-diode you may even break your ESP quite easily.

The power supply board that provides the 3.3v and the 5v from 12v may not be adequate. In many of those boards the regulators do use the PCB as a heatsink as the package is intended to do.

If the 3.3v is actually powering the relay then there is no real point in looking any further. Relay will probably draw something in excess of 100mA (if it really is a 3.3v relay) , with the nodeMCU requiring at least that as well the power supply board is probably browning out.

Thank you for the replies. I will have to start over on a breadboard. I will come back when I get results.

Are you referring to the VoltIn pin on the board? The only Vout pins are 3.3v.

Yes, the V-in pin can be used to power the NodeMCU with 5volt, but when the NodeMCU is powered on the USB socket then there is 5volt on that pin available to power a small load like a relay.
Leo..

Update:
I've powered the esp through micro usb, added a 330ohm resistor between base and dPin, added a diode between Vin and relay coil power side, uploaded the blink sketch, so far so good. Moving on to the dht.

Google
The diode goes across the relay coil, not in series with relay power.
Anode (ring) to relay power, cathode to collector of the transistor.
Google something like "relay driver" or "Arduino relay driver", and go to images.
Leo..

Alright, I've got that circuit set up and working as you said, now I've encountered a problem with the DHT. I've copied the same libraries from my previous sketch, but am getting inaccurate and invalid readings on serial monitor. I've attached 2 photos, one shows results with the 10k resistor connected from the dht's data pin to 3.3v, and the other with no resistor attached.

[code]
#include "DHT.h"
#define DHTTYPE DHT11
#include <DHT_U.h>
#include <Adafruit_Sensor.h>
DHT dht(4, DHTTYPE); // D2
float temperature;
void setup() {
  Serial.begin(115200);
  pinMode(14, OUTPUT); // transistor D5
}
void loop() {
  temperature = dht.readTemperature();
  digitalWrite(14, HIGH);
  delay(1000);
  digitalWrite(14, LOW);
  delay(1000);
  Serial.print(temperature);
  Serial.println(" C");
}
[/code]

Here's the second picture

No experience with a DHT11. I always use I2C T/H sensors.
Do you have the 3-pin or the 4-pin version.
The 4-pin version already seems to have the 10 pull up resistor on the board.
Try powering it from the 3.3volt pin of the NodeMCU.
Why all the includes. I think you only need dht.h
Forget about switching that relay in your code, and first get the DHT working.
There are many NodeMCU/DHT11 examples for that on the web.
Leo..

It is a 3 pin dht. It has always been on 3.3v. I commented the unnecessary libraries. Eventually I figured out why I was getting the "nan" results. I had to include the wifi library and wifi.begin in setup, then the dht was outputting results I would expect. Would do a full test soon, but I'm also trying to recover from some sickness. Thanks for the help.

Confused by your Fritzy picture, which shows the 5volt and 3.3volt lines joined.

Adafruit says that a DHT11 sometimes has problems on 3.3volt power.
It seems you can power it from 5volt, and pull the data pin up to 3.3volt with a 10k resistor.
Leo..

I've ditched that project, as of now I have a working thermometer on a breadboard. 5v and a resistor didn't give correct result. Straight 3.3v is working so far. I will try to make a new fritzing that's up to date.

As of now, this setup is working as intended. Will move on to adding transistor and relay soon.

#include "DHT.h"
#define DHTTYPE DHT11
#include <ESP8266WiFi.h>
DHT dht(4, DHTTYPE); //D2
float temperature;
char ssid[] = "Attic";//for blynk
char pass[] = "BG8XTGTQE";//for blynk
void setup()  {
  Serial.begin(115200);
  WiFi.begin(ssid, pass);
}
void loop() {
  static unsigned long thermoBuffer = millis();
  if (millis() - thermoBuffer > 10000) {
    temperature = dht.readTemperature();
    Serial.println(temperature);
    thermoBuffer = millis();
  }
}

A hand drawn schematic is preferred. A digitally drawn one even better. Fritzing is not always clear to me (us)