Week 13 - Motor Controller

This lab entailed the creation of a motor controller using pulse-width modulation (PWM) to change the speed of a DC-motor.
Circuit
The circuit includes the XIAO ESP32-S3, a small DC motor, one transistor (TIP120), one diode (IN914), two push buttons, one 4.7kΩ resistor, and two 1kΩ resistors (for the buttons). We also used the XIAO expansion board, which allowed us to power the motor using a dedicated LiPo battery, rather than powering it directly from the microcontroller. Our challenge was to use the push buttons to change the motor speed by adjusting the motor's duty cycle via PWM.

Code
The defining feature of our code was the use of interrupts to handle changes in fan speed. The interrupt routines were instantiated in the setup()
function, and allowed us to control the fan speed asynchronously in response to hardware button presses.


Demo:
We had some issues getting the circuit to respond to button presses consistently, and the oscilloscope in the video shows quite a bit of noise in the circuit. This may have been due to defective buttons or loose jumper cables, but you can see the basic functionality of the system in the video below.
Downloads
The code used for our demo can be downloaded here.