WEEK 10
Output Devices
Group assignment:
- Measure the power consumption of an output device.
- Document your work on the group work page and reflect on your individual page what you learned.
What I Learned From Teamwork
Installing libraries for our devices
In this group assignment, I learned how to search for the libraries for each of the output devices we used, and then we checked that the compilation was correct. For this exercise, we used Adrian Torres's FABXIAO board and, as a first device, an LCD screen.
Checking the power consumption of the devices
For this group assignment, we first created the code to program our LCD screen and our servo motor. Then the devices were connected to the board and the power consumption was measured with a multimeter. We measured the power consumption at rest and then while the devices were operating, and later verified it using the basic power formula. We also confirmed that the servo motor consumes more power than the LCD screen.
Conclusion
In conclusion, the multimeter is a very useful tool for measuring the power consumption of devices. We also confirmed that the servo motor consumes more power than the LCD screen, because the servo motor has an internal motor that requires more energy than the LCD. In addition, we verified that power consumption at rest is lower than power consumption while the devices are operating, since devices demand more energy during operation.
Individual assignment:
- Add an output device to a microcontroller board you've designed and program it to do something.
Testing my PCB with my 9g microservo
First, we verify whether the connections in the schematic are correct.
To do this, we open KiCad and load the project, then open the schematic to confirm the connections. In this case, the servo motor is connected to 5V and to ground, and it is wired to pin D0 on the XIAO.
Now, in the PCB layout, we check the physical connections for the Microservo by tracing each connection.
We place our correctly soldered board and make the corresponding connections.
We generated a first test code to verify that the servo motor works correctly. For this, we used Gemini as a base and made some modifications so the servo motor moves when a button is pressed. We also added an LED that turns on while the servo motor is moving.
#include Servo myServo; int servoPin = D0; int buttonPin = D3; int ledPin = D2; bool state = false; // general state bool lastButtonState = HIGH; void setup() { myServo.attach(servoPin); pinMode(buttonPin, INPUT_PULLUP); pinMode(ledPin, OUTPUT); } void loop() { bool reading = digitalRead(buttonPin); // Detect button press (falling edge) if (lastButtonState == HIGH && reading == LOW) { state = !state; // toggle state if (state) { myServo.write(180); digitalWrite(ledPin, HIGH); } else { myServo.write(0); digitalWrite(ledPin, LOW); } delay(200); // simple debounce } lastButtonState = reading; }
The video shows that the servo motor moves correctly when the button is pressed, and the LED turns on while the servo motor is moving. This indicates that the code works correctly and that the output device is functioning properly.
Testing my PCB with the LDR sensor and the microservo
We generated a second test code to interact with the LDR sensor and the microservo. For this, we used Gemini as a base and made some modifications so the servo motor moves depending on light and darkness, from 0 to 180 degrees.
#include Servo myServo; int ldrPin = D1; // your connection int servoPin = D0; int threshold = 500; // adjust it void setup() { myServo.attach(servoPin); Serial.begin(115200); } void loop() { int ldrValue = analogRead(ldrPin); Serial.println(ldrValue); if (ldrValue > threshold) { myServo.write(180); // light } else { myServo.write(0); // darkness } delay(100); }
The video shows that the microservo responds correctly to the changes in light detected by the LDR sensor. In this case, the test was done with light and darkness: using a flashlight for light and covering the sensor with my finger for darkness.
Running tests for my hexamodular
We used an AI-generated code to interact with the LDR module and the microservo. For this, we used Gemini as a base and made some modifications so the servo motor moves depending on light and darkness, from 0 to 180 degrees. We also added gradual movement so the servo motor moves smoothly instead of abruptly.
#include Servo myServo; int ldrPin = D1; int servoPin = D0; int minLDR = 60; int maxLDR = 900; int currentAngle = 0; // current position void setup() { myServo.attach(servoPin); Serial.begin(115200); } void loop() { int ldrValue = analogRead(ldrPin); // Limit range ldrValue = constrain(ldrValue, minLDR, maxLDR); // Convert to target angle int targetAngle = map(ldrValue, minLDR, maxLDR, 0, 180); // Gradual movement (1 degree per cycle) if (currentAngle < targetAngle) { currentAngle++; } else if (currentAngle > targetAngle) { currentAngle--; } myServo.write(currentAngle); Serial.print("LDR: "); Serial.print(ldrValue); Serial.print(" Target: "); Serial.print(targetAngle); Serial.print(" Current: "); Serial.println(currentAngle); delay(15); // controls speed (lower = faster) }
We observed that our microservo, installed in our cardboard model, moves gradually according to the intensity of the light detected by the LDR sensor.
Conclusions:
- I confirmed that my designed PCB works correctly by integrating a microservo as an output device and controlling it from the XIAO RP2040.
- I verified that the connection between the servo, button, LED, and LDR sensor allows physical and interactive responses to be generated from my own board.
- I learned to program different servo behaviors in Arduino IDE, from simple 0° and 180° movements to smoother gradual motion.
- I understood that calibrating the LDR values is essential to achieve a stable and accurate microservo response to changes in light and darkness.
- This practice reinforced the importance of checking connections, soldering, and pin assignment, since any error directly affects the operation of the output device.
- As a result, I now have a stronger foundation to integrate controlled movement into my final project, applying output devices in a functional way that is consistent with my proposal.