Project dc motor + ir sensor

Hi everyone,

i have to make a project about a machine and i like to ask how do i give a command to the IR sensor that gives the DC motor with 12Voltage 100RPM to stop for a few seconds. Sinds the arduino can only have 5 voltage or more (not sure how much max is). I am using a buckconverter to set the 12volt for the DC motor and 5,2 volt for the rest of the electronics, including the arduino.

The only thing i already have tested with a simulator so far is how to get the DC motor spinning at the rate with the 12 voltage through the external powersupply. which is only a The only thing i need help with is how to set the IR sensor to a stop command (twice with 2 IR sensor) with a timer

so far the code (which i already write down as the DC motor spins)

void setup()
{
pinMode(13, OUTPUT);
}

void loop()
{
digitalWrite(13, HIGH);
delay(1000); // Wait for 1000 millisecond(s)
}

PS: i hope my drawing is understandable

You’re looking at it the wrong way round. You read from IR sensors and then you decide what to do and send commands to motors to start and stop them. You don’t send commands to IR sensors, they just provide information for you.

Steve

So i have to put if IR sensor goes from low to high the motor stops for 3000 milliseconds for example?

That sounds reasonable. Write some code to do that, try it and see what happens.

If you have problems post your code here and we'll help you to get it working.

Steve

Hi this is currently my code (underneath). i connected the arduino with a 1K ohm resistor + mosfet + diode + dc motor 12V (runs at 9V/5V, cant connect it to a buck converter sinds the program does not have one) and 1 IR sensor for now. There is hopefully no error as i tested it myself. and i probably need help as i want to make the DC motor stop at the point when the IR sensor get disrupted / crossed. also i need to put more codes as i need a second IR sensor aswell.

void setup() {

  pinMode(13, OUTPUT);
  pinMode(11, INPUT);
  Serial.begin(9600);
}

void loop() {

int detect = digitalRead(11);
  if(detect == LOW) {
    digitalWrite(13, HIGH);
  delay(1000); 
    Serial.println("Obstacle on the way");
  }else{
     digitalWrite(13, LOW);
    delay(1000);
    Serial.println("Obstacle arrived");
  }
    delay(5000);
  }