HTMAA 25

home about me final project

week 9: output devices

Published: 2025-11-05

Overview

For this week, we were supposed to add an output device into a microcontroller board we designed. Since the board I made last week was designed to work with motors, my goal was just to plug these motors in and spin them.

Group assignment

Documented here.

PCB

Here is a picture of the board I was working with:

More details about its design and assembly can be found in my documentation for input devices week.

The main detail to note is that my motors are controlled by MOSFETs on pins 0 and 1.

Motors

With my final project in mind and with Anthony’s advice, I chose the following motors:

Both run perfectly fine at 12V, which is what my board will be powered off of.

Testing

I integrated the motors into my sensor code for last week, such that something coming into a 30cm range of the distance sensor would activate one motor, and something activating the beam-break sensor would activate another.

#include <Wire.h>
#include <VL53L1X.h>

#define RED 17
#define GREEN 16
#define BLUE 25

#define MOTORA 0
#define MOTORB 1

#define IRLED 26
#define PHOTOTRANSISTOR 27

VL53L1X sensor;

void setup()
{
  pinMode(RED, OUTPUT); digitalWrite(RED, HIGH); // LEDs on the XIAO turn on at LOW and off at HIGH
  pinMode(GREEN, OUTPUT); digitalWrite(GREEN, HIGH);
  pinMode(BLUE, OUTPUT); digitalWrite(BLUE, HIGH);

  pinMode(MOTORA, OUTPUT);
  pinMode(MOTORB, OUTPUT);

  pinMode(IRLED, OUTPUT); digitalWrite(IRLED, HIGH);
  pinMode(PHOTOTRANSISTOR, INPUT);

  Wire.begin();
  Wire.setClock(400000); // use 400 kHz I2C

  sensor.setTimeout(500);
  if (!sensor.init()) {
    digitalWrite(RED, LOW);
    while (1);
  }

  sensor.setDistanceMode(VL53L1X::Long);
  sensor.setMeasurementTimingBudget(15000);
  sensor.startContinuous(15);
}

void loop()
{
  int dist = sensor.read();
  if (dist < 300) {
    digitalWrite(BLUE, LOW);
    digitalWrite(MOTORA, HIGH);
  } else {
    digitalWrite(BLUE, HIGH);
    digitalWrite(MOTORA, LOW);
  }

  int beam = analogRead(PHOTOTRANSISTOR);
  if (beam < 60) {
    digitalWrite(GREEN, LOW);
    digitalWrite(MOTORB, HIGH);
  }
  else {
    digitalWrite(GREEN, HIGH);
    digitalWrite(MOTORB, LOW);
  }

}

Here it is in action on 5V laptop power:

For 12V, I tested the motors separately so that I could hold each motor while holding my phone to film.

Takeaways

I was busy with a lot of my other classes this week, so I’m glad I kept it simple. Happy to see my board from last week works, and now just have to catch up on doing some final project stuff!