Measuring Total Time Above A Voltage


embayweather

Recommended Posts

I am using a Labjack U3 to run a weather station, connected to professional level instruments. I need to be able to measure sunshine hours, and this occurs when a voltage output from the sensor is greater than 2.5 Volts. When there is no or low sunshine amounts the voltage level is 0 volts. What is the best expression to use to total time above a certain voltage, clearly for the total reading each day. At the end of the day I would manually reset along with the other instruments .

Thank you for your advice.

Best wishes

Mike

Link to comment
Share on other sites

Create a Test Channel with Timing 0, call it "totalSunshine". In your input channel's event (I'll say its called "sunshine") put script like this:


if (sunshine[0] > 2.5)
totalSunshine.addValue(insertTime(totalSunshine[0] + (sunshine.time[0] - sunshine.time[1]), systime(), 0))
else

totalSunshine.addValue(insertTime(totalSunshine[0] , systime(), 0))
endif


[/CODE]

The else part is optional. It will simply ensure your totalSunshine channel has the same number of points as your sunshine channel. Note that you'll have to initialize / reset totalSunshine to 0 somewhere by doing:

totalSunshine.addValue(0)

The code simply adds the difference in time between two consecutive sunshine readings when the latest reading is > 2.5. The insertTime() function ensures the new data point has the current time and not the time of the last reading.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.