Disable Digital output with time delay

Hi

My logic is simple when digital input is Low Digital output should be enabled HIGH just for 5 Milliseconds and then Digital output should go LOW irrespective of Digital input status.

In next round when again Sensor sense it should repeat. Speed 2500 RPM.

Trying to Make a Stroboscope with a Speed sensor.

Your post is as simple as your logic. :slight_smile:

Do you have any questions?

Please have a look at the forum guidelines and provide information that will be needed to answer your questions. e.g. what Arduino you are using, schematic and links to datasheets of non-Arduino components. Post your code and tell us what does not work as you expect it.

What have you tried so far ?

First tried with 2 Pots. One for defining ON time another one for OFF time. Its working good.
The application i develop is for variable in speed. fixed speed strobe will not help.
So decided to go for IR sensor and match the strobe speed with IR sensor speed. Its not successfull. Its giving blurr image. To get the clear image LED ON time should be very less like 1 or 2 milli seconds.

So looking for a code which will turn ON led for just 2 milli second once got signal from Sensor.

Below is the code which works with 2 Potentiometer.

//

int strobe=13;

void setup()
{
pinMode(strobe, OUTPUT);
Serial.begin(9600);

}
void loop()
{

int don = map (analogRead (A0), 0, 1023, 0, 2); // Reads Potentiometer and maps it to an integer between 0 to 2)

int dof = map (analogRead (A1), 0, 1023, 15, 25); // Reads Potentiometer and maps it to an integer between 15 to 25)

digitalWrite(strobe, HIGH); // turn the strobes on (HIGH is the voltage level)
delay(don); // wait for however long sets by the potentiometer
digitalWrite(strobe, LOW); // turn the strobes off by making the voltage LOW
delay(dof); // wait for however long sets by the potentiometer

Serial.println( "ON" );
Serial.println(don);
Serial.println( "OFF" );
Serial.println(dof);

}

Oh Sorry..! :grimacing:

I use Arduino UNO. and IR Speed sensor.
I try to make a strobe, Its speed should automatically match with Object speed.

RPM measuring code and Strobe code which available online working independently.
my application demand to club the both, here I struggle.

When combining sketches most new users struggle with the delay() function. It is good for simple examples but bad for more complex sketches because it stops other parts of your sketch from working. You need to avoid it at all cost.

Have a look at the following example

File -> Examples -> 02.Digital -> BlinkWithoutDelay

This will teach you how to time parts of your code without stopping everything else. Change your current sketch using this concept. Your loop should run as often as possible and your strobe should work just like they do now but without delay(). Move the strobe code into its own function.

When this works you can start moving more code into your sketch. Because loop() can now run freely this should be a lot easier. Let us know when you get stuck. Post your new code.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.