Im currently doing a project that uses esp32, l298n motor driver, limit switch and a bipolar stepper motor. Im able to make the stepper motor spin one time every time the limit switch is pressed. I need help for the coding. I want the serial moniter to count every time the motor spin, for example the limit switch is pressed one then the serial moniter shows number 1, and when the limit switch is pressed again the serial moniter shows number 2.
Do you mean count or display the count? The serial monitor can not count anything.
The L298n motor drive is an obsolete chip that has not been made for decades. It can loose 4V from the supply and so your motor may not turn, depending on the motor supply voltage.
It is a bad fit with the ESP32 processor because that only produces 3V3 signals. So it will need level shifting in order to drive it.
For that you will need some sort of photo electric sensor to pick up a pulse on each rotation, so you can calibrate your stepping motor.
Post your code and a schematic of what you thing you are going to use as your hardware setup.
Yes you can still buy the odd number around the world but they are technically rubbish. Especially when it comes to operating with an Arduino. This is because they use transistors in darling pair configuration which gives a very high voltage drop.
There are many many threads saying, in effect, that the motor runs when directly connecting to the power source, but not when connected through this chip.
Also they can never be used in commercial designs because they are not lead free device. So there is great pressure on holders of accent stock to palm them off on unsuspecting hobbyist.
An L298 drops about 2.5volt at 1Amp motor current.
The TB6612 (used on Adafruit motor shield v2) drops about 0.5volt at that current.
But OP seems to use a stepper motor, in which case any brushed DC motor driver could be the wrong choice. We need to know which stepper motor OP is using (type, voltage, current).
Leo..
Yes I would say that it is more efficient than the L298. I have used the SN754410. in the past.
However, using a H-Bridge to drive a stepping motor is a poor choice. The reason is that this forces you to use a voltage that limits the current to a safe value. Many stepping motors are designed with low impedance coils and this would restrict the torque / speed you can get from the motor.
On the other hand if you use a driving circuit designed for stepping motors, like those in the links i posted, you can set the current to be what the motor requires, but use a much higher voltage. The advantage of using a higher voltage is that the current gets into the coils quicker, thus maximizing the torque / speed you can get from the motor.
The drivers do this by monitoring the current, and when it reaches the required current it turns off the voltage. This is known as a chopping regulator. This will also, depending on the actual driver, allow you to have micro stepping, which allows a fraction of the movement for each step.
I think it is actually double that because of the two sides of the H-Bridge.
This is very true. I notice that after 12 replies the OP has only ever made the one initial post.
@adriman do you have anything to say about the replies given in this thread, or have you gone away?
that may not be what you are trying to describe, but that's what a current regulator does, it provides a varying voltage to maintain a constant current