Question

In: Electrical Engineering

Write a program By using ardino and h-bridg and dc motor No sensoer. VICHAEL start from...

Write a program By using ardino and h-bridg and dc motor
No sensoer.
VICHAEL start from A move some distance till point B
than turn 90 degree than move some distance till C
than turn 90 degree and move Tell point D
than turn 90 degree and move till start point which is A
As square moving (, starting from A and back to A)

Solutions

Expert Solution

Let's consider the H bridge has an enable pin like most standard H bridges and two control pins as shown in the block diagram below. ( I'll be considering the standard L293D H bridge for example code)

We need two such H bridges to control the two motors ( left and right ) individually. I assume that Arduino Uno is used but the code will be compatible with any Arduino. The code is commented describing itself clearly. Screenshots of the code have been attached as well for easy readability.

#define left_dir1_pin 12 // Defining all the pins for different signals

#define left_dir0_pin 11 // If some of these pins are already used they can

#define right_dir1_pin 10 // be changed here to any other GPIO pin.

#define right_dir0_pin 9

#define left_enable_pin 8

#define right_enable_pin 7

#define forward_delay 2000 // This delay decides how far the bot

// moves in straight lines

#define turn_delay 1500 // This defines how much the bot turns

// This delay will have to be adjusted

// based on the motor and power supply

// to achieve 90 degree turns.

void setup() {

pinMode(left_dir1_pin,OUTPUT); // Here we set all the control signals to the

pinMode(left_dir0_pin,OUTPUT); // H-bridge as outputs so that we can write

pinMode(right_dir1_pin,OUTPUT); // high and low signals to the inputs of the

pinMode(right_dir0_pin,OUTPUT); // H-bridge

pinMode(left_enable_pin,OUTPUT);

pinMode(right_enable_pin,OUTPUT);

}

void forward()

{

digitalWrite(left_dir1_pin,HIGH); // Set left dir1 pin high

digitalWrite(left_dir0_pin,LOW); // Set left dir0 pin low

digitalWrite(right_dir1_pin,HIGH); // Set right dir1 pin high

digitalWrite(right_dir0_pin,LOW); // Set right dir0 pin low

digitalWrite(left_enable_pin,HIGH); // Care must be taken if enable is active high or

digitalWrite(right_enable_pin,HIGH); // active low. Here we enable the outputs

}

void left()

{

digitalWrite(left_dir1_pin,LOW); // Set left dir1 pin low

digitalWrite(left_dir0_pin,HIGH); // Set left dir0 pin high

digitalWrite(right_dir1_pin,HIGH); // Set right dir1 pin high

digitalWrite(right_dir0_pin,LOW); // Set right dir0 pin low

digitalWrite(left_enable_pin,HIGH); // Care must be taken if enable is active high or

digitalWrite(right_enable_pin,HIGH); // active low. Here we enable the outputs

}

void right()

{

digitalWrite(left_dir1_pin,HIGH); // Set left dir1 pin high

digitalWrite(left_dir0_pin,LOW); // Set left dir0 pin low

digitalWrite(right_dir1_pin,LOW); // Set right dir1 pin low

digitalWrite(right_dir0_pin,HIGH); // Set right dir0 pin high

digitalWrite(left_enable_pin,HIGH); // Care must be taken if enable is active high or

digitalWrite(right_enable_pin,HIGH); // active low. Here we enable the outputs

}

void back()

{

digitalWrite(left_dir1_pin,LOW); // Set left dir1 pin low

digitalWrite(left_dir0_pin,HIGH); // Set left dir0 pin high

digitalWrite(right_dir1_pin,LOW); // Set right dir1 pin low

digitalWrite(right_dir0_pin,HIGH); // Set right dir0 pin high

digitalWrite(left_enable_pin,HIGH); // Care must be taken if enable is active high or

digitalWrite(right_enable_pin,HIGH); // active low. Here we enable the outputs

}

void halt()

{

digitalWrite(left_enable_pin,LOW); // Care must be taken if enable is active high or

digitalWrite(right_enable_pin,LOW); // active low. Here we disable the outputs

}

void loop() {

forward(); // Move forward from A

delay(forward_delay); // Delay to reach point B

left(); // Turn left (90 degrees)

delay(turn_delay);

forward(); // Move from point B

delay(forward_delay); // Delay to reach point C

left(); // Turn left (90 degrees)

delay(turn_delay);   

forward(); // Move from point C

delay(forward_delay); // Delay to reach point D

left(); // Turn left (90 degrees)

delay(turn_delay);   

forward(); // Move from point D

delay(forward_delay); // Delay to reach point A again

halt(); // Stop the bot

while(1); // Infinite loop

}


Related Solutions

Control DC Using PIC18f46k20 and MPLAB IDE v8.8, write a program that can 1. Start and...
Control DC Using PIC18f46k20 and MPLAB IDE v8.8, write a program that can 1. Start and Stop the motor 2.Vary The motor Speed 3.Change the direction of the motor rotation 4.Display motor speed in OLED screen using c of MPLAB IDE v8.8 please test the code before posting
Compare the brushed motor (DC motor) and a brushless motor (Induction Motor) in FIVE aspects.
Compare the brushed motor (DC motor) and a brushless motor (Induction Motor) in FIVE aspects.
What is the process for reversing a DC motor?
What is the process for reversing a DC motor?
In order for a dc motor to function properly, it must be protected from physical damage...
In order for a dc motor to function properly, it must be protected from physical damage during the starting period. At starting conditions, the motor is not rotating, and armature generated voltage EA = 0 V. Since the internal resistance of a normal DC motor is very low, a very high current flows. It is possible for a motor to be severely damaged by such currents, even if they last for only a moment. A solution to the problem of...
how can I mount a 3" wheel on a motor with a 52mm dc motor
how can I mount a 3" wheel on a motor with a 52mm dc motor
Can you do brief research on : - Separetely excited DC motor applications - Shunt DC...
Can you do brief research on : - Separetely excited DC motor applications - Shunt DC motor applications - Series DC motor applications
Starting from the dynamic equations of the PM DC motor obtain the voltage-to-speed transfer function in...
Starting from the dynamic equations of the PM DC motor obtain the voltage-to-speed transfer function in s-domain. Draw the block diagram.
Starting from the dynamic equations of the PM DC motor obtain the voltage-to-speed transfer function in...
Starting from the dynamic equations of the PM DC motor obtain the voltage-to-speed transfer function in s-domain. Draw the block diagram.
1-Select one of the DC motor type belonging to any company and specify the motor parameters...
1-Select one of the DC motor type belonging to any company and specify the motor parameters from its catalog/datasheet. 2-Calculate the maximum inertia value of the load to be driven according to the motor inertia specified from catalog, use given rule below to specify gear ratio plugged between load and DC motor If your student id is 12568013, then u=(1+2+5+6+8+0+1+3)/5 u = = 5.2 3-The speed measured from the rotor of an asynchronous motor with 12-pole, 80 Hz is K...
I have a question for the effect and difference on a DC motor for the speed(...
I have a question for the effect and difference on a DC motor for the speed( rad/s) in time (sec) if you apply: 1. Nothing (so no charge in the circuit only the mecanic charge of the generator) 2. A resistant charge (only the resistant is plug in with the generator) 3. Short circuit (No exterior electric charge but the terminals are bounds together so an excessive amount of current flow into the circuit) 4. Capacitive charge (only the capacitor...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT