Actuator automation based on timer from sunrise.

I want to catch the relative time of daylight. Then based on the number of times I choose per day, I want to extend and then retract an actuator. I have some experience in programming C++, and understand libraries, but I have little experience with this kind of hardware. I will except any help with the hardware, but I think I can figure that out with tutorials. The programming with this hardware is where I am confused.

I intend you use an arduino (version unsure) and relays to open and close the actuator. I want to use a light sensor to recognize a certain level of light to determine the day has begun. It is not important that I know the time of day.

I could use help on both hardware and programming.

Here is an example of what I would like to happen,
variable A = 4
If Light then begin timer
If timer > (some set time, let's say 4 hours) and A >0 then run the actuator out, wait (seconds), then run actuator in.
A = A - 1

When A = 0 and/or No light then restart process the next day.

Could I initiate a loop when the light is detected, delay (4 hours) at the beginning of the loop, run the actuators, A = A - 1, close the loop when A = 0? Then nothing happens until the next time the sensor detects light?

Knowing some C++ is good. Actually old fashioned C is quite usable.

There are books for Arduino beginners that tell the basics, both about hardware and software. Have You got any of that?

What's Your experience regarding hardware, electronics, used around microcontrollers? It is not "plug and play".

That is my problem, I don't have any experience in this category. I am a fabricator with a computer science degree. I never used the degree, because of the kind of work I chose. I don't have a lot of time due to the variety of other things I am doing. I am trying to fabricate something here, but need to be pointed in the right direction. I think the general idea I propose at the end of my comment should work, if it will work in this environment. I can figure out the inputs and outputs and how to connect a dual relay to the actuators. However, can I run the loop for 10-12 hours using the delay function at the beginning of the loop

This is why I need some Project Guidance. :confused:

Okey. I don’t see any code in Your posting. (My bad day? Too late?)
Delay is not very precise. It’s obtained from a simple oscillator, not any precision chrystal oscillator.
I suggest a real time clock module in order to handle time frames like that.

If you don't need a lot of accuracy/precision [u]delay()[/u] or a [u]millis()[/u] timer should work fine. They aren't good for time-of-day because they drift farther-and-farther off every day. The Arduino uses a ceramic resonator which isn't as accurate as a crystal, and not nearly as accurate as the crystals used in watches (or real-time clock modules).

But that's not a big problem if you're starting over every day at sunrise. Both of those use milliseconds with type unsigned long, so 4 hours or a day isn't a problem. And, you could improve the accuracy by calibrating/compensating in your software if you find it's running a little fast or slow.

delay() pauses execution so your program can't respond to a button push or read the light level or anything during the delay time. For that reason delay() is often avoided, or used "carefully" or only for short delays, etc. From what you've told us it's OK if execution stops. Otherwise, you can make a millis() timer. millis() rolls-over after something like 45 days (I don't remember exactly) so you'd have to handle that. And, you can't reset millis() without a processor hardware reset so you do have to handle the rollover (if you're going to run it that long).

Take a look at the [u]Blink Example[/u] and the [u]Blink Without Delay Example[/u].

On the hardware side, look for an LDR (light dependent resistor) example. That's probably the easiest way to detect light and you can experimentally calibrate your own analog threshold.

The Arduino can't put-out enough current to directly power a relay coil but you can buy "relay boards" with a driver circuit built-in. Or, there are solid state relays that can be directly driven from the Arduino. But solid state relays are a little trickier because AC & DC solid state relays are not interchangeable and sometimes AC solid state relays actually have a minimum turn-on voltage.

Dvddoug- thank you. Very helpful. I don’t care if the Time is ten min off. What matters is the number of times it’s actuated and that it is during the day. I need this as simple as possible, because it will be outside and out of reach for up to 14 days.

You don't really say what you are trying to do, or about the order of accuracy. Is it the level of light that you want? Or is that it should be daylight? These things vary according to the weather and or the time of year. Either way, you may be better off with an RTC, which is weatherproof and dirtproof. It may only be needed to tell you that a new day has started, and Arduino is quite capable of telling you when the sun rises and sets for any day.

If you want someone to write code for you, post on the Gigs and Collaborations forum section. You may be asked to pay for the help.

A simple light sensor is a Light Dependent Resistor (LDR), sometimes called a photocell to CdS (Cadmium Sulfide) cell. You pit it against a fixed resistor, one trying to pull an analog input pin down to Ground and the other trying to pull the pin up to +5V. You can then use ‘analogRead(pin)’ to get a number from 0 to 1023 that changes with light level. Use a simple program to see how the value changes with light level and decide what threshold you want to call ‘day’.

void setup()
{
  Serial.begin(115200);
  while (!Serial && millis() < 5000) {}
}


void loop()
{
  // Show the light level on Tools->Serial Monitor or Tools->Serial Plotter
  Serial.println(analogRead(A0));
  delay(5000); // wait five seconds
}

The amount of light in winter and summer is different. A car passing by and shining its lights on the LDR should not turn it on. Therefor you need some kind of filter or algorithm in software.

For many years it is my dream project to have a clock running that counts the hours and synchronizes with a LDR. The time should not be influenced by light from a lamp (when it is only turned on a short time). It should count every hour without skipping an hour, so it is possible to do something at a certain hour. I would like it to be in sync after a day or three. It should not use a lot of ram.
When the curve of the average light intensity is known, then also the sunrise and sunset can be dermined.

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