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.
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.
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.
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
จ้างทำโปรเจคเลย