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.
Program in Bash: Write a program using bash script that can read a file from the...
Program in Bash: Write a program using bash script that can read a file from the same directory, sort the nonrepeating integers from 0-9 from smallest to largest, and output the results on the same line. Do not use the sort function.
Using the Python program: a/ Write a program that adds all numbers from 1 to 100...
Using the Python program: a/ Write a program that adds all numbers from 1 to 100 to a list (in order). Then remove the multiples of 3 from the list. Print the remaining values. b/ Write a program that initializes a list with ten random integers from 1 to 100. Then remove the multiples of 3 and 5 from the list. Print the remaining values. Please show your work and explain. Thanks
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT