I only need the Arduino program code Do not copy or link to

I only need the Arduino program code.

Do not copy or link to \"Anonymous answered this - 361 answers\" (The sensors output pin goes to HIGH...\". We don\'t know what that code is for. Drunk texting, perhaps.

Design a circuit and Arduino program that accomplishes the following:

An IR distance sensor will detect the presence (through waving of a hand)

A H-Bridge circuit with 9V battery power will control the direction of the DC motor as described in Chapter 4 (pp. 70-79) of your textbook.

When a hand is waved over the IR sensor, the motor moves in one direction (simulating opening a door). There is a 2 second pause, and then the motor moves in the opposite direction (simulating closing the door).

The motor stops until another hand is waved over the IR sensor again.

Solution

// Connected iRSensor to digital pin 6
int iRsensor = 6;
//
int switchPin = 2;
int motor1Pin = 3;
int motor2Pin = 4;
int enablePin = 9;

void setup() {
   //Set iRSensor input as INPUT
   pinMode(iRsensor,INPUT);

   //Set motor pins.
   pinMode(motor1Pin,OUTPUT);
   pinMode(motor2Pin,OUTPUT);
   pinMode(enablePin,OUTPUT);
   digitalWrite(enablePin, HIGH);//StartTheMotor

}

void loop() {
   int readSensor = digitalRead(iRsensor);

   if( readSensor == HIGH){
       do{
           digitalWrite(enablePin, HIGH);
           //Move in one direction
           digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
           digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
           delay(2000);           //Give 2 sec delay
           //Move in another direction
           digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
           digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
           digitalWrite(enablePin, LOW); //off the motor.
       }while( readSensor == HIGH);
      
   }
}

I only need the Arduino program code. Do not copy or link to \

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site