Appearance
WEEK 11 – Networking and Communications
Assignments
Individual Assignment
- Design, build, and connect wired or wireless node(s) with network or bus addresses and local input &/or output device(s)
Group Assignment
- Send a message between two projects
Group Work
Our group work is accessible HERE (add the link)
Individual Work
1. Introduction/Scenario
My aim for this week Individual Assignment is to establish Wi-Fi connection betwwen the Xiao ESP32-S3 on my PCB Extension Board and the Arduino UNO R4 Wi-Fi.
Additionally, a Flying-Fish obstacle sensor (wired to my PCB Extension Board) should scale up the heart shape displayed on the Arduino UNO R4 Wi-Fi when detecting an obstacle. Arduino IDE's Serial Monitor function should display "Small Heart" or "Big Heart" depending on the status of the signal (0/1).
2. Materials Needed
- My PCB Extension Board with Xiao ESP32-S3
- Flying-Fish obstacle sensor (wired to D5 on my PCB)
- Arduino UNO R4 Wi-Fi
- 2 USB cables (for both boards)
- Arduino IDE
PCB Boards:(My Extension Board (with Xiao ESP32-S3) + Arduino UNO R4 Wi-Fi)

Flying-Fish obstacle sensor:
Description: This is a multipurpose infrared sensor which can be used for obstacle sensing, color detection(between basic contrasting colors), fire detection, line sensing, etc and also as an encoder sensor. The sensor provides a digital output. The sensor outputs a logic one(+5V) at the digital output when an object is placed in front of the sensor and a logic zero(0V), when there is no object in front of the sensor. An on board LED is used to indicate the presence of an object. This digital output can be directly connected to an Arduino, Raspberry Pi, AVR, PIC, 8051 or any other microcontroller to read the sensor output.
3. Final Result
Note: The message displayed in the Serial Monitor above is opposite to my original intent "Small Heart"/"Big Heart". This issue has been fixed in the coding section you will find further down.

4. Codes in Arduino IDE
Code for my PCB Extension Board (with Xiao ESP32-S3 and Flying-Fish obstacle sensor) - BROADCASTING
- Prompt to Gemini:
Write an Arduino C++ program for an Xiao ESP32-S3 board that connects to a Wi-Fi network created by an Arduino UNO R4 WiFi configured as an Access Point.
The program should:
- Include the necessary libraries (WiFi.h and WiFiUdp.h).
- Connect to the Wi-Fi network using SSID "UNO_R4_Heart" and password "12345678".
- Use a fixed destination IP address 192.168.4.1 (the UNO R4’s AP address) and UDP port 2390.
- Define a digital input pin, for example D5, that reads input from a pushbutton or sensor.
- Whenever the input pin reads HIGH, send a "1" via UDP to the Arduino UNO R4 (to trigger a "big heart" on its LED matrix). When the input reads LOW, send a "0" (to show a "small heart").
- Print connection and transmission details to the Serial monitor for debugging.
- Use a simple continuous loop() to read the sensor and send corresponding UDP packets.
- Optionally, include commented-out debounce logic for future use, but implement the basic version without it.- Generated code:
#include <WiFi.h>
#include <WiFiUdp.h>
// Replace with the SSID and password of your UNO R4 AP
const char* ssid = "UNO_R4_Heart";
const char* password = "12345678";
// Default IP address of the UNO R4 in AP mode
const char* udpAddress = "192.168.4.1";
const int udpPort = 2390;
WiFiUDP udp;
#define SENSOR_PIN D5
// Variables for non-blocking debounce
//int lastInputState = LOW; // Previous raw reading from the input pin
//int buttonState = LOW; // Current stable button state
//unsigned long lastDebounceTime = 0; // The last time the input pin state changed
//const unsigned long debounceDelay = 50; // Debounce delay in milliseconds (50ms is usually sufficient)
void setup() {
Serial.begin(115200);
// Use standard INPUT mode since the hardware setup includes an external pull-down resistor
pinMode(SENSOR_PIN, INPUT);
// Initialize network connection
Serial.print("Connecting to UNO R4...");
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("\nConnected to UNO R4 Network!");
}
void loop() {
// Read the raw state of the D0 pin
udp.beginPacket(udpAddress, udpPort);
if (digitalRead(SENSOR_PIN) == HIGH)
{
udp.print("1");
Serial.println("Switch Pressed (HIGH) -> Sent: 1 (Big Heart)");
}
else
{
udp.print("0");
Serial.println("Switch Released (LOW) -> Sent: 0 (Small Heart)");
}
udp.endPacket();
}Code for Arduino UNO R4 Wi-Fi - RECEIVING
- Prompt to Gemini:
Write an Arduino C++ program for an Arduino UNO R4 WiFi board that uses the built-in LED matrix and acts as a Wi-Fi Access Point.
The program should:
- Include the necessary libraries (WiFiS3, WiFiUdp, and Arduino_LED_Matrix).
- Create an access point with SSID "UNO_R4_Heart" and password "12345678".
- Listen for UDP packets on port 2390 and read incoming messages into a buffer.
- When receiving a '1' command, display a big heart icon on the LED matrix; when receiving a '0', display a small heart icon.
- Define two hearts (big and small) as 8x12 patterns using hexadecimal arrays created by the Arduino LED Matrix tool.
- Print debugging information to the Serial monitor (e.g., received packet content, AP status).
The code should initialize the Wi-Fi AP in setup(), load the small heart by default, and swap between hearts in the loop() based on incoming UDP messages. Include appropriate delays and make the logic clear and beginner-friendly.- Generated code:
#include <WiFiS3.h>
#include <WiFiUdp.h>
#include <Arduino_LED_Matrix.h>
ArduinoLEDMatrix matrix;
WiFiUDP Udp;
// Set your AP Network credentials
char ssid[] = "UNO_R4_Heart";
char pass[] = "12345678";
unsigned int localPort = 2390; // Local port to listen on
char packetBuffer[255]; // Buffer to hold incoming packet
// Define Big Heart and Small Heart (generated via Arduino LED Matrix tool)
const uint32_t bigHeart[] = {
0x3184a444, 0x42081100, 0xa0040000
};
const uint32_t smallHeart[] = {
0x00000000, 0x01804208, 0x1100a004
};
void setup() {
Serial.begin(115200);
matrix.begin();
// Start the Access Point
Serial.print("Creating AP...");
WiFi.beginAP(ssid, pass);
// Wait a moment for AP to start
delay(2000);
Udp.begin(localPort);
Serial.println("AP Created! Listening for UDP packets...");
// Load Small Heart by default
matrix.loadFrame(smallHeart);
}
void loop() {
// Check if there's data available to read
int packetSize = Udp.parsePacket();
if (packetSize) {
int len = Udp.read(packetBuffer, 255);
if (len > 0) {
packetBuffer[len] = 0; // Null-terminate the string
}
// --- Added Debugging Info ---
Serial.print("Received UDP Packet: ");
Serial.println(packetBuffer[0]);
// ----------------------------
// Process the received command
if (packetBuffer[0] == '1') {
matrix.loadFrame(bigHeart); // Change to Big Heart
} else if (packetBuffer[0] == '0') {
matrix.loadFrame(smallHeart); // Change to Small Heart
}
}
}