Need help with my NodeMCU V3

Hi, Im having problem with my nodemcu. Im upload all coding of gas sensor into my nodemcu then it got error “an error occured while uploading the sketch”
I use port 4
board Generic ESP8266 Module
(It is correct board for mylilon nodemcu v3 ?)
and this is my coding

#include <ESP8266WiFi.h>;
const int gasPin=A0;
int gasValue=0;
const int buzpin=5;
const int threshold=100;
const int ledPin=6;


void setup()
{
  Serial.begin(9600);
  pinMode (gasPin,INPUT);
  pinMode (buzpin,OUTPUT);
  pinMode  (ledPin, OUTPUT);  
}
   

void loop()
{
  gasValue=analogRead(gasPin);
  Serial.println(gasValue);
  delay(500);

  
  if (gasValue>150)
  {
    digitalWrite (2,HIGH);
    tone (buzpin,100);
    digitalWrite (ledPin, HIGH);
    delay(100); 
    
    
  }
  
      else if (gasValue<150)
   {
        digitalWrite (2,LOW);
        noTone(buzpin); 
        digitalWrite (ledPin, LOW);
        
  }

  
   }

  

How is this question related to Blynk?

Possibly the nodemcu is not set to programming mode (“Flash” button)?

If i didnt success yet with this coding so how can i connect with blynk hmm , ok let me try it

Try disconnecting all the external connections from your NodeMCU and re-flashing it again.

When you do re-connect your external devices, be aware that the GPIO numbers used in the code (GPIO 5 for your buzzer and 6 for your LED) are not the pins marked D5 and D6 on the board.

GPIO 5 is marked D1
GPIO 6 is not available on the NodeMCU anyway, so once you get your code uploaded it will probably crash anyway as you’re trying to do write operations to a reserved GPIO.

Pete.

it is a mistake
you have to choose nodemecu 1.0


How to re flashing my nodemcu ,can i just press that flash button?

So gpio 5 is d1 in my nodemcu
Gpio 6 can i put on d2 ?

Ohh :ok_hand:Thank you

look that
ARDUINO NODEMCU
16 DO
5 D1
4 D2
0 D3
2 D4
14 D5
12 D6
13 D7
15 D8
3 D9
1 D10

Wahh thank youu , about the re flash my nodemcu , can i just press the button ‘flash’ on the nodemcu

if you want to upload your sketch , flash button is not need on the nodemcu

But pete said “Try disconnecting all the external connections from your NodeMCU and re-flashing it again” because i get an error while trying to upload my sketch

let me see your issue when you upload

as @PeteKnight said
GPIO 6 is not available on the NodeMCU

The flash button on the NodeMCU doesn’t normally need to be used when reflashing. I think it’s only there so that if you manage to get into a reset loop where the code that you have previously uploaded is preventing you from re-flashing with new code, you can use the Flash button to put the device into a state where it doesn’t execute the uploaded code.
To use the Flash button, disconnect the power, then press and hold the Flash button whilst reconnecting the power, then release the button and upload your code.

I don’t think there’s actually any significant differences between the Generic ESP and NodeMCU v1.0 Board types, provided you choose nodemcu as your reset type when using the generic board.

You need to change your code so that you define your LED pin as something other than “6” and connect the LED to the appropriate pin. I’d suggest changing the code to use GPIO4, in which case the LED should be connected to D2.

Pete.

@Blynk_Coeur , @PeteKnight ok success uploading and my led , gas sensor also buzzer also works thank you so muchhhh , now i want to include blynk to my coding.
my project is ,when the gas sensor detect gas then it will send noti to blynk so can i use this coding ?

/*************************************************************
  Download latest Blynk library here:
    https://github.com/blynkkk/blynk-library/releases/latest

  Blynk is a platform with iOS and Android apps to control
  Arduino, Raspberry Pi and the likes over the Internet.
  You can easily build graphic interfaces for all your
  projects by simply dragging and dropping widgets.

    Downloads, docs, tutorials: http://www.blynk.cc
    Sketch generator:           http://examples.blynk.cc
    Blynk community:            http://community.blynk.cc
    Follow us:                  http://www.fb.com/blynkapp
                                http://twitter.com/blynk_app

  Blynk library is licensed under MIT license
  This example code is in public domain.

 *************************************************************

  You’ll need:
   - Blynk App (download from AppStore or Google Play)
   - ESP8266 board
   - Decide how to connect to Blynk
     (USB, Ethernet, Wi-Fi, Bluetooth, ...)

  There is a bunch of great example sketches included to show you how to get
  started. Think of them as LEGO bricks  and combine them as you wish.
  For example, take the Ethernet Shield sketch and combine it with the
  Servo example, or choose a USB sketch and add a code from SendData
  example.
 *************************************************************/

/* Comment this out to disable prints and save space */
#define BLYNK_PRINT Serial


#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>

// You should get Auth Token in the Blynk App.
// Go to the Project Settings (nut icon).
char auth[] = "e34ebc75567b4a098cc183acf7e84495";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk-cloud.com", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}

void loop()
{
  Blynk.run();
  // You can inject your own code or combine it with other sketches.
  // Check other examples on how to communicate with Blynk. Remember
  // to avoid delay() function!
}
1 Like
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <ESP8266WiFi.h>;
const int gasPin = A0;
int gasValue = 0;
const int buzpin = 5;
const int threshold = 100;
const int ledPin = 6;
BlynkTimer timer;

char auth[] = "e34ebc75567b4a098cc1xxxxxxxx";

// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "YourNetworkName";
char pass[] = "YourPassword";

void setup()
{
  pinMode (gasPin, INPUT);
  pinMode (buzpin, OUTPUT);
  pinMode  (ledPin, OUTPUT);
  // Debug console
  Serial.begin(9600);

  Blynk.begin(auth, ssid, pass);

  timer.setInterval(120000L, gas);  // check every 120s
}

void gas()
{
  gasValue = analogRead(gasPin);
  Serial.println(gasValue);
  delay(500);
  if (gasValue > 150)
  {
    digitalWrite (2, HIGH);
    tone (buzpin, 100);
    digitalWrite (ledPin, HIGH);
    delay(100);
  }
  else if (gasValue < 150)
  {
    digitalWrite (2, LOW);
    noTone(buzpin);
    digitalWrite (ledPin, LOW);
  }
}
void loop()
{
  timer.run();
  Blynk.run();
 }

i copy all of this coding and put my own auth,ssid and pass but my buzzer,led doesnt work and why my serial monitor all blank?

and

#include <BlynkSimpleEsp8266.h>

should “BlynkSimpleEsp8266.h” become red color as the other #include ? because mine is black

mine is black too

did you select the good com speed ?

where to know the com speed?