Suggest please " How to write code for Detecting Stopped shaft of a DC Motor?"

/* //test program for detecting stopped DC Motor shaft\

  • A 120 RPM 6V DC Motor (dcm) is connected to pin 8 via Power Mosfet,
  • a Cog wheel(toothed gear) is fixed on DC Motor shaft infront of that a Proximity sensor
  • which gives output(Connected to pin A1) HIGH & LOW continously when shaft is Rotationg and in case of Shaft
  • stopped rotating it gives single long output either HIGH or LOW . so what I am expecting is
  • if Output status either HIGH or LOW remains for More then 250 milli seconds then break; the
  • DC Motor driving function for(;:wink:
    */
    int dcm=8;
    void setup()
    {Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
    pinMode(dcm,OUTPUT);
    }//END OF SETUP

void loop()
{
for(;:wink: // DC Motor driving function
{
digitalWrite(dcm,HIGH);
if(digitalRead(A1)==HIGH||LOW>millis(250))
{
break;
}
}
digitalWrite(dcm,LOW); // OFF DC Motor

}

    if(digitalRead(A1)==HIGH||LOW>millis(250))

The millis() function does not take any arguments. Even if it did, I can not see that relationship between what it returns and LOW. So I can not see that the comparison makes any sense as the OR part of a compound statement.

If you're going to want to read A1 as a digital input, it would be a good idea to make it a digital input.

And code tags. We love code tags

If you're going to want to read A1 as a digital input, it would be a good idea to make it a digital input.

That's the default, isn't it?

And code tags. We love code tags

Yes, we do.

thank you all for Quick reply.

Is there any solution in proper code writing to above task of detecting stopped shaft ?

sorry what is "And code tags. We love code tags" ? I am new to Arduino.

If you read the "How To Use This Forum" thread before you posted you would know what code tags are.

Reading the instructions or documentation first is what separates good programmers from poor ones. From the look of what you've written, this is a skill you should polish up on.

Delta_G:
If you read the "How To Use This Forum" thread before you posted you would know what code tags are.

Reading the instructions or documentation first is what separates good programmers from poor ones. From the look of what you've written, this is a skill you should polish up on.

ohh this is QUATE !!!!!!!!!!

RAHUL_AREKAR:
ohh this is QUATE !!!!!!!!!!

Quite possibly (or equally possibly not)
What exactly is a "QUATE" ?

PLEASE IGNORE THAT,

AND LET’S TALK ON TOPIC

OK, but please stop SHOUTING

RAHUL_AREKAR:

  • which gives output(Connected to pin A1) HIGH & LOW continously when shaft is Rotationg and in case of Shaft

I suspect you need to save the value of millis() (or maybe micros() ) each time a pulse is detected. Then you can check the time between pulses to detect whether the motor has stopped… Something like

if (newPulseMillis - previousPulseMillis > interval) {
   // motor seems to have stopped
}

What is the normal interval between pulses when the motor is working properly?

And when posting code please use the code button </>so your code looks like thisand is easy to copy to a text editor See How to use the Forum

…R

What is the normal interval between pulses when the motor is working properly?

...R
[/quote]

It is only 10 milliseconds.

So, if you see 20ms or more, can you assume it's stopped?

-jim lee

I am not good even at Basic level of coding, I am just putting my points / task ,

and I am hoping for correct coding or even suggestion of complete Hardware (motor, sensor) or code change.

I am not good even at Basic level of coding

You are not yet at the point where you should be writing code. You have not even defined the requirements.

You know that RPM means so many pulses per minute, right? So, 0 pulses in one minute means 0 RPM. Counting pulses in one minute is not hard.

The other way to determine RPM is to record when each pulse happens. When the second one happens, the interval between the first and the second defines the amount that the shaft rotated, so you can compute the RPM, assuming that the speed is relatively constant.

To show 0, you need to determine that some period of time has passed with no input. If the pulses are 10 milliseconds apart at some speed, you can determine how far apart they are at 1 RPM. When the time between now and the last pulse exceeds that time, you can safely assume that the shaft has stopped.

So, 10 milliseconds is not a useful answer to the time between pulses. 10 milliseconds at xxxx RPM is (where you supply a value for xxxx).

What interval do you want to use to decide that the shaft has stopped? Where are you recording when a pulse happens?

let me clear myself again considering your above Basic points, & I may take a day as I am New.

thanks a lot.

I WILL LOOK AT TASK AGAIN. THANK'S A LOT

Please make sure you turn the caps lock key off.
The shouting is getting tedious.

RAHUL_AREKAR:
It is only 10 milliseconds.

Then I think it would be best to use an interrupt to detect the pulses and record the value of micros() at every pulse.

Read about attachInterrupt() in the reference section.

...R

Robin, attach attachInterrupt()? You're hittin' warp speed and he's not sure about the direction to sit on a horse.

-jim lee