WEEK 10
Output Devices
How the week started
Input device week did give an idea about how these devices work. So the output devices have been chosen after discussing with my instructor Sibin and Saheen.
How the week ended
The week did start off well. As part of the spiral development, I chose to try out a servo motor and a stepper motor. A bit of planning would have been better on my side. I am yet to test the module.
Week 10’s Assignment
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.
Individual assignment:
- Add an output device to a microcontroller board you’ve designed and program it to do something.
Group assignemnt insight
We are calculating the power consumed by 3 NeoPixel lights (WS2812B). In NeoPixel lights, we can change the colors and the brightness. These affect the power consumption.
The board was programmed and then the NeoPixel was set to white light and 50/255 (20%) brightness level. The NeoPixels were powered from Bench Power Supply 9123A with a 5V supply voltage and 0.5A maximum current limit.
The probes were connected to the power and ground pins. A digital multimeter was used to measure the current consumption. The meter was set to current measurement mode. The probes connect the meter in series with the power supply to measure the current consumption. The measured current consumption was 0.0337A at a 5V input supply.
NeoPixel Power Consumption = Current × Voltage = 0.0337A × 5.0V = 0.16W
This means that if we want to run 20 NeoPixels for 3 hours, we will need 3.2Wh or about a 640mAh 5V battery.
With a motor controller board, we powered the servo motor. With a 5V input supply, it consumed 0.011A of current.
Motor Power Consumption = Current × Voltage = 0.011A × 5.0V = 0.05W
If you scroll a bit above you could find the group link. In case you are feeling lazy to do so Here is the link to group assignment
Why I need an Output Device?
This week we are using devices that interact with us. In my final project I need the sun to move in a curved path. This movement of the light is linked to the time in the RTC. The RTC tells time to the microcontroller, then the light moves. This is the output part.
To do this movement I need a motor. There are stepper motors and servo motors.
My understanding of Output devices
How Electric Motors Work
What is a Motor?
An electric motor converts electrical energy into mechanical energy, usually as rotational motion. There are two types of electric motors based on the type of current they use, the coil design, and the magnetic field created.
‖ An Introduction to Motors ‖ What is an Eelctric Motor? ‖ ‖ Youtube - How does an Electric Motor work? ‖
DC motors
The DC motor works by direct current flowing to the commutator. The commutator is connected to the electromagnets. The electromagnets rotate as the polarity changes due to the current. The electromagnets are surrounded by permanent magnets. The rotation happens because of continuous switching of current direction through the commutator and brushes.
DC motors are of two types based on the commutation they use: brushed motor and brushless motor.
Brushed DC Motor
Dc Motors that use mechanical commutation , that is they use brushes as the mechanical contact. The current is delivered as the rotor turns, the brushes make contact with the commutor. These brushes stay in contact with the rotating part (Shaft).
BLDC - Brushless DC Motor
Dc Motors that use elctronic commutation are called Brushless DC motors (BLDC). As it operates without brushes it has high efficiency, long life, and precise control when compared to brushed dc motor.
- ESC (electronic speed controller) electronically commutates the motor by controlling the flow of current in the stator’s winding based on feedback from hall sensors.
- Hall sensor gives real time rotor position feedback, allowing the electronic controller to switch the stator coil current (commutation) at the precise moment for smooth, efficient operation.
Stepper Motor
Stepper motors are a type of brushless motors. It is rotated by direct current. It is an electronic motor which rotates in steps rather than an continuous rotation motion. Since it rotates in steps it has larger number of magnetic poles.
Stepper motors have a relatively large torque, especially at low speeds .
Stepper Motor + Driver
Stepper motors work based on the number of steps required for the motor to rotate. The number of steps can be called input impulses. The driver rotates the motor based on the number of steps it is instructed to move. The driver does not know the exact position of the motor, it only follows the given steps. Therefore, if there are any unexpected changes in the load or the device, the change in position of the rotation is not known by the driver.
‖ Stepper Motors ‖ ‖ Brushless DC Motors vs. Stepper Motors 1 ‖ ‖ Brushless DC Motors vs. Stepper Motors 2 ‖
Servo Motor
Servo motors can roate to a specific angle or position. It has built-in position feedback mechanism therfore allowing precise control over angular velocity and position of motor. the servo motors are usually DC motors but somethimes AC motors. Servo motors are usually rated in kg/cm (kilogram per centimetre), Exanmple:
Stepper motors have a relatively large torque, especially at low speeds .
‖ Servo Motor Basics ‖ servo control of stepper motors ‖ Understanding Basics of Servo Motor Working ‖
Servo motors are usually rated in kg/cm (kilogram per centimetre). This means the torque the motor can provide at a certain distance from the shaft. For example, a 25 kg·cm servo means it can support 25 kg at 1 cm from the shaft. If the distance increases to 2 cm, it can support 12.5 kg. At 3 cm, it can support around 6.25 kg.
If the motor is unable to move due to excess weight, the current consumption increases.
Servo - Closed-loop feedback system
The servo motor control system continuously compares the input signal (desired position) with the feedback signal (actual position) obtained from the position sensor. When there's a difference, the control circuit generates an error signal that drives the motor until the desired position is reached. This closed-loop feedback system ensures precise positioning accuracy.
When connecting a servo motor, make sure the connections are correct:
• Yellow to PWM (Pulse Width Modulation)
• Orange to power
• Brown to ground
Note: One must cross check the pinout diagram of the microcontroller to identify the PWM pins and ensure the servo motor functions correctly.
In the XIAO RP2040, all pins support PWM, so I could connect the servo motor to any pin. I connected it to D0.
Schottky diode controls the direction of current flow. It allows current to pass in only one direction. Therefore, it is used in devices that require low voltage operation and the ability to switch quickly with minimal power loss.
Example: In my PCB this week, I am using a motor that requires 12V and a XIAO that requires only 5V. To ensure that only 5V reaches the XIAO, I used a Schottky diode. The diode provides a low voltage drop and fast switching characteristics, making it suitable for power management circuits.
This makes Schottky diodes an ideal choice for radio frequency applications and devices with low voltage requirements.
MG90S Micro Servo Motor – 180° Rotation
- Weight: 13.4 g
- Dimensions: 22.5 x 12 x 35.5 mm (approx.)
- Stall torque: 1.8 kgf·cm (4.8 V), 2.2 kgf·cm (6 V)
- Operating speed: 0.1 s/60° (4.8 V), 0.08 s/60° (6 V)
- Operating voltage: 4.8 V to 6.0 V
- Dead band width: 5 µs
KiCAD Designs
KiCad Schematic Diagram
Connections in the Schematic Drawing
Electronics Rules Checker
ERC. I added the power flags to the mentioned points. This error occurs because KiCad doesn't understand where the power is connected to the board. This error wouldn't affect the physical aspects of the design.
Components Used
Click A to open the component library and place components. We used Fab PCB components to maintain uniformity. Some additional components were downloaded based on the project requirements.
Images Used for Reference
28BYJ 48 Stepper Motor Arduino Reference
Servo Motor Reference
These were helpful when drawing the schematic diagram.
Image Sources:
28BYJ 48 Pinout and Wiring Diagram
ULN2003 to Unipolar Stepper Motor Circuit
NCP1117 Voltage Regulator Datasheet
KiCAD - PCB Board Editor
The whole view of the board design.
A closer view for reference.
Download and Import Footprint
Update / Change Footprint
TOUCH PAD - How to.

