Time constrained signal sensing

Hey experts,
I want to write a code in which the arduino senses the number of times a high or low signal is received within a time specified time constraint.....example: 3 times high in a span of ten seconds glow led or 6 times low in a span of 10 seconds printxxx....

Please help!

What code have you tired? Post that here. Then tell us how its behavior differs from your expectations.

You mention an LED. Have you followed any of the LED tutorials to light an LED? If not, this is the place to start.

You mention printing output. I assume you mean printing to the serial monitor. Have you done that?

You mention reading a signal. Do you have something that is sending a signal? If so, can you read that signal on the arduino?

After you tackle these things, getting the logic to do what you describe will be easy.

Sir Im using a Long range Infrared (obstacle) Sensor E18-DYNK series!

So according to my understanding and practice whenever the input signal switches from low to high means an obstacle is detected! Which can be also confirmed by the the red led at the rear of the sensor!

I have interfaced an LCD with the arduino and will be printing into it!

I want to write a code in which,

if the Input signal from the sensor is HIGH continuously (uninterruptedly) for more than 4 seconds, then the arduino should print 'System Error' into the LCD and power on a Servo.

Also if the input signal from the sensor is LOW continuously (uninterruptedly) for more than 4seconds, even then the arduino should print 'System Error' into the LCD and power on a Servo.

Please Help me!

Thanks in advance!

akhilzorba:
I want to write a code in which,
...

We want you to write a code too. So have a try to write something then post it here and we'll help you to get it working. What we won't do is just write it for you.

Steve

I could not write it constraining time…becz i dont know how it is done…
instead i have tried using guides and i could be able to write an rpm counter code…
But that unnecessarily makes the code complex…

Here it is…

#include <LiquidCrystal.h>

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

const int dataIN = 6; //IR sensor INPUT

unsigned long prevmillis; // To store time
unsigned long duration; // To store time difference
unsigned long lcdrefresh; // To store time for lcd to refresh

int rpm; // RPM value

boolean currentstate; // Current state of IR input scan
boolean prevstate; // State of IR sensor in previous scan

void setup()
{
pinMode(dataIN,INPUT);
lcd.begin(16,2);
prevmillis = 0;
prevstate = LOW;
Serial.begin(9600);
}

void loop()
{
// RPM Measurement
currentstate = digitalRead(dataIN); // Read IR sensor state
if( prevstate != currentstate) // If there is change in input
{
if( currentstate == HIGH ) // If input only changes from LOW to HIGH
{
duration = ( micros() - prevmillis ); // Time difference between revolution in microsecond
rpm = (60000000/duration); // rpm = (1/ time millis)10001000*60;
prevmillis = micros(); // store time for nect revolution calculation
}
}
prevstate = currentstate; // store this scan (prev scan) data for next scan

// LCD Display
if( ( millis()-lcdrefresh ) >= 100 )
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Speed of Motor”);
lcd.setCursor(0,1);
lcd.print("RPM = ");
lcd.print(rpm);
lcdrefresh = millis();
}
if (rpm< 20)
{
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“System Failure”);
delay(500);
}
else{}
}

Even I am not looking for ready made code that will finish my projects easily!! :slight_smile:

I want to learn it!

If you could teach me which function and how to use it!

Iam so confused with the millis() function and delay()…

lot of complexities arise …i need help!

So where is the

akhilzorba:
I want to write a code in which the arduino senses the number of times a high or low signal is received within a time specified time constraint.....example: 3 times high in a span of ten seconds glow led or 6 times low in a span of 10 seconds printxxx....

I'm sorry but that code doesn't seem to have anything to do with what you say you are trying to do.

From your code, what exactly are the "high or low signals" that you are trying to count? Where is the LED that you want to "glow" and what is it that you want to print? When?

Steve

         duration = ( micros() - prevmillis ); // Time difference between revolution in microsecond
         rpm = (60000000/duration); // rpm = (1/ time millis)*1000*1000*60;
         prevmillis = micros(); // store time for nect revolution calculation

The WTF light exploded.

prevmillis is a stupid name when the value it stores comes from millis(). It is completely idiotic when the value comes from micros().

The WTF light exploded.

prevmillis is a stupid name when the value it stores comes from millis(). It is completely idiotic when the value comes from micros().

Sir I am a mechanical engineer, who has just stepped into the world of coding! So, Please pardon my stupidity and the idiocy also! Any help in making me understand the concept would be appreciated!

Regards

Aum