Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino UNO Stepper Motor Controller with Phototransistor and Pushbutton Inputs

View and Edit Project In Cirkit DesignerImage of Arduino UNO Stepper Motor Controller with Phototransistor and Pushbutton Inputs

Circuit Documentation

Summary

This circuit involves an Arduino UNO microcontroller, a phototransistor, a stepper motor, pushbuttons, a ULN 2003 driver, and a resistor. The Arduino UNO reads input from the phototransistor and pushbuttons, and controls the stepper motor through the ULN 2003 driver. The phototransistor measures light intensity, and the pushbuttons allow for manual control of the stepper motor's rotation.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. Phototransistor

    • Description: A light-sensitive transistor.
    • Pins: C (Collector), E (Emitter)
  3. 28BYJ-48 Stepper Motor

    • Description: A 5V stepper motor.
    • Pins: BLUE, PINK, YELLOW, ORANGE, RED
  4. Pushbutton

    • Description: A simple pushbutton switch.
    • Pins: Pin 2, Pin 1, Pin 3, Pin 4
  5. ULN 2003

    • Description: A high-voltage, high-current Darlington transistor array.
    • Pins: IN1, IN2, IN3, IN4, IN5, IN6, IN7, GND, +, COIL1, COIL2, COIL3, COIL4, COIL5
  6. Resistor

    • Description: A 10k Ohm resistor.
    • Pins: pin1, pin2
    • Properties: Resistance = 10k Ohms

Wiring Details

Arduino UNO

Phototransistor

28BYJ-48 Stepper Motor

Pushbutton 1

Pushbutton 2

ULN 2003

Resistor

Code Documentation

#include <Stepper.h>

// Define the number of steps per revolution for the stepper motor
#define STEPS_PER_REV 2048

// Define pin connections
const int motorPin1 = 2; // IN1 on ULN2003 to D2 on Arduino
const int motorPin2 = 3; // IN2 on ULN2003 to D3 on Arduino
const int motorPin3 = 4; // IN3 on ULN2003 to D4 on Arduino
const int motorPin4 = 5; // IN4 on ULN2003 to D5 on Arduino
const int button1Pin = 6; // Pushbutton 1 to D6 on Arduino
const int button2Pin = 7; // Pushbutton 2 to D7 on Arduino
const int photoPin = A0; // Phototransistor to A0 on Arduino

// Initialize the stepper library
Stepper stepper(STEPS_PER_REV, motorPin1, motorPin3, motorPin2, motorPin4);

void setup() {
  // Set up the motor pins as outputs
  pinMode(motorPin1, OUTPUT);
  pinMode(motorPin2, OUTPUT);
  pinMode(motorPin3, OUTPUT);
  pinMode(motorPin4, OUTPUT);

  // Set up the button pins as inputs
  pinMode(button1Pin, INPUT);
  pinMode(button2Pin, INPUT);

  // Initialize serial communication for debugging
  Serial.begin(9600);
}

void loop() {
  // Read the state of the pushbuttons
  int button1State = digitalRead(button1Pin);
  int button2State = digitalRead(button2Pin);

  // Read the value from the phototransistor
  int photoValue = analogRead(photoPin);

  // Print the phototransistor value to the serial monitor
  Serial.print("Light Intensity: ");
  Serial.println(photoValue);

  // Control the stepper motor based on button states
  if (button1State == HIGH) {
    // Rotate the motor clockwise
    stepper.step(1);
  } else if (button2State == HIGH) {
    // Rotate the motor counterclockwise
    stepper.step(-1);
  }

  // Add a small delay to debounce the buttons
  delay(50);
}

This code initializes the stepper motor and sets up the pushbuttons and phototransistor. In the main loop, it reads the state of the pushbuttons and the value from the phototransistor, printing the light intensity to the serial monitor. Depending on the state of the pushbuttons, it rotates the stepper motor clockwise or counterclockwise.