Specifying state of digital pin, but state fluctuates
hello,
i'm marine biologist, not programmer, thought had code pretty figured out until now. project, trying control both heater , valve. @ particular time of day (low tide) want valve open (letting water out) , heater come on.
the issue arose morning, hadn't been issue before, has controlling valve (seemingly easiest part of project)
some background on code:
currently, enter low tide start time in 2 parts such (lowtidestarttimehr = 10, lowtidestarttimemin = 30) low tide starting @ 10:30. same end of low tide. convert these 2 times minutes (lowtidestarttime = lowtidestarttimehr * 60 + lowtidestarttimemin) using current time (from rtc) , series of "if else" statements determine if low tide. section of code shown below. there's added complication there 2 low tides each day there both "lowtidestarttime_1" , "lowtidestarttime_2", specified in same manner , "if else" statements, if bit long, not complicated.
the issue have run "lowtiderelay" pin doesn't seem stay high or low during high or low tide periods, switches "randomly".
i used serial port see what's going on , posted small section of below. printed additional output variables explore if fluctuation associated other change in system.
the variables have in output posted below are: "datetime", "measured temp", "set temp", "valvestate, equals relay pin", "current time", "lowtidestart", "lowtideend".
the primary column of interest valve state. when "time" between "lowtidestart" , "lowtideend", state should high (1). is. have attached file followed same timeline longer (and across switch low tide high tide) , can see state fluctuates , forth 0 1. seems have pattern, , gets random. when time greater lowtideend (its no longer low tide , state should low (0)), valve more 1, still fluctuates , forth (see attached file).
i'm not sure what's going on here, need valve/relay/pin maintain 1 state during "low tides" (valve open) , opposite state during "high tides" (valve closed) , right doesn't seem doing this.
additionally, i'm not happy way timing of tides set because it restricts timing of low tides cannot extend 1 day next (over midnight). so, open thoughts on how avoid whole mess, rewrite code, , specify timing of tides in different manner may not result in behavior seeing now.
i have attached full code, longer serial output, possible see valve state switches.
maybe simple mistake of not specifying initial state , appreciate feedback well.
thank you,
nate
i'm marine biologist, not programmer, thought had code pretty figured out until now. project, trying control both heater , valve. @ particular time of day (low tide) want valve open (letting water out) , heater come on.
the issue arose morning, hadn't been issue before, has controlling valve (seemingly easiest part of project)
some background on code:
currently, enter low tide start time in 2 parts such (lowtidestarttimehr = 10, lowtidestarttimemin = 30) low tide starting @ 10:30. same end of low tide. convert these 2 times minutes (lowtidestarttime = lowtidestarttimehr * 60 + lowtidestarttimemin) using current time (from rtc) , series of "if else" statements determine if low tide. section of code shown below. there's added complication there 2 low tides each day there both "lowtidestarttime_1" , "lowtidestarttime_2", specified in same manner , "if else" statements, if bit long, not complicated.
code: [select]
void tidevalve()
{
// current time, store in object 'now'
datetime = rtc.now();
if(now.hour()*60+now.minute() >= lowtidestarttime_1 && now.hour()*60+now.minute() < lowtideendtime_1 || now.hour()*60+now.minute() >= lowtidestarttime_2 && now.hour()*60+now.minute() < lowtideendtime_2 ) //if low tide
{
digitalwrite(lowtiderelay, high); //turn on relay1 power (open) valve
digitalwrite(lowtide_led, high); // turn on indicator led
}
else if(now.hour()*60+now.minute() < lowtidestarttime_1 || now.hour()*60+now.minute() >= lowtideendtime_1 || now.hour()*60+now.minute() < lowtidestarttime_2 || now.hour()*60+now.minute() >= lowtideendtime_2) //if high tide
{
digitalwrite(lowtiderelay, low); //switch relay1 (close valve)
digitalwrite(lowtide_led, low); //turn off indicator led
}
}
the issue have run "lowtiderelay" pin doesn't seem stay high or low during high or low tide periods, switches "randomly".
i used serial port see what's going on , posted small section of below. printed additional output variables explore if fluctuation associated other change in system.
the variables have in output posted below are: "datetime", "measured temp", "set temp", "valvestate, equals relay pin", "current time", "lowtidestart", "lowtideend".
the primary column of interest valve state. when "time" between "lowtidestart" , "lowtideend", state should high (1). is. have attached file followed same timeline longer (and across switch low tide high tide) , can see state fluctuates , forth 0 1. seems have pattern, , gets random. when time greater lowtideend (its no longer low tide , state should low (0)), valve more 1, still fluctuates , forth (see attached file).
i'm not sure what's going on here, need valve/relay/pin maintain 1 state during "low tides" (valve open) , opposite state during "high tides" (valve closed) , right doesn't seem doing this.
additionally, i'm not happy way timing of tides set because it restricts timing of low tides cannot extend 1 day next (over midnight). so, open thoughts on how avoid whole mess, rewrite code, , specify timing of tides in different manner may not result in behavior seeing now.
i have attached full code, longer serial output, possible see valve state switches.
maybe simple mistake of not specifying initial state , appreciate feedback well.
thank you,
nate
code: [select]
2014/3/18 12:11:51, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 731 lowtidestart: 360 lowtideend; 735
2014/3/18 12:11:54, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 731 lowtidestart: 360 lowtideend; 735
2014/3/18 12:11:58, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 731 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:01, 21.31 deg.c, set temp: 13.10 valvestate: 1 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:04, 21.31 deg.c, set temp: 13.10 valvestate: 1 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:08, 21.31 deg.c, set temp: 13.10 valvestate: 1 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:11, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:14, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:18, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:21, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:24, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:28, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:31, 21.31 deg.c, set temp: 13.10 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:34, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:38, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:41, 21.31 deg.c, set temp: 13.15 valvestate: 1 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:44, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:48, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:51, 21.31 deg.c, set temp: 13.15 valvestate: 1 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:54, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:12:58, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 732 lowtidestart: 360 lowtideend; 735
2014/3/18 12:13:01, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 733 lowtidestart: 360 lowtideend; 735
2014/3/18 12:13:04, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 733 lowtidestart: 360 lowtideend; 735
2014/3/18 12:13:08, 21.37 deg.c, set temp: 13.15 valvestate: 1 time: 733 lowtidestart: 360 lowtideend; 735
2014/3/18 12:13:11, 21.37 deg.c, set temp: 13.15 valvestate: 0 time: 733 lowtidestart: 360 lowtideend; 735
ugghh...
played around bit more , problem solved! of course. valve relay on pin 1, tx pin. every time data printed lcd switching state of pin! using different pin , resolved. feeling rather stupid.
thanks,
nate
Arduino Forum > Using Arduino > Programming Questions > Specifying state of digital pin, but state fluctuates
arduino
Comments
Post a Comment