Draw a rectangle. Double click on it. It opens the Properties box.
Choose Corners by Box.
Select Filled Shape.
Line Style: Solid.
Net: Touch Pad. I am choosing this because this is the label I had used for touch. This is a very important step. This decides which net class the rectangular shape is. If I choose power or ground, then it acts like that.
Layer: F.Cu because I am using the front side of the copper clad.
Click OK.
3D Views
The front view.
The back view. Shows the drills.
Milling & Soldering
Roland Modela milling machine used for PCB milling
PCB board after milling
Components placed on the PCB board for soldering
just to show how the vertical header pin was connected on the baord
PCB board and the electronic components that will be used for assembly
JST connector of the stepper motor connected to the PCB board
Testing
Power consumption testing setup for the board
The arrangement is similar to the power consumption testing setup used in the group project.
Testing if the stepper motor works
The rotation of the servo was restricted by holding it from moving. The torque capacity of the servo is less than the load created by the resisting force applied. This shows that the servo consumes more current trying to overcome that resisting force.
Board connections and external power supply setup
The board connections are shown above. It requires power from the Owon power supply because I designed the traces so that the XIAO and the servo motor receive power from the 12V supply.
Finally lets code -Arduino
Servo motor- Sweep- Arduino example
I tested the servo with an example code available in ardunio. If the libray is not available install Servo by Arduino / Michael Margolis. Usually the library comes with Ardunio. File > Examples > Servo > Sweep
/* Sweep
by BARRAGAN <http://barraganstudio.com>
This example code is in the public domain.
modified 28 May 2015
by Michael C. Miller
modified 8 Nov 2013
by Scott Fitzgerald
http://arduino.cc/en/Tutorial/Sweep
*/
#include <Servo.h>
Servo myservo; // create servo object to control a servo
// twelve servo objects can be created on most boards
void setup() {
myservo.attach(D0); // attaches the servo on GIO2 to the servo object
}
void loop() {
int pos;
for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees
// in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
for (pos = 0; pos <= 180; pos += 1) this is to move the arm of the servo from 0 degree to 180 degree. With 500 millisecond delay.
Then the for (pos = 180; pos >= 0; pos -= 1)makes the arm to move back 180 degree, making it to the starting position. After 500 miliseconds it moves according to the prevous code.
Stepper motor- Sweep- Arduino example
I tested the 28byj48 12V stepper motor with an example code available in ardunio. Usually the library is built-in Ardunio. File > Examples > Stepper > stepper_oneRevolution
/*
Stepper Motor Control - one revolution
This program drives a unipolar or bipolar stepper motor.
The motor is attached to digital pins 8 - 11 of the Arduino.
The motor should revolve one revolution in one direction, then
one revolution in the other direction.
Created 11 Mar. 2007
Modified 30 Nov. 2009
by Tom Igoe
*/
#include <Stepper.h>
const int stepsPerRevolution = 200; // change this to fit the number of steps per revolution
// for your motor
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, D7, D8, D9, D10);
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(100);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// step one revolution in one direction:
Serial.println("clockwise");
myStepper.step(stepsPerRevolution);
delay(500);
}
// initialize the stepper library on pins 8 through 11:
Stepper myStepper(stepsPerRevolution, D7, D8, D9, D10);
These are the 4 pins of the microcontroller to which the ULN2003 is connected. It has to be named as shown, or else Arduino doesn't recognise it.
myStepper.step(stepsPerRevolution);
The rotation is in the clockwise direction. The speed is set at 100 RPM by me for the movement to be visible, though the suggested one in the code was 60 RPM.
If the rotation was to be in the anticlockwise direction, then it has to be changed to
myStepper.step(-stepsPerRevolution);. A (minus) - sign is added.
Capacitive Touch + Servo - Xiao Rp2040
create arduino code for capacitive touch pad on the pcb connected to d6 in xiao rp2040. when i touch the touchpad i need the servo motor to do one turn. servo motor is connected to d0 as control pin, then power and ground
Mentioning the microcontroller's name and the pins are important and you can also upload the KiCAD drawing.I mentioend the names of the pins
#include <Servo.h>
// Pin Definitions
const int TOUCH_PIN = D6; // Connected to your PCB pad
const int SERVO_PIN = D0; // Servo control pin
Servo myServo;
// Threshold for touch detection (adjust based on PCB sensitivity)
const int TOUCH_THRESHOLD = 20000;
void setup() {
Serial.begin(115200);
myServo.attach(SERVO_PIN);
// Initialize servo at 0 degrees
myServo.write(0);
pinMode(TOUCH_PIN, INPUT);
Serial.println("System Initialized. Touch the ARDRA pad!");
}
void loop() {
long touchValue = readCapacitivePin(TOUCH_PIN);
// If the sensor value exceeds our threshold, trigger the servo
if (touchValue < TOUCH_THRESHOLD) {
Serial.print("Touch Detected! Value: ");
Serial.println(touchValue);
// Perform "one turn"
// Note: Standard servos move 0-180.
// If it's a 360 continuous servo, this dictates speed/time.
// Assuming standard 180-degree servo:
myServo.write(180);
delay(1000);
myServo.write(0);
delay(500); // Debounce delay
}
delay(10);
}
// Simple capacitive sensing function for RP2040
long readCapacitivePin(int pinToMeasure) {
long total = 0;
for (int i = 0; i < 10; i++) {
pinMode(pinToMeasure, OUTPUT);
digitalWrite(pinToMeasure, LOW);
delayMicroseconds(10);
pinMode(pinToMeasure, INPUT);
long cycles = 0;
while (digitalRead(pinToMeasure) == LOW && cycles < 2000) {
cycles++;
}
total += cycles;
}
return total;
}
Serial.begin(115200); Set the baud rate to this value so the Serial Monitor output is readable.
const int TOUCH_THRESHOLD = 20000; This is the threshold value that is set.
myServo.write(0); This is the position of the servo arm.
if (touchValue < TOUCH_THRESHOLD) {
Serial.print("Touch Detected! Value: ");
Serial.println(touchValue);
The touch value is the threshold value when the pad is touched. The touch value is less than the set threshold value.
What happened on my board was that I forgot to add a 1M ohm resistor, which would have made it a pull up resistor. However, the touch pad still worked. The Serial output was constantly displaying "Touch Detected". The threshold value changed when the pad was touched. This was actually caused by electrical noise from the body. This caused the servo to move.
So, the servo arm moves to 180 degrees and waits for 1000 milliseconds, then comes back to 0 degrees and waits for 500 milliseconds before moving again if a touch has been detected.
delay(10); This delay of 10 milliseconds is for the MCU to reset.
week-9
CSS style + Prompt
Use of Ai












