[go: up one dir, main page]

0% found this document useful (0 votes)
25 views7 pages

Nodemcu Module

This document provides instructions for setting up an ESP32-based board and connecting various sensors and modules. It includes steps to add board URLs to the Arduino IDE, install the ESP8266 package, and connect an ultrasonic sensor, OLED display, and SD card module. Code examples are provided to read distance measurements from the ultrasonic sensor and display text on the OLED. The SD card code shows how to write and read data from a file.
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)
25 views7 pages

Nodemcu Module

This document provides instructions for setting up an ESP32-based board and connecting various sensors and modules. It includes steps to add board URLs to the Arduino IDE, install the ESP8266 package, and connect an ultrasonic sensor, OLED display, and SD card module. Code examples are provided to read distance measurements from the ultrasonic sensor and display text on the OLED. The SD card code shows how to write and read data from a file.
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/ 7

VEX123 - Teaching ICT as Exploratory Course

NODEMCU
ESP32 BASED BOARD

WEMOS D1 MINI

Created By: Christian I. Cabrera


VEX123 - Teaching ICT as Exploratory Course

SET-UP
Make sure Arduino IDE is already installed on your machine.
1. Select File Menu -> Preferences
2. Goto additional board manager URLs
Add this
https://dl.espressif.com/dl/package_esp32_index.json,
http://arduino.esp8266.com/stable/package_esp8266com_index.json

3. Open the Boards Manager. Go to Tools > Board > Boards Manager…

Created By: Christian I. Cabrera


VEX123 - Teaching ICT as Exploratory Course

4. Search for ESP8266 and press install button for the “ESP8266 by
ESP8266 Community“:

5. Select Install

Hardwares:
1. Ultrasonic sensor

2. Sd card Module

3. 0.96 OLED display

Created By: Christian I. Cabrera


VEX123 - Teaching ICT as Exploratory Course

Connect ultrasonic sensor to nodemcu


VCC VIN
TRIG D3 0
ECHO D4 2
GND GND

CODE:
#include <SPI.h>
#include <Wire.h>
const int trigPin = 0;
const int echoPin = 2;

//define sound velocity in cm/uS


#define SOUND_VELOCITY 0.034
#define CM_TO_INCH 0.393701

long duration;
float distanceCm;
float distanceInch;

void setup(){
Serial.begin(115200);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
}
void loop() {
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);
// Calculate the distance
distanceCm = duration * SOUND_VELOCITY/2;
// Convert to inches
distanceInch = distanceCm * CM_TO_INCH;
// Prints the distance on the Serial Monitor
Serial.print("Distance (cm): ");
Serial.println(distanceCm);
Serial.print("Distance (inch): ");
Serial.println(distanceInch);
delay(1000);
}

Created By: Christian I. Cabrera


VEX123 - Teaching ICT as Exploratory Course

Connect 0.96 OLED Display

OLED PIN BOARD PIN


VIN 3V
GND GND
SCL D1 5
SDA D2 4

Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

#define OLED_RESET D3 // Use D3 (GPIO0) for OLED_RESET


Adafruit_SSD1306 display(OLED_RESET);

void setup() {
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // Initialize the OLED display
display.clearDisplay(); // Clear the display buffer
display.setTextSize(1); // Set text size to 1
display.setTextColor(SSD1306_WHITE); // Set text color to white
display.setCursor(0, 0); // Set the starting position of the text
display.println("Hello, OLED!"); // Display text on the OLED display
display.display(); // Show the text on the OLED display
}

void loop() {
// Your code here
}

Created By: Christian I. Cabrera


VEX123 - Teaching ICT as Exploratory Course

Connect SD Card Module for read and write

GND GND
MISO(MASTER IN SLAVE OUT) D6 12
CLK(SERIAL CLOCK) D5 14
MOSI(MASTER OUT SLAVE IN) D7 13
CS(CHIP SELECT) D8 15
3V 3V

Pin Description
Name
GND This is the ground pin which should be connected with the ground pin of ESP8266.
VCC This pin supplies power to the module. The power supply of ~4.5V-5.5V. The adapter consists of a 3.3V
voltage regulator circuit as well to cater to ESP8266’s power supply range.
CS This is the Chip Select pin for SPI communication.
MOSI This is called the ‘Master Out Slave In.’ It is used as the SPI input to the module.
SCK This is called the ‘Serial Clock’ pin which is used in SPI serial clock output.
MISO This is called the ‘Master in Slave Out.’ It is used as the SPI output from the module.

CODE:
#include <SPI.h>
#include <SD.h>

File myFile;

void setup() {
// Open serial communications and wait for port to open:
Serial.begin(115200);
Serial.print("Initializing SD card...");
if (!SD.begin(15)) {
Serial.println("initialization failed!");
return;
}
Serial.println("initialization done.");

// open the file. note that only one file can be open at a time,
// so you have to close this one before opening another.
myFile = SD.open("test.txt", FILE_WRITE);

// if the file opened okay, write to it:


if (myFile) {
Serial.print("Writing to test.txt...");
myFile.println("testing 1, 2, 3.");
// close the file:
myFile.close();
Serial.println("done.");
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}

Created By: Christian I. Cabrera


VEX123 - Teaching ICT as Exploratory Course

// re-open the file for reading:


myFile = SD.open("test.txt");
if (myFile) {
Serial.println("test.txt:");

// read from the file until there's nothing else in it:


while (myFile.available()) {
Serial.write(myFile.read());
}
// close the file:
myFile.close();
} else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");
}
}

void loop() {
// nothing happens after setup
}

Created By: Christian I. Cabrera

You might also like