|
arduino IDEArduino
|
Use a Stepper Motor As a Rotary Encoder
Rotary encoders are great for use in microcontroller projects as an input device but their performance is not very smooth and satisfactory. Also, having a lot of spare stepper motors around, I decided to give them a purpose. So if have some stepper motors lying around and want to make something, get the supplies, and let's get started!
Step 1: Watch the Video
Step 2: Get All the Stuff
For this project, you will need:
- A stepper motor(Unipolar or bipolar).
- An LM358P op-amp chip.
- A 1k Ohm resistor.
- 2x 100k Ohm resistors.
- 2x 4.7k Ohm resistors.
- 2x 47k Ohm resistors.
- An LED.
- Connecting wires.
- Optional components:
- 2x LEDs
- 2x 330 Ohm resistors
Step 3: Study the Circuit Diagram
Thanks, Andriyf1!
Make sure you go through the circuit schematic before proceeding.
Since the two pins in the middle of the header to be connected to the stepper motor are connected to the same point in the circuit(Say, common), you can use a 1x3 header instead of the 1x4 header in the permanent version, but then for connecting a bipolar stepper motor, you will need to connect one wire of the two coils each together and connect them to the common point of the circuit with the remaining two wires to be connected to the pins P and S respectively.
Step 4: Assemble the Circuit on a Breadboard and Test It
Start by placing the op-amp ship on the board and proceed by connecting resistors to the appropriate locations. Try to use shorter wires and avoid entangling the wires. Make sure no connections are loose and are made according to the circuit schematic.
Connect the stepper motor to the amplifier and power it up with a 5-volt power source.
If you are using the optional LEDs, connect each LED's anode to each of the outputs through a 330 Ohm resistor and connect their cathodes to 'GND'.
Step 5: Make a Permanent Version
The right part of the circuit, including the 7-segment display, the long female header pins, and the resistors are not required for this project.
A permanent version of the amplifier will be recommended to make as it will be more compact and practical to use in projects.
Step 6: Test It With a Microcontroller, Upload the Arduino Code
This example controls the brightness of an LED connected to pin 'D13' by adjusting the duty cycle on that output pin, controlled by a rotary encoder.
Step 7: Make the Wiring Connections
Connect the amplifier's power to *'+5-V pin, '-ve' to 'GND' pin, and the output pins to the pins 'D6' and 'D7' of the Arduino board. The sequence of the connection of the output pins of the amplifier to the input pins of the Arduino determines whether the particular direction of movement of the stepper motor will be registered as clockwise or anticlockwise.
*If you are using a microcontroller that works on a 3.3-V logic level, make sure you power the amplifier with 3.3-V DC only!
Step 8: Power Up the Setup
Connect the setup to an appropriate power source(5-12 volt DC) and power it up.
Step 9: Expand It Furthur
Now that you have got it working, you can do all sorts of projects which can be done with a rotary encoder. If you make something with it, try sharing some pictures of your work with the community.
/*
* Arduino code to control the brightness of an LED using a rotary encoder.
*
* Made by Tech Build:-https://www.youtube.com/channel/UCNy7DyfhSD9jsQEgNwETp9g?sub_confirmation=1
*
* Feel free to modify the code to adapt it to your application.
*/
#define inputA 6
#define inputB 7
#define LED 9
int aState;
int aLastState;
int b = 0;
int bb = 0;
void setup() {
// put your setup code here, to run once:
pinMode(inputA,INPUT);
pinMode(inputB,INPUT);
pinMode(LED, OUTPUT);
aLastState = digitalRead(inputA);
}
void loop() {
aState = digitalRead(inputA); // Reads the "current" state of the inputA
// If the previous and the current state of the inputA are different, that means a Pulse has occured
if (aState != aLastState){
if (digitalRead(inputB) != aState && bb < 512) {
bb++;
} else if(bb > 0) bb--;
b = map(bb, 0, 512, 0, 255);
analogWrite(LED, b);
// If the inputB state is different to the inputA state, that means the encoder is rotating clockwise
}
aLastState = aState; // Updates the previous state of the inputA with the current state
}
Use a Stepper Motor As a Rotary Encoder
- Comments(0)
- Likes(1)
- Prasanna K Oct 08,2023
- 0 USER VOTES
- YOUR VOTE 0.00 0.00
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
More by KushagraK7
- Raspberry Pi Pico RC Vehicle SuppliesA Raspberry Pi Pico(Almost any microcontroller can be used here, but the Pico offers great f...
- Stepper Motor Controlled Stepper Motor Without Microcontroller! Step 1: Watch the VideoWatch the video to get a full understanding of the project and learn how to t...
- Automated Model Railroad Layout Running Two Trains I made an Automated Model Train Layout with Passing Siding a while back. Upon request from a fellow ...
- Program the Raspberry Pi Pico With the Arduino IDE The Raspberry Pi Pico is a recently launched product in the family of microcontrollers and its load ...
- Reuse an Old Laptop's Touchpad to Control a Computer! PS/2 laptop touchpads are among the coolest user interface devices to use with a microcontroller. Th...
- Automated Model Railroad Layout With Reverse Loops In one of my previous projects, I showed how to make a Simple Automated Point to Point Model Railroa...
- Use a Stepper Motor As a Rotary Encoder Rotary encoders are great for use in microcontroller projects as an input device but their performan...
- Keyboard Controlled Model Train(PS/2 Interface) Using Arduino microcontrollers, there are a lot of ways of controlling model railway layouts. A keyb...
- Stepper Motor Speed and Direction Control Without a Microcontroller In one of my previous projects, I showed you how to control a stepper motor's speed using a 555 time...
- Smartphone Controlled 4X4 Robot With ESP8266 SuppliesFor this project, you will need:An ESP8266 microcontroller(Node MCU)A dual H-bridge motor dr...
- Touchpad Controlled Digital Servo Motor Here is a quick and simple project where we control a digital servo motor with the slide of our fing...
- Smartphone Controlled Model Railroad With an ESP8266 IntroA while back, I made a project where a stepper motor's position is controlled using a smartphon...
- Simple USB Volume Controller with Arduino This project uses a rotary encoder connected to an Arduino Leonardo to control the audio volume of a...
- Motor Speed and Direction Control with a Web-Server using an ESP01 Supplies:For this project, you will need:An ESP01 microcontroller(You can use any ESP8266-based micr...
- Wi-Fi Controlled Stepper Motor With an ESP Microcontroller Step 1: Get All the Required StuffFor this project, you will need:An ESP8266 microcontrollerA Steppe...
- Simple Automated Model Railroad Loop With Yard Siding Video:Supplies: For this project, you will require:An Arduino microcontroller board compatible with ...
- Laptop Touchpad Controlled Model Railroad Supplies:For this project, you will require:An Arduino microcontroller compatible with Adafruit Moto...
- Control a Stepper Motor with a Slide of Your Finger Supplies:An Arduino microcontroller boardA PS/2 touchpad from a laptop(Try to get one with a Synapti...
-
-
-
kmMiniSchield MIDI I/O - IN/OUT/THROUGH MIDI extension for kmMidiMini
124 0 0 -
DIY Laser Power Meter with Arduino
173 0 2 -
-
-
Box & Bolt, 3D Printed Cardboard Crafting Tools
162 0 2 -