Nodemcu Module
Nodemcu Module
NODEMCU
ESP32 BASED BOARD
WEMOS D1 MINI
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…
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
CODE:
#include <SPI.h>
#include <Wire.h>
const int trigPin = 0;
const int echoPin = 2;
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);
}
Code:
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
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
}
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);
void loop() {
// nothing happens after setup
}