Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer the questions on conclusio part. Please answer the questions on co

ID: 2991320 • Letter: P

Question

Please answer the questions on conclusio part.

Please answer the questions on conclusio part. 5.2 Running a DC Motor using analogWrite function with Arduino: In this step, we'll build a circuit that allows using our computers to run a DC motor and its speed according to value we entered to the software. For this purose, Ardunio's pin 9 will be used as output of DC motor's one input (and the other goes GND as expected). It is important to know that the value of analogWrite(pin, Value) goes from 0-255. 5.2.1 Procedure: 1. Write the code to do this process and 2. Connect Pin 9 to one leg of the DC motor, the other one to the GND. 3. Change the Voltage value in the code and upload it again. (Remember, the ) Arduino board supports up to 5V without using external power supply)

Explanation / Answer

const int switchPin = 2; // switch input
const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 9; // H-bridge enable pin

void setup() {
   // set the switch as an input:
   pinMode(switchPin, INPUT);

   // set all the other pins you're using as outputs:
   pinMode(motor1Pin, OUTPUT);
   pinMode(motor2Pin, OUTPUT);
   pinMode(enablePin, OUTPUT);
   pinMode(ledPin, OUTPUT);

   // set enablePin high so that motor can turn on:
   digitalWrite(enablePin, HIGH);
}

void loop() {
   // if the switch is high, motor will turn on one direction:
   if (digitalRead(switchPin) == HIGH) {
       digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
       digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
   }
   // if the switch is low, motor will turn in the other direction:
   else {
       digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
       digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
   }
}