How to use the Arduino UNO R4 WIFI board step by step

How to use the Arduino UNO R4 WIFI board step by step

Hello and welcome back. In this tutorial, we will learn how to use the Arduino UNO R4 WIFI board step by step. For that, I used a simple web server example. You can make a smart bulb using this knowledge.

Arduino UNO R4 WIFI

Two new boards have been released under the Arduino UNO R4 category: R4 MINIMA and R4 WIFI. I have already discussed the R4 MINIMA board in a previous article, which you can read through this link. This board is also based on the 32-bit RA4M1 series microcontroller (R7FA4M1AB3CFM#AA0) from Renesas. It features a 48 MHz Arm Cortex-M4 microprocessor. Additionally, it includes the ESP32-S3 Wi-Fi module (ESP32-S3-MINI-1-N8) and a 12 x 8 LED matrix. Also, it has large memory like 256 kB Flash, 32kB SRAM, and 8kB EEPROM. Now, let’s take a look at the features of this microcontroller.

  • 256 kB flash / 32 kB SRAM / 8 kB data flash (EEPROM)
  • Real-time Clock (RTC)
  • 4x Direct Memory Access Controller (DMAC)
  • up to 14-bit ADC
  • up to 12-bit DAC
  • OPAMP
  • 1x CAN bus
How to use the Arduino UNO R4 WIFI board step by step

ESP32-S3-MINI-1-N8 module

That is the secondary MCU of this board. This board is mainly based on the Xtensa® dual-core 32-bit LX7 microprocessor. Also, it includes the 40 MHz crystal oscillator and operates the 3.3v voltage. With this module, we can utilize both WIFI and Bluetooth technologies. You can see the features of this module below.

  • Xtensa® dual-core 32-bit LX7 microprocessor
  • 40 MHz crystal oscillator
  • up to 240 MHz clock speed
  • 384 kB ROM
  • 512 kB SRAM
  • Up to 150 Mbps bit rate

Now you can see the Wi-Fi and Bluetooth features included in this module.

Wi-Fi®
  • Wi-Fi® support with 802.11 b/g/n standard (Wi-Fi® 4)
  • Bit rate at up to 150 Mbps
  • 2.4 GHz band

Bluetooth®

  • Bluetooth® 5 LE support
How to use the Arduino UNO R4 WIFI board step by step

LED matrix

This Arduino UNO R4 WIFI board includes the 12 x 8 LED (96 dots)matrix. We can use this matrix for displaying animations, sensor data, or any kind of characters. It depends on your requirement. For that, you can use the tool below. We will use this tool for our future projects.

How to use the Arduino UNO R4 WIFI board step by step

We can use these boards for beginner-level projects, IOT projects, or any kind of project. Also, you can use the IOT cloud for IOT projects. In this project, I haven’t used the IOT cloud. We will use it for future projects.

Key benefits of this board

  • More memory and faster clock – With this benefit, we can handle more complex projects.
    • Motor control
    • Data sensing
    • Scientific equipment
    • Network-connected projects
  • Compatibility with UNO R3 – we can use the existing shields and projects can be easily ported to the new board.
  • New built-in peripherals – It includes 12-bit DAC, CAN BUS, and OP AMP.
  • USB-C® – We can use the USB type-C port to connect it to the computer.
  • SWD connector – We can use it for connecting external debuggers.
  • HID (Human Interface Device) device — It enables to simulate a mouse or keyboard when connected to a computer via a USB cable.
  • Wi-Fi® and Bluetooth® — These technologies are incorporated into the ESP32-S3 module.
  • Qwiic I2C connector– We can connect one or multiple nodes chosen from the huge Qwiic ecosystem.
  • Support for battery-powered RTC – We can use these pins to run the internal Real-Time Clock.
  • LED matrix — In this board includes a 12X8 LED matrix.
  • Diagnostics for runtime errors – In this board includes the error-catching mechanism. That’s we can see the runtime crashes with detailed explanations and hints about the code.
  • Larger voltage range – allowing power supplies up to 24V.

PIN diagram of this Arduino UNO R4 MINIMA board

How to use the Arduino UNO R4 WIFI board step by step

Top specification of this board

  • Microcontroller : Renesas RA4M1 (Arm® Cortex®-M4)
  • Memory:  256 KB Flash, 32 KB SRAM / ESP32-S3: 384 kB ROM, 512 kB SRAM
  • Operating voltage: 5 V (ESP32-S3 is 3.3 V)
  • Input voltage: 6-24 V
  • DC Current per I/O Pin: 8 mA
  • Clock speed: 48 MHz / ESP32-S3: up to 240 MHz
  • Programming port: USB-C®
  • Digital pins: 14
  •  PWM: 6
  • ADC: 6 (14-bit)
  • DAC: 1 (12-bit)
  • SPI: 1
  • I2C: 1
  • CAN: 1
  • Width: 68.85 mm
  • Length: 53.34 mm

OK, let’s do this project step by step. The required components are given below.

Disclosure: These Amazon links are Affiliate links. As an Amazon Associate, I earn from qualifying purchases.

Step 1

Firstly, identify these components.

Step 2

Secondly, connect the relay module to the Arduino board. For that, use the circuit diagram below.

How to use the Arduino UNO R4 WIFI board step by step

Step 3

Thirdly, connect the Arduino R4 WIFI board to the computer. And then, install the Arduino UNO R4 boards on the Arduino IDE. For that, follow the steps below.

  • First, open your Arduino IDE and go to preferences. And then, click the additional board manager URL button.
  • Now, include the Arduino R4 Renesas Url.
  • Windows —> http://downloads.arduino.cc/packages/package_renesas_index.json
  • MacOS —>
    • http://downloads.arduino.cc/packages/package_renesas_index.json
    • http://downloads.arduino.cc/packages/package_staging_index.json
  • Next, go to the board manager and search for “r4” on it. And then, install the boards.

OK, Arduino UNO R4 boards are ready for you.

Step 4

Now, copy and paste the following program into the Arduino IDE.

#include "Arduino_LED_Matrix.h"
#include "WiFiS3.h"
#define relay 2

ArduinoLEDMatrix matrix;

const uint32_t hi[] = {
  0xcdfcdfcc,
  0x4fc4fc4c,
  0xc4cdfcdf,
  66
};

char ssid[] = "***********"; //Enter your WIFI SSID
char pass[] = "*************";   //Enter your WIFI password
int keyIndex = 0;      // your network key index number (needed only for WEP)

String output = "off";
String header;

// Current time
unsigned long currentTime = millis();
unsigned long previousTime = 0;
// Define timeout time in milliseconds (example: 2000ms = 2s)
const long timeoutTime = 2000;


int status = WL_IDLE_STATUS;
WiFiServer server(80);

void setup() {
  Serial.begin(9600); // initialize serial communication
  matrix.begin();
  pinMode(relay, OUTPUT); // set the Relay pin mode
  digitalWrite(relay, HIGH);

  // check for the WiFi module:
  if (WiFi.status() == WL_NO_MODULE) {
    Serial.println("Communication with WiFi module failed!");
    // don't continue
    while (true);
  }

  String fv = WiFi.firmwareVersion();
  if (fv < WIFI_FIRMWARE_LATEST_VERSION) {
    Serial.println("Please upgrade the firmware");
  }

  // attempt to connect to WiFi network:
  while (status != WL_CONNECTED) {
    Serial.print("Network named: ");
    Serial.println(ssid);

    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    // wait 10 seconds for connection:
    delay(10000);
  }
  server.begin(); // start the web server on port 80
  printWifiStatus(); // you're connected now, so print out the status
}


void loop() {
  webServer();
  LEDMatrix();
}

void LEDMatrix() {
  matrix.loadFrame(hi);
}

void webServer() {
  WiFiClient client = server.available();   // Listen for incoming clients
  if (client) {                             // If a new client connects,
    Serial.println("New Client.");          // print a message out in the serial port
    String currentLine = "";                // make a String to hold incoming data from the client
    currentTime = millis();
    previousTime = currentTime;
    while (client.connected() && currentTime - previousTime <= timeoutTime) { // loop while the client's connected
      currentTime = millis();
      if (client.available()) {             // if there's bytes to read from the client,
        char c = client.read();             // read a byte, then
        Serial.write(c);                    // print it out the serial monitor
        header += c;
        if (c == '\n') {                    // if the byte is a newline character
          // if the current line is blank, you got two newline characters in a row.
          // that's the end of the client HTTP request, so send a response:
          if (currentLine.length() == 0) {
            // HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
            // and a content-type so the client knows what's coming, then a blank line:
            client.println("HTTP/1.1 200 OK");
            client.println("Content-type:text/html");
            client.println("Connection: close");
            client.println();

            // turns the relay on and off
            if (header.indexOf("GET /on") >= 0) {
              output = "on";
              digitalWrite(relay, LOW);
            } else if (header.indexOf("GET /off") >= 0) {
              output = "off";
              digitalWrite(relay, HIGH);
            }

            // Display the HTML web page
            client.println("<!DOCTYPE html><html>");
            client.println("<head><meta name=\"viewport\" content=\"width=device-width, initial-scale=1\">");
            client.println("<link rel=\"icon\" href=\"data:,\">");
            // CSS to style the on/off buttons
            // Feel free to change the background-color and font-size attributes to fit your preferences
            client.println("<style>html { font-family: Helvetica; display: inline-block; margin: 0px auto; text-align: center;}");
            client.println(".on { background-color: #FF0000; border: 5px; color: white; padding: 16px 40px; border-radius: 20px;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}");
            client.println(".off {background-color: #000000;border: 5px; color: white; padding: 16px 40px; border-radius: 20px;");
            client.println("text-decoration: none; font-size: 30px; margin: 2px; cursor: pointer;}</style></head>");


            // Web Page Heading
            client.println("<body><h1>SriTu Hobby IOT system</h1>");
            client.println("<p>Relay " + output + "</p>");
            if (output == "off") {
              client.println("<p><a href=\"/on\"><button class=\"off\">OFF</button></a></p>");
            } else {
              client.println("<p><a href=\"/off\"><button class=\"on\">ON</button></a></p>");
            }

            client.println("</body></html>");

            // The HTTP response ends with another blank line
            client.println();
            // Break out of the while loop
            break;
          } else { // if you got a newline, then clear currentLine
            currentLine = "";
          }
        } else if (c != '\r') {  // if you got anything else but a carriage return character,
          currentLine += c;      // add it to the end of the currentLine
        }
      }
    }
    // Clear the header variable
    header = "";
    // Close the connection
    client.stop();
    Serial.println("Client disconnected.");
    Serial.println("");
  }
}

void printWifiStatus() {
  // print the SSID of the network you're attached to:
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your board's IP address:
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

  // print the received signal strength:
  long rssi = WiFi.RSSI();
  Serial.print("signal strength (RSSI):");
  Serial.print(rssi);
  Serial.println(" dBm");
  // print where to go in a browser:
  Serial.print("Now open this URL on your browser --> http://");
  Serial.println(ip);
}
  • Now, enter your WIFI SSID and password.
  • And then, select the board and port. After, click the upload button.
  • Now, open Serial Monitor and copy(Ctrl + C) your IP address. (In this case, you need to enable the WIFI connection)
How to use the Arduino UNO R4 WIFI board step by step

Step 5

And then, remove the USB cable and connect the bulb holder to the relay module. I used a plug top for connecting the AC voltage. Also, you can connect any component instead of an AC bulb holder. For that, use the circuit diagram above.

Step 6

Next, install the AC bulb and provide an AC voltage using a plug top. Finally, connect the 5VDC power supply using a DC barrel connector.

Step 7

Now, paste the IP address on your browser. (You copied earlier) Then, you can see the simple web application.

You can also control it using your smartphone. For that enter your IP address on your mobile browser. Then, you can see the simple web application.

OK, enjoy this project. The full video guide is below. We hope to see you in the next project or tutorial.

How to use the Arduino UNO R4 WIFI board step by step

Similar Posts

One Comment

  1. my code:

    #include

    char ssid[] = “****”;
    char pass[] = “****”;
    int status = WL_IDLE_STATUS;
    WiFiServer server(80);

    void setup() {
    Serial.begin(9600);
    setupWiFi();
    }

    void loop() {
    webServer();
    }

    void setupWiFi() {
    // initialize with the SSID, password, and encryption type
    WiFi.begin(ssid, pass);

    while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println(“Connecting to WiFi…”);
    }

    Serial.println(“Connected to WiFi”);
    printWifiStatus();
    server.begin();
    }

    void webServer() {
    WiFiClient client = server.available();
    if (client) {
    Serial.println(“New Client.”);
    String currentLine = “”;
    while (client.connected()) {
    if (client.available()) {
    char c = client.read();
    Serial.write(c);
    currentLine += c;
    if (c == ‘\n’) {
    if (currentLine.length() == 1) {
    // HTTP request has ended, process it
    processHttpRequest(client);
    break;
    }
    currentLine = “”;
    }
    }
    }
    client.stop();
    Serial.println(“Client disconnected.”);
    Serial.println(“”);
    }
    }

    void processHttpRequest(WiFiClient client) {
    // Check if the HTTP request is for the index page
    if (client.find(“GET / HTTP/1.1”)) {
    sendIndexPage(client);
    } else {
    // Handle other requests or routes here
    // …

    // If no matching route is found, send a 404 response
    sendNotFoundResponse(client);
    }
    }

    void sendIndexPage(WiFiClient client) {
    String content = “Hello WorldHello World!”;
    response += “Content-Length: ” + String(content.length()) + “\r\n”;

    client.print(response);
    client.flush();
    client.stop();
    }

    void sendNotFoundResponse(WiFiClient client) {
    String response = “HTTP/1.1 404 Not Found\r\n”;
    response += “Content-type: text/html\r\n”;
    response += “Connection: close\r\n”;
    response += “\r\n”;
    response += “404 Not Found”;
    response += “404 Not Found”;
    response += “”;

    client.print(response);
    client.flush();
    client.stop();
    }

    void printWifiStatus() {
    Serial.print(“SSID: “);
    Serial.println(WiFi.SSID());
    IPAddress ip = WiFi.localIP();
    Serial.print(“IP Address: “);
    Serial.println(ip);
    long rssi = WiFi.RSSI();
    Serial.print(“Signal strength (RSSI):”);
    Serial.print(rssi);
    Serial.println(” dBm”);
    Serial.print(“Now open this URL in your browser –> http://“);
    Serial.println(ip);
    }

Leave a Reply

Your email address will not be published. Required fields are marked *