This circuit is designed to control a 28BYJ-48 stepper motor using an Arduino UNO. The motor is driven by a ULN2003 driver. The speed and direction of the motor are controlled by two pushbuttons. A phototransistor is used to detect light intensity and can be used to trigger motor actions based on light levels.
Arduino UNO
Phototransistor
28BYJ-48 Stepper Motor
Pushbutton (1)
Pushbutton (2)
ULN 2003
Resistor
/*
* Arduino UNO Controlled Stepper Motor with Phototransistor and Pushbutton Inputs
*
* This code controls a stepper motor using an Arduino UNO. The motor is driven
* by a ULN2003 driver. The speed and direction of the motor are controlled by
* two pushbuttons. A phototransistor is used to detect light intensity and can
* be used to trigger motor actions based on light levels.
*/
#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 documentation provides a comprehensive overview of the circuit, including a summary, detailed component list, wiring details, and the code used to control the circuit.