Week 11

Networking and communications

Learning outcomes

  • Demonstrate workflows used in network design
  • Implement and interpret networking protocols and/or communication protocols
Week 3 cover

Assignment requirements

Group assignment

  • Send a message between two projects
  • Document your work to the group work page and reflect on your individual page what you learned

Individual assignment

  • Design, build and connect wired or wireless node(s) with network or bus addresses and a local input and/or output device(s)

Progress status

Group work Done

Send a message between two projects

Individual work Done

Design, build and connect wired or wireless node(

Documentation Done

Upload source files

1) Introduction

Closing gaps

  • Learn about output devices
  • Interact more with Arduino IDE
  • Discuss the group project
  • Develop the individual project
Step right image

2) Group assignment - Send a message between two projects

For more details visit Fab Lab Peru - Group Assignment: https://fabacademy.org/2026/labs/lima/#page-top


Problems

Projects don't connect

Review connections

Solutions

Review the cable connections

Review the software configuration

Running 1
Connecting devices
Running 1
MQTT Client toolbox installation: The user interface (UI) of MQTTX adopts a chat-based layout, simplifying operational logic. It enables users to establish multiple MQTT connections, thereby facilitating swift testing of MQTT/MQTTS connections, as well as message subscription and publication
Running 3
Setup server using MQTT (Message Queuing Telemetry Transport): Add quick copy options for topic, broker, and host information. Add topic whitespace detection setting to warn about leading/trailing spaces.
Running 4
Setup server
Swimming 2
First message
Swimming 2
Communication between two computers
Camera 1
Programming with Arduino IDE
Camera 1
Programming with Arduino IDE
Camera 1
Programming with Arduino IDE
Camera 1
We need a break :) :) :) :)
// Programming Project 1 - Counter with OLED display
                      // TU_WIFI

                  #include 
                  #include 
                  #include 
                  #include 
                  #include 

                  #define SCREEN_WIDTH 128
                  #define SCREEN_HEIGHT 64

                  Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);

                  // WiFi
                  const char* ssid = "IoT_UP";
                  const char* password = "ti6WzfPsk3WnqZpt8d";

                  // MQTT
                  const char* mqtt_server = "broker.emqx.io";

                  WiFiClient espClient;
                  PubSubClient client(espClient);

                  String mensaje = "";
                  bool nuevoMensaje = false;

                  void setup() {
                    Serial.begin(115200);

                    // OLED
                    Wire.begin(D4, D5);
                    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);

                    display.clearDisplay();
                    display.setTextSize(2);
                    display.setTextColor(SSD1306_WHITE);
                    display.setCursor(0, 20);
                    display.println("Contador");
                    display.display();

                    // WiFi
                    WiFi.begin(ssid, password);
                    while (WiFi.status() != WL_CONNECTED) {
                      delay(500);
                    }

                    // MQTT
                    client.setServer(mqtt_server, 1883);
                    client.setCallback(callback);
                  }

                  void reconnect() {
                    while (!client.connected()) {
                      if (client.connect("XIAO_OLED")) {
                        client.subscribe("fabacademy/contador");
                      } else {
                        delay(2000);
                      }
                    }
                  }

                  void callback(char* topic, byte* payload, unsigned int length) {
                    mensaje = "";

                    for (int i = 0; i < length; i++) {
                      mensaje += (char)payload[i];
                    }

                    Serial.println(mensaje);
                    nuevoMensaje = true;
                  }

                  void loop() {
                    if (!client.connected()) {
                      reconnect();
                    }
                    client.loop();

                    if (nuevoMensaje) {
                      display.clearDisplay();
                      display.setTextSize(3);
                      display.setTextColor(SSD1306_WHITE);
                      display.setCursor(20, 20);
                      display.println(mensaje);
                      display.display();

                      nuevoMensaje = false;
                    }
                  }

            
// Programming Project 2 - Button counter with MQTT
                       // TU_WIFI

                #include 
                #include 

                // WiFi
                const char* ssid = "IoT_UP";
                const char* password = "ti6WzfPsk3WnqZpt8d";

                // MQTT
                const char* mqtt_server = "broker.emqx.io";

                WiFiClient espClient;
                PubSubClient client(espClient);

                int boton = D7;
                int contador = 0;
                bool estadoAnterior = HIGH;

                void setup() {
                  Serial.begin(115200);
                  pinMode(boton, INPUT_PULLUP);

                  WiFi.begin(ssid, password);
                  while (WiFi.status() != WL_CONNECTED) {
                    delay(500);
                  }

                  client.setServer(mqtt_server, 1883);
                }

                void reconnect() {
                  while (!client.connected()) {
                    client.connect("XIAO_BOTON");
                  }
                }

                void loop() {
                  if (!client.connected()) reconnect();
                  client.loop();

                  bool estadoActual = digitalRead(boton);

                  // Detecta pulsación
                  if (estadoAnterior == HIGH && estadoActual == LOW) {
                    contador++;

                    String msg = String(contador);
                    Serial.println(msg);

                    client.publish("fabacademy/contador", msg.c_str());

                    delay(300); // anti rebote
                  }

                  estadoAnterior = estadoActual;
                }

            
Camera 1
Pushing button and counting in the screen
Camera 1
Pushing button and counting in the screen
Video demonstration
<

Project - LM 393 Photosensitive light dependent resistor (LDR)

4) Individual assigment

Problems

Designed microcontroller board doesn't work

Posible solution - make a new board

Step 1 - Protoboard

Mesasure something with the microcontroller Xiao ESP32 C3

Step 2 - Repeat with a new board

Measure and test devices using a multimeter or an oscilloscope

Swimming 2
Considering last week's assignment - input: test with three sensors: left - center - right
Camera 1
Connections at Xiao ESP 32 C3 using the protoboard
// Using three TCRT5000L reflective optical sensor
            // Input devices 
            // Board: Seeed Studio XIAO ESP 32 C3

              #define sensor1 D6   // cambia al GPIO/pin que uses
              #define sensor2 D5   // cambia al GPIO/pin que uses
              #define sensor3 D4   // cambia al GPIO/pin que uses

              void setup() {
                  Serial.begin(115200);
                  pinMode(sensor1, INPUT);  
                  pinMode(sensor2, INPUT);  
                  pinMode(sensor3, INPUT);  
              }

              void loop() {
                  int val1 = digitalRead(sensor1);
                  int val2 = digitalRead(sensor2);
                  int val3 = digitalRead(sensor3);
            
              if(val1==1){
                  Serial.println("izquierda");
                  }
              else if(val2==1){
                  Serial.println("centro");
               }
              else if(val3==1){
                   Serial.println("derecha");
              }
              else{
                    Serial.println("error");
              }
              delay(100);
              }

            
Camera 2
Testing devices
Camera 1
Using three TCRT5000L reflective optical sensor & buzzer output
// Using three TCRT5000L reflective optical sensor & buzzer - Center or not
              // Input devices 
              // Board: Seeed Studio XIAO ESP 32 C3

              #define sensor1 D6   // cambia al GPIO/pin que uses
              #define sensor2 D5   // cambia al GPIO/pin que uses
              #define sensor3 D4   // cambia al GPIO/pin que uses


              void setup() {
                  Serial.begin(115200);
                  pinMode(sensor1, INPUT);  
                  pinMode(sensor2, INPUT);  
                  pinMode(sensor3, INPUT);  
                  pinMode(D3, OUTPUT);
              }

              void loop() {
                int val1 = digitalRead(sensor1);
                int val2 = digitalRead(sensor2);
                int val3 = digitalRead(sensor3);
                if(val1==1){
                  Serial.println("izquierda");
                    digitalWrite (D3, HIGH);
                    delayMicroseconds (5000);
                    digitalWrite (D3, LOW);
                    delayMicroseconds (100000);
                }
                else if(val2==1){
                  Serial.println("centro");
                }
                else if(val3==1){
                  Serial.println("derecha");
                    digitalWrite (D3, HIGH);
                    delayMicroseconds (5000);
                    digitalWrite (D3, LOW);
                    delayMicroseconds (100000);
                }
                else{
                  Serial.println("error");
                    digitalWrite (D3, HIGH);
                    delayMicroseconds (5000);
                    digitalWrite (D3, LOW);
                    delayMicroseconds (100000);
                }
                delay(100);
              }
            
Camera 1
Step 2 - Repeat with PCB and testing using voltimeter and an oscilloscoper

5) Final project advance

Devices

GP2Y0A21YK0F Sharp, infrared distance sensor, 10-80 cm

GP2Y0A02YK0F Sharp, infrared distance sensor, 20-150 cm

2Y0A710K Sharp, infrared distance sensor, 100 a 550cm

Camera 1
Sharp, line detector, screen
Camera 2
Grove- Vision AI Module V2, camera and signal sensort

6) Final results

7) References files

We learn how to design, make and test a PCB with sensor. Files: in each section

Sections