Group Assignment:

  • Measure the power consumption of an output device

Individual Assignment:

  • Add an output device to a microcontroller board you've designed, and program it to do something
Have you answered these questions?
Linked to the group assignment page ✅
Documented what you learned from interfacing an output device(s) to your microcontroller and optionally, how the physical property relates to the measured results. ✅
Documented what you learned from interfacing output device(s) to microcontroller and controlling the device(s).✅
Linked to the board you made in a previous assignment or documented your design and fabrication process if you made a new board. ✅
Explained the programming process/es you used.✅
Explained any problems you encountered and how you fixed them.✅
Included original source code and any new design files.✅
Included a ‘hero shot’ of your board.✅

Group assignment

  • Probe an input device(s)'s analog levels and digital signals
  • Document your work on the group work page and reflect on your individual page what you learned
  • Group Training

    During the group project meeting, I had the opportunity to collaborate with my classmate Evelin, with whom we discussed various measurement concepts. I was also able to explain in more detail how these measuring instruments work, such as the multimeter, which measures various electrical properties, such as voltage, current, and resistance, while a power meter measures the energy consumption of a device or system. The multimeter is a general tool for electrical testing, while the power meter focuses on analyzing energy usage.

    With the knowledge acquired, I was able to better understand the use of the instruments and their applications.

    Individual assignment

    Add an output device to a microcontroller board you've designed, and program it to do something

    In week 6, I designed a printed circuit board (PCB), and in week 8, I fabricated a board. You can view the full details at the link: Electronics Design, Electronics Production.

    Printed Circuit

    • In the image you can see the PCB that I made according to my design in Kicad, the tracks are on the bottom layer. online simulator to blink an LED.

    connection of output devices

    1.-Servomotor

    A servomotor is an actuator, or control motor, that allows precise control of an axis' angular position, speed, and acceleration. Essentially, it's an electric motor combined with a feedback system and a controller that allows the axis' position to be adjusted with high precision.

    To control a servo motor with the XIAO ESP32-C3 microcontroller, we have followed the following steps:

    Necessary Components:

    • XIAO ESP32-C3
    • Servomotor (SG90 or similar)
    • Suitable power supply (if the servo motor requires more current than the ESP32 can provide)
    • Connect the servo motor signal pin (PWM) to the GPIO pin of the XIAO ESP32-C3 (in our case, GPIO2)
    • Connect the power pin (+5V) of the servo motor to the 5V pin of the XIAO ESP32-C3.
    • Connect the ground pin (GND) of the servo motor to the GND pin of the XIAO ESP32-C3.

    This is the code I used:

    
    #include   // Official library for ESP32 servos
    
    const int servoPin = 2;  // GPIO2 para control del servo
    Servo miServo;           // Servo object
    int pos = 0;             // Variable for position
    bool girando = true;      // Steering control
    												
    void setup() {
    Serial.begin(115200);
    miServo.attach(servoPin);  // Initialize servo in GPIO2
    														  
    //Configuration to display PWM signal
    Serial.println("Posicion_Servo,PWM_Value"); // Encabezados para Serial Plotter
    }
    														
    void loop() {
    // Giro progresivo (0° a 180°)
    if (girando) {
    pos++;
    if (pos >= 180) girando = false;
    } 
    / Giro regresivo (180° a 0°)
    else {
    pos--;
    if (pos <= 0) girando = true;
    }
    														  
    miServo.write(pos);  // Mueve el servo
    														  
    // Envía datos al Serial Plotter (posición y valor PWM real)
    int pwmValue = map(pos, 0, 180, 500, 2400);  // Convierte ángulo a µs PWM
    Serial.print(pos);         // Posición angular (0-180)
    Serial.print(",");         // Separator
    Serial.println(pwmValue);  // Pulse width in microseconds
    												  
    delay(15);  // Adjust movement speed
    }								
    

    stepper motor electrical diagram

    Output devices connected to the designed PCB

    2.- stepper motor

    A stepper motor is an electromechanical device that converts electrical pulses into discrete mechanical movements. The shaft of a stepper motor rotates in discrete increments when electrical control pulses are applied to it in the correct sequence.

    connection diagram

    For this exercise, the first thing we have done is to make the connection diagram using the CirkitDesigne, online simulator which will allow us to load the programming code into the Arduino IDE, as well as simulate it.

    simulation carried out in circuit designer

    This is the code I used:

    											
    	// Pines XIAO ESP32C3 -> Driver ULN2003 (IN1 a IN4)
    	const int pinMotor1 = 2;  // GPIO2 -> IN1
    	const int pinMotor2 = 3;  // GPIO3 -> IN2
    	const int pinMotor3 = 4;  // GPIO4 -> IN3
    	const int pinMotor4 = 5;  // GPIO5 -> IN4
    	
    	// Configuración motor
    	int velocidadMotor = 1000;  // Microsegundos entre pasos (1000 = suave)
    	int pasosPorVuelta = 4076;  // Pasos para 360° (28BYJ-48)
    	
    	// Secuencia media fase (8 pasos) - Mayor precisión
    	const int tablaPasos[8] = {
    	  B1000, // Paso 1: IN1 activo
    	  B1100, // Paso 2: IN1+IN2
    	  B0100, // Paso 3: IN2 activo
    	  B0110, // Paso 4: IN2+IN3
    	  B0010, // Paso 5: IN3 activo
    	  B0011, // Paso 6: IN3+IN4
    	  B0001, // Paso 7: IN4 activo
    	  B1001  // Paso 8: IN4+IN1
    	};
    	
    	void setup() {
    	  // Configurar pines como salidas
    	  pinMode(pinMotor1, OUTPUT);
    	  pinMode(pinMotor2, OUTPUT);
    	  pinMode(pinMotor3, OUTPUT);
    	  pinMode(pinMotor4, OUTPUT);
    	  
    	  Serial.begin(115200);
    	  Serial.println("IN1,IN2,IN3,IN4"); // Encabezados para Serial Plotter
    	}
    	
    	void loop() {
    	  // Giro horario (2 vueltas)
    	  for (int i = 0; i < pasosPorVuelta * 2; i++) {
    		ejecutarPaso(i % 8, true); // true = horario
    		delayMicroseconds(velocidadMotor);
    	  }
    	  delay(1000);
    	
    	  // Giro antihorario (2 vueltas)
    	  for (int i = 0; i < pasosPorVuelta * 2; i++) {
    		ejecutarPaso(i % 8, false); // false = antihorario
    		delayMicroseconds(velocidadMotor);
    	  }
    	  delay(1000);
    	}
    	
    	void ejecutarPaso(int paso, bool horario) {
    	  int pasoActual = horario ? paso : 7 - paso; // Invierte dirección
    	  
    	  // Escribe señales en los pines
    	  digitalWrite(pinMotor1, bitRead(tablaPasos[pasoActual], 0));
    	  digitalWrite(pinMotor2, bitRead(tablaPasos[pasoActual], 1));
    	  digitalWrite(pinMotor3, bitRead(tablaPasos[pasoActual], 2));
    	  digitalWrite(pinMotor4, bitRead(tablaPasos[pasoActual], 3));
    	
    	  // Envía datos al Serial Plotter (1 = HIGH, 0 = LOW)
    	  Serial.print(bitRead(tablaPasos[pasoActual], 0));
    	  Serial.print(",");
    	  Serial.print(bitRead(tablaPasos[pasoActual], 1));
    	  Serial.print(",");
    	  Serial.print(bitRead(tablaPasos[pasoActual], 2));
    	  Serial.print(",");
    	  Serial.println(bitRead(tablaPasos[pasoActual], 3));
    	}