/* //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(;
*/
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(; // DC Motor driving function
{
digitalWrite(dcm,HIGH);
if(digitalRead(A1)==HIGH||LOW>millis(250))
{
break;
}
}
digitalWrite(dcm,LOW); // OFF DC Motor
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 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.
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
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?