How to, Programming, Tech

Arduino ESP32 | How to Connect to a WiFi network?

ESP32_Espressif_ESP-WROOM-32_Dev_Board

ESP32 Espressif ESP-WROOM-32 Dev Board

What is Arduino ESP32?

Arduino ESP32  is a low-cost, low-power device based on a microcontroller integrated with WiFi and dual-mode Bluetooth. ESP32 is created and developed by Espressif Systems, a Shanghai-based Chinese company. It is a successor to the ESP8266 microcontroller.

What will we learn?

  1. Connect an ESP32 to a WiFi network.
  2. After a successful connection, perform an action. i.e. blink an onboard LED.

Requirement

  1. ESP32
  2. Platform.io on Visual Studio Code or equivalent

Steps :

  1. Install Platform.io on Visual Studio and the necessary drivers for your Arduino device.
  2. Use the following code.
#include <Arduino.h>
#include "WiFi.h"
const char* ssid = "your_ssid";
const char* password =  "your_password";

void setup() {
  // put your setup code here, to run once:
  pinMode(2, OUTPUT);
  WiFi.begin(ssid, password);
}
void loop() {
  // put your code here, to run repeatedly:
  Serial.begin(115200);
   while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.println("Connecting to WiFi..");
    digitalWrite(2, LOW);
  }
   Serial.println("Connected to the WiFi network");
  digitalWrite(2, HIGH);
  delay(1000);
  digitalWrite(2, LOW);
  delay(1000);
} 
  1. While uploading the code, press the boot button and EN (reset) button at once on your ESP32. Wait until the upload is complete.
  2. To view the monitor output on the terminal, press the electric plug icon.
  3. If this is your first time printing the message to the serial monitor, go to platform.ino file and add the following code.
;Custom Serial Monitor speed (baud rate)
monitor_speed = 115200 

The baud rate of 115200 defined in the setup function helps the serial connection to work properly.

Output

Arduino ESP32 wifi output screen

Just in case, if your ESP32 device can not be detected in your OS, install the appropriate driver to fix the issue.

Click here to read about “How to download all the images from the website?

Spread the love

Leave a Reply