Motor voltage reduces with if condition

Hi, I'm just getting started with arduino. I've managed to get a DC motor running using a motor shield. Now, I want to use a IR sensor as input. So, I simply made one pin input and enclosed the motor code inside that. ie.

int m1= 2;
int m2=7;
int input=10;

void setup()
{
  pinMode(m1,OUTPUT);
  pinMode(m2,OUTPUT);
  pinMode(input,INPUT);

}

void loop()
{   int state = digitalRead(input);
   if( state==HIGH )   
    {
    digitalWrite(m1, HIGH);
  digitalWrite(m1, LOW);
     
    }
}

However, now , when the sensor LED glows(indicating 1), I can only hear a small buzzing sound from the motor and no movement. A quick check with the multimeter returns a voltage of 0.5 V across its terminals, which are around 2.5 V when perfectly running.

(I've checked the pin connections of the sensor a number of times, so I guess my pin number isn't wrong) What am I doing wrong?

Thanks

What you wrote was:

  if( state==HIGH )   
    {
    digitalWrite(m1, HIGH);  // Turn the motor on
    digitalWrite(m1, LOW);   // Turn the motor off again immediately
    }

What you wanted was:

  if( state==HIGH )   
    {
    digitalWrite(m1, HIGH);  // Turn the motor on
    }
  else
    {
    digitalWrite(m1, LOW);   // Turn the motor off
    }

Which is the same as saying:

    digitalWrite(m1, state);  // Turn the motor on or off to match input