We will learn how to control DC motors using Arduino. We will take a look at some basic techniques for controlling DC motors and make two examples through which we will learn how to control DC motors using the l2 98n driver and the Arduino board. At the end, we will be able to build and control our own Arduino robot car. We can control the speed of a DC motor by simply controlling the input voltage to the motor and most common methods of doing that is by using PWM signal, PWM or pulse width. Modulation is a technique which allows us to adjust the average value of the voltage that is going to the electric device by turning on and off the power. At the fast rate, the average voltage depends on the duty cycle or the amount of time. The signal is on versus the amount of time. The signal is off in a single period of time, so, depending on the size of the motor, we can simply connect an Arduino PWM output to the base of a transistor or a gate of a MOSFET and control. The speed of the motor by controlling the PWM output, the low power Arduino PWM signal switches on and off the gate at the MOSFET through which the high power motor is driven, on the other hand, for controlling the rotation direction. We just need to invert the direction of the current flow through the motor and the most common method of doing that is by using an H bridge.
An H bridge circuit contains four switching elements: transistors or MOSFETs, with the motor at the center forming an H like configuration by activating two particular switches. At the same time, we can change the direction of the current flow does change the rotation direction of the motor. So if we combine these two methods, the PWM and the H bridge, we can save a complete control over the DC motor. There are main DC motor drivers that have these features, and the l2 98n is one of them. The l2 98 M is a dual edged. Rich motor driver which allows speed and direction control of 2 DC motors. At the same time, the module can drive DC motors that have voltages between 5 and 35 volts with big currents up to 2 amps let’s take a closer look at the pin out of the l2 98n module and explain how it works. The module has two screw terminal blocks for the motor, a and B and another screw terminal block for the prop in the VCC for the motor and a 5 volts pin, which can either be an input or output. This depends on the voltage used at the motor VCC. The modules have an onboard 5 volts regulators, which is either enabled or disabled using a jumper. If the motor supply voltage is up to 12 volts, we can enable the 5 volt regulator and the 5 volts pin. Can be used as output, for example, for powering our Arduino board, but if the more voltage is greater than self balls, we must disconnect the jumper, because these voltages will cause the image to the onboard 5 volt regulator.
In this case, the 5 volts pin will be used as input as we need to connect it to a 5 volt power supply in order the IC to work properly. We cannote here that the IC makes a voltage drop of about 2 volts. So, for example, if we use a silver power supply, the voltage at the motors terminal will be about 10 volts, which means that we won’t be able to get the maximum tipped out of our 12 volt DC. Motor next are the logic control inputs, the enable a and enable VPS are used for enabling and controlling the speed of the motor. If a jumper is present on this pin, the model will be enabled and work at maximum speed, and if we remove the jumper, we can connect a PWM input to this pin and in that way, control the speed of the motor. If we connect this pin to a ground, the motor we’ll be disabled. Next, the input 1 and input 2 pins are used for controlling the rotation direction of the motor a and the inputs 3 amp 4 for the motor be using these things. We actually control the switches of the H bridge inside the L 298 and I see if input 1 if flow and input 2 is high, the motor will move forward and vice versa. If the input 1 is high and input 2 is low, the motor will move backwards in case both inputs are the same either low or high.
The motor will stop. The same applies for the inputs. 3 amp 4 and motor B now let’s make some practical applications. In the first example, we will control the speed of a motor using a potentiometer can change the rotation direction using a push button here’s the circuit schematic. So we need an L, 2 98 n driver a DC motor, a potentiometer, a push button and on arduino board here’s the arduino code. So first we need to define the pins and some variables needed for the program. In the second section, we need to set the pin modes and set the initial rotation direction of the motor in the loop section. We start by reading the potentiometer value and then map the value that we get from it, which is from 0 to 1023 to a value from 0 to 255 for the PWM signal, or this 0 to 100 percent duty cycle of the PWM signal. Then, using the analog write function, we send the PWM signal to the enable pin of the l2 98n board which actually drives the motor. Next, we check whether we have press the button and, if that’s true we’ll change the rotation direction of the motor by setting the input 1 and input 2 States inversely, the push button will work as toggle button and each time we press it, it will change the Rotation direction of the motor. So once we have learned this now we can build our own Arduino robot car here’s, the circuit schematic.
All we need is two DC mo ders DL 298 and driver an Arduino board and a joystick for the control. As for the power supply, I chose to use three three point: seven volt lithium batteries providing total of 11 volt. I made the chassis out of three millimeters thick plywood attach the motors to it, using metal brackets attached bills to the motors and in front attached, as we will reel now, let’s take a look at the Arduino code and see how it works after defining the pins. In the loop section we start with reading the juristic x and y axes values. The joystick is actually made of two potentiometers which are connected to the analog inputs of the Arduino and they have values from 0 to 1023, when the joystick stays in its centre position. The value of both potentiometers for the exes is around 500 and sells. We will add a little tolerance and consider the values from 470 to 550 and Center. So if we move the y axis of the joystick beckford and the value goes below the 470, we will set the 2 motors rotation direction to backward using the 4 input pins. Then we will convert the declining values from 470 to 0 into increasing PWM values from 0 to 255, which is actually the speed of the motor similar. If we move the Y axis of the joystick forward and the value goes above 550, we will set the motors to move forward and convert their readings from 550 to 1023 into PWM values from 0 to 255.
If the joystick stays in its centre position, the motor speed will be 0 next let’s see how we use the x axis for the left and right control of the car. So again, first we need to convert the x axis readings into speed values from 0 to 255 for moving left. We use this value to decrease the left motor speed and increase the right motor speed here because of the arithmetic functions. We also use two additional. If statement to confine the range of the motor speed from 0 to 255, the same method is used for moving the car to the right, depending on the applied voltage and motor itself at lower speeds. The motor is not able to start moving and it produces a buzzing sound. In my case, the motors were not able to move if the value of the pwm signal was below 70. Therefore, using these two, if statements, I actually can find the speed range from 70 to 255. At the end, we just send the final motor speed or pwm signal to the enable pings of the l2 98n driver.
arduino 12v Video
arduino 12v news
Posted on Monday September 16, 2019Over-Engineered Cat Door Makes Purrfect Sense Hackaday … Continue Reading »
Posted on Thursday May 23, 2019Linear Actuator Arduino Control Wonderful Engineering … Continue Reading »
Posted on Friday August 30, 2019Your Arduino SAMD21 ADC Is Lying To You Hackaday … Continue Reading »
arduino 12v Social
🔬 Now that you’ve gotten your feet wet, dive into the kit and enjoy all nine experiments. Order yours today: http://bit.ly/2MnQ7fr