pulseIn doesn't work

Hello,

I try to check a relais. The relais is open for 5-10 minutes, then closed for until 15 minutes and so on.

I would like to start reading sensors as soon as the relais closes, in order to control the status of the sensors immediatly after closing of the relais.
After that should the program wait for the next closing.

I did write

if (pulseIn(relaispin, LOW) { ......

but it doesn't work. The sensor was readed the whole time while the relais was closed.

Is pulseIn not suitable for that purpose?

If not, what instead of that?

Thank in advance

mgbd

That line is missing a parenthesis and would obviously throw an error. How about you post the real code. All of it.

The Reference page for pulseIn() states that it is only good for up to 3 minutes so your 5, 10 and 15 minute timing may be the cause of your issue (assuming your parentheses error is a simple typo).

With such long timing, couldn't you simply poll the relay? Is it important to know exactly how long it was open/closed for? Your description make it seem like you just want the relay to act as an activation signal to start the sensors reading?

I can't say, how long the relay is open or closed. There is a permanent fluctuating.

May be can I use pulseIn to start one measuring run and then by using delay()'s or asking the relay status fiddle away the time until relay-changing?

If not possible have I to restart the arduino at every relay changing for one measuring circle. Not elegant but the last back door.

VG

Why are you so set on using pulseIn()? It really doesn't seem like that function is appropriate for your application.

Poll the relay or use interrupts if it is that time critical. There's certainly no need to reset the entire Arduino.

Poll the relay or use interrupts if it is that time critical. There's certainly no need to reset >the entire Arduino.

ok, I wil do so.

But I've still a question to pulseIn().
If I start the program sequence by using

if (pulseIn(relaispin, LOW)) {......

and the relay is already low, then starts the sequence - altough there is no low-pulse.
It runs until the relay is changing (tested for 1 minute)

Is that really right?

pulseIn is for getting the length of time that a pin was in a particular state. It doesn't make any sense in an if statement where it isn't compared to some number. Do you think digitalRead would be better? If you want to react to the relay closing then I think it would.

pulseIn is for getting the length of time that a pin was in a particular state

ok, that was a missunderstanding about the function of pulseIn. I see that is necessary to use something other instructions for my problem.

I think to use digitalRead to start the sensor sequence once and after that wait until the relay is changed and it’s time for a new digitalRead and a new sensor-reading.