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
Send a message between two projects
Design, build and connect wired or wireless node(
Upload source files
1) Introduction
Closing gaps
- Learn about output devices
- Interact more with Arduino IDE
- Discuss the group project
- Develop the individual project
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
// 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;
}
Video demonstration
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
// 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);
}
// 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);
}
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
6) Final results
- Linked to the group assignment page
- Documented how you determined power consumption of an output device with your group
- Documented what you learned from interfacing output device(s) to microcontroller and controlling
- Linked to the board you made in a previous assigment or documented your design and fabrication
- Explain how your code works
- Explained any problems you encountered and how you fixed them
- Include original source code and any design files
- Included a 'hero shot' of your board
7) References files
We learn how to design, make and test a PCB with sensor. Files: in each section