กลับหน้าหลัก
views
How to Install Library for NodeMCU ESP8266 in Arduino IDE
Last updated on

How to Install Library for NodeMCU ESP8266 in Arduino IDE


How to Install Library for NodeMCU ESP8266 in Arduino IDE

Why Library Installation Matters

When writing Arduino code for NodeMCU ESP8266, red errors during upload usually mean the IDE doesn’t recognize commands from external libraries.

Code that has #include at the top requires additional libraries to compile. For example, reading the GY-302 BH1750FVI light sensor needs its library to be present in the system.

Diagram showing Arduino code structure with #include directive pulling in external library

Steps to Install Library in Arduino IDE

1. Find Arduino IDE Installation Folder

Open File Explorer and navigate to your Arduino IDE installation directory, such as C:\Program Files\Arduino. Then go into the libraries folder.

2. Place Library Folder

Copy the extracted library folder into the libraries directory. Verify that the folder contains .h or .cpp source files that define the library.

Screenshot showing the libraries folder in Arduino IDE with various library folders inside

3. Restart Arduino IDE

Close and reopen Arduino IDE completely. This step is necessary because the IDE only loads newly added libraries when it starts up.

4. Upload Code

Press the upload button to send code to NodeMCU ESP8266. If the library is installed correctly, you’ll see Done uploading at the bottom of the window.

Screenshot showing green "Done uploading" message at the bottom of Arduino IDE

Example Code: Read GY-302 BH1750FVI Light Sensor

After installing the library, try this code to test light intensity readings:

#include <BH1750FVI.h>

BH1750FVI LightSensor(BH1750FVI::k_DevModeContLowRes);

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

void loop() {
  uint16_t lux = LightSensor.GetLightIntensity();
  Serial.print("Light: ");
  Serial.print(lux);
  Serial.println(" lux");
  delay(250);
}

This code reads light intensity in lux units and prints to Serial Monitor every 250 milliseconds. Remember to set Serial Monitor baud rate to 115200.

อยากทำโปรเจคแบบนี้?

รับทำโปรเจค Arduino / IoT จบงานไว ส่งงานครบ พร้อมสอน

If you need Arduino project service or urgent IoT development, see full service details on the home page

จ้างทำโปรเจคเลย

ประเมินราคาอัตโนมัติ + Reference Code

ขอให้ AI ประเมินราคาโปรเจคนี้

กรอกข้อมูลให้ครบ ระบบจะสร้างรหัสอ้างอิงและประเมินราคา/ระยะเวลาคร่าว ๆ จากรายละเอียดงาน แล้วให้กด Add LINE พร้อมพิมพ์รหัสนี้เพื่อคุยต่อ

คำถามให้ AI ประเมินแม่นขึ้น

หลังส่งฟอร์ม ระบบจะโชว์ Reference Code ให้ copy แล้วกด Add LINE เพื่อคุยต่อ ข้อมูลส่วนตัวจะไม่ถูกส่งเข้า GA4

ความคิดเห็น

รีวิวจากคนใช้งานจริง

รีวิวจากลูกค้าและคนที่เคยใช้งาน

ถ้าเคยสั่งงาน เคยอ่านหน้านี้แล้วได้ประโยชน์ หรือมีข้อเสนอแนะ ฝากรีวิวไว้ได้เลย

กำลังโหลดรีวิว...