connexion-wifi.ino

Arduino Nano ESP32 · File : connexion-wifi.ino · Language : Arduino · Use case : Se connecter au WiFi (2,4 GHz) avec l'ESP32-S3

The Arduino Nano ESP32 WiFi connection uses the full ESP-IDF stack through WiFi.h: station mode, DHCP hostname, RSSI tracking and auto-reconnect. The S3 only sees the 2.4 GHz band — the first trap to know.

Hardware

An Arduino Nano ESP32 (dual-core ESP32-S3, 2.4 GHz Wi-Fi + Bluetooth Low Energy, Nano-compatible physical pinout, native USB, 3.3 V pins only). Nano ESP32, 2.4 GHz access point (no 5 GHz), current credentials.

Wiring

No wiring; the module PCB antenna suffices indoors, avoid metal enclosures.

How it works

WiFi.begin() is asynchronous: poll WiFi.status() with a timeout. RSSI gives received power; the loop watches the link and restarts connection after a drop.

Running it

Install the Arduino ESP32 Boards package (or follow the official Nano ESP32 guide), select Arduino Nano ESP32, upload. Pins are 3.3 V: never feed 5 V into an input. The serial monitor uses native USB.

Variants

Store credentials in NVS and offer a captive-portal setup on first boot, or add WiFi.setSleep(false) to cut latency.

connexion-wifi.ino

// Connexion WiFi de l'Arduino Nano ESP32 (coeur esp32, WiFi.h).
#include <WiFi.h>

const char SSID[] = "MonReseau";
const char PASS[] = "motdepassewifi";

void setup() {
  Serial.begin(115200);
  WiFi.mode(WIFI_STA);
  WiFi.setHostname("nano-esp32");
  WiFi.begin(SSID, PASS);
  Serial.print("Connexion");
  unsigned long t = millis();
  while (WiFi.status() != WL_CONNECTED && millis() - t < 20000) {
    delay(400);
    Serial.print(".");
  }
  if (WiFi.status() == WL_CONNECTED) {
    Serial.println();
    Serial.print(F("IP : "));
    Serial.println(WiFi.localIP());
    Serial.print(F("RSSI : "));
    Serial.print(WiFi.RSSI());
    Serial.println(F(" dBm"));
  } else {
    Serial.println(F(" ECHEC — verif SSID/mot de passe (2,4 GHz)"));
  }
}

void loop() {
  // temoin de liaison : reconnecte si le WiFi tombe
  if (WiFi.status() != WL_CONNECTED) {
    Serial.println(F("Liaison perdue, reconnexion..."));
    WiFi.disconnect();
    WiFi.begin(SSID, PASS);
  }
  delay(2000);
}

← Back to the board