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

Arduino-Controlled Stepper and DC Motor Winding Machine with LCD Interface and IR Sensing

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Stepper and DC Motor Winding Machine with LCD Interface and IR Sensing

Circuit Documentation

Summary

This circuit is designed to control a stepper motor and a DC motor using an Arduino UNO microcontroller. It includes a user interface with a 16x2 LCD display and a 4x4 membrane matrix keypad for input. The circuit also features a rotary encoder for additional input, an IR sensor for detecting motor rotations, and a potentiometer for variable input. The A4988 stepper motor driver is used to drive a Nema 17 stepper motor, and the L298N motor driver controls the DC motor. Power is supplied to the circuit components through a common power supply.

Component List

A4988 Stepper Motor Driver (Red)

DC Motor

Rotary Encoder

Arduino UNO

Potentiometer

IR Sensor

Nema 17 Stepper Motor (42-STH48)

16x2 LCD

4x4 Membrane Matrix Keypad

Power Supply

L298N DC Motor Driver

Wiring Details

A4988 Stepper Motor Driver (Red)

DC Motor

Rotary Encoder

Arduino UNO

Potentiometer

IR Sensor

Nema 17 Stepper Motor (42-STH48)

16x2 LCD

4x4 Membrane Matrix Keypad

Power Supply

L298N DC Motor Driver

Documented Code

#include <LiquidCrystal.h>
#include <Keypad.h>

// LCD pins
LiquidCrystal lcd(A0, A1, A2, A3, A4, A5);

// Keypad setup
const byte ROWS = 4; 
const byte COLS = 4; 
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte rowPins[ROWS] = {3, 4, 5, 6}; 
byte colPins[COLS] = {7, 8, 9, 10}; 
Keypad keypad = Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);

// Motor pins
const int stepPin = 6;
const int dirPin = 7;
const int dcMotorPin1 = 8;
const int dcMotorPin2 = 9;
const int dcMotorEnable = 10;
const int irSensorPin = 2;

int turns = 0;
int targetTurns = 0;

void setup() {
  lcd.begin(16, 2);
  lcd.print("Enter Turns:");
  
  pinMode(stepPin, OUTPUT);
  pinMode(dirPin, OUTPUT);
  pinMode(dcMotorPin1, OUTPUT);
  pinMode(dcMotorPin2, OUTPUT);
  pinMode(dcMotorEnable, OUTPUT);
  pinMode(irSensorPin, INPUT);
}

void loop() {
  char key = keypad.getKey();
  if (key) {
    if (key >= '0' && key <= '9') {
      targetTurns = targetTurns * 10 + (key - '0');
      lcd.setCursor(0, 1);
      lcd.print(targetTurns);
    } else if (key == '#') {
      lcd.clear();
      lcd.print("Winding...");
      startWinding();
      lcd.clear();
      lcd.print("Done!");
    }
  }
}

void startWinding() {
  turns = 0;
  attachInterrupt(digitalPinToInterrupt(irSensorPin), countTurns, RISING);
  
  digitalWrite(dcMotorEnable, HIGH);
  digitalWrite(dcMotorPin1, HIGH);
  digitalWrite(dcMotorPin2, LOW);
  
  while (turns < targetTurns) {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(800);
    digitalWrite(stepPin, LOW);
    delayMicroseconds(800);
  }
  
  digitalWrite(dcMotorEnable, LOW);
  detachInterrupt(digitalPinToInterrupt(irSensorPin));
}

void countTurns() {
  turns++;
}

This code is designed to run on the Arduino UNO microcontroller. It initializes the LCD and keypad, sets up the motor control pins, and defines the main loop and functions for the user interface and motor control. The startWinding function is responsible for controlling the stepper motor based on the number of turns entered by the user through the keypad. The IR sensor is used to count the number of turns made by the motor.