0% found this document useful (0 votes)
107 views

Node MCU - Lab Manual-2-16

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views

Node MCU - Lab Manual-2-16

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

Arduino IDE 2.

0 Installed

Before proceeding make sure you have Arduino IDE 2.0 installed in your computer.
Go to the Arduino website and download the version for your operating system.

▪ Windows: run the file downloaded and follow the instructions in the installation guide.
▪ Mac OS X: copy the downloaded file into your application folder.
▪ Linux: extract the downloaded file, and open the arduino-ide file that will launch the IDE.

If you have doubts, you can go to the Arduino Installation Guide.

To install the ESP8266 board in your Arduino IDE, follow these next instructions:
1. In your Arduino IDE 2.0, go to File > Preferences.
2. Copy and paste the following line to the Additional Boards Manager URLs field.
http://arduino.esp8266.com/stable/package_esp8266com_index.json
Adding ESP8266 Board Manager

In the Additional Boards Manager enter below URL.

http://arduino.esp8266.com/stable/package_esp8266com_index.json

As highlighted in the figure and enter OK.


Selecting Board

Now open the tools in that select Board: “Arduino/Genuino Uno” and click on the Boards Manager as
shown in the figure

ESP8266 Board Package

The Boards Manager window opens, scroll the window page to bottom till you see the module with the
name ESP8266. Once we get it, select that module and select version and click on the Install button. When
it is installed it shows Installed in the module as shown in the figure and then closes the window.
Selecting ESP8266 Arduino Board

To run the esp8266 with Arduino we have to select the Board: “Arduino/Genuino Uno” and then
change it to NodeMCU 1.0 (ESP-12E Module) or other esp8266 modules depending on what you have
to select and select port, Upload the program.
EXPERIMENT 1:

AIM: TO TEST LED WITH NODE MCU

CIRCUIT DIAGRAM:

CODE:
int led = D1; // LED pin
void setup() {
pinMode(led, OUTPUT);
}
void loop() {
digitalWrite(led, HIGH); delay(1000);
digitalWrite(led, LOW); delay(1000);
}
CONNECT C6 TO C13
EXPERIMENT 2:

AIM: TO TEST LED & SWITCH WITH NODE MCU

CIRCUIT DIAGRAM

CODE:

int led = D6; // LED pin


int button = D3; // push button is connected
int temp = 0; // temporary variable for reading the button pin status
void setup() {
pinMode(led, OUTPUT); // declare LED as output
pinMode(button, INPUT); // declare push button as input
}
void loop() {
temp = digitalRead(button);
if (temp == HIGH) {
digitalWrite(led, LOW);
Serial.println("LED Turned OFF");
delay(1000);
}
else {
digitalWrite(led, HIGH);
Serial.println("LED Turned ON");
}
}

CONNECT C6 TO SWITCHES AND C4 TO LESS & press s1 led 1 will turn on


EXPERIMENT 3:

AIM: TO TEST DHT 11 ON OLED WITH NODE MCU

CIRCUIT DIAGRAM:

CODE:

#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>
#include <DHT.h>
#define SCREEN_WIDTH 128 // OLED display width, in pixels
#define SCREEN_HEIGHT 64 // OLED display height, in pixels
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
#define DHTPIN D4 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT11 // DHT 11
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(115200);
dht.begin();
if(!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
Serial.println(F("SSD1306 allocation failed"));
for(;;);
}
delay(2000);
display.clearDisplay();
display.setTextColor(WHITE);
}
void loop() { delay(5000);
float t = dht.readTemperature();
float h = dht.readHumidity();
if (isnan(h) || isnan(t)) {
Serial.println("Failed to read from DHT sensor!");
}
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0,0);
display.print("Temperature: ");
display.setTextSize(2);
display.setCursor(0,10);
display.print(t);
display.print(" ");
display.setTextSize(1);
display.cp437(true);
display.write(167);
display.setTextSize(2);
display.print("C");
display.setTextSize(1);
display.setCursor(0, 35);
display.print("Humidity: ");
display.setTextSize(2);
display.setCursor(0, 45);
display.print(h);
display.print(" %");
display.display();
}
CONNECT C5 TO C8 & C3 TO C10
EXPERIMENT 4:

AIM: TO TEST ULTRASONIC WITH NODE MCU

CIRCUIT DIAGRAM:

CODE:
const int trigPin = D5; //trig
const int echoPin = D4; //Echo
long duration;
int distance;
void setup() {
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
Serial.begin(115200); // Starts the serial communication
}
void loop() {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance= duration*0.034/2;
// Prints the distance on the Serial Monitor
Serial.print("Distance: ");
Serial.println(distance);
delay(2000);
}

CONNECT C3 TO C9
EXPERIMENT 5:

AIM: TO TEST LDR WITH NODE MCU

CIRCUIT DIAGRAM:

CODE:
int light_pin = D4;
void setup() {
pinMode(light_pin, INPUT);
Serial.begin(115200);
}
void loop() {
int light_data = digitalRead(light_pin);
if(light_data==0){
Serial.println("Light Detected!");
}
else{
Serial.println("Light not Detected!");
}
delay(100);
}

CONNECT C3 TO C11 & SEE RESULT IN SERIAL MONITOR


EXPERIMENT 6:

AIM: TO TEST SOIL MOISTURE SENSOR WITH NODE MCU

CIRCUIT DIAGRAM:

CODE:

#include <ESP8266WiFi.h> //adding esp266 wifi library


#include <ThingSpeak.h> //adding thingspeak library
int SM_pin = A0; // Arduino pin A0
const char *ssid = "PCS Labs";
const char *pass = "pcs@2468";
float soil = 0;
WiFiClient client;
long myChannelNumber = ******;
const char myWriteAPIKey[] = "**********";
void setup() {
pinMode(SM_pin, INPUT);
Serial.begin(115200);
WiFi.begin(ssid, pass);
while(WiFi.status() != WL_CONNECTED)
{
delay(200);
Serial.print("..");
}
Serial.println();
Serial.println("NodeMCU is connected!");
Serial.println(WiFi.localIP());
ThingSpeak.begin(client);
}

void loop() {
int SM_value = analogRead(SM_pin);
Serial.print("SOIL MOISTURE Value : ");
Serial.println(SM_value);
ThingSpeak.writeField(myChannelNumber, 3, SM_value, myWriteAPIKey);
Serial.println("data sent to cloud");
delay(1000);
}

CONNECT C1 TO C12 ATTACH CONNECTOR AND SEE RESULTS ON THINGSPEAK.

You might also like