Newbie First Sketch. How difficult.

Hey everybody. My day job is a sys admin, primarily writing Powershell scripts. I could write what I want in Powershell in an hour, but I know almost nothing about arduino and haven’t had time to dig into it yet. How difficult will it be to write the following sketch. It’s to control a chicken coop, which I know has been done, but not with lighting, which is important for egg production.

Hardware:

Adafruit DS3231 Precision RTC
AC light dimmer. Forward phase.
Aurduino uno
Pololu 5v 1a regulator
2 Chanel relay module
12v linear actuator
12v PSU

At sunrise the the linear actuator is provided power to retract for 3 minutes

1 hour after sunrise, the lights are turned on to 100% brightness. Lights will remain 100% brightness for 12.5 hours and gradually dim to off over a 1 hour period.

At sunset the linear actuator is provided power to extend to 3 minutes.

In theory, it is not a difficult intermediate level project. In practice, most chicken coop sketches end up as a train wreck. Your best bet is to construct and program a mock-up. That will give you a headstart and an opportunity to make mistakes without committing money to equipment and time to methods that won't work out in the long run.

I already bought the equipment, just havnt had a chance to do anything with it. My coop door is wired with the linear actuator and a toggle switch for now. I have 12v and 120v power for other reasons. I just need the 2 functions. Opening and closing the door automatically, providing providing lighting that doesn't plunge the birds into darkness without warning, and doesn't wake them up before sunrise.

Do most sketches end up as a train wreck because people don't know how to program, or for other reasons?

tsperry88:
Do most sketches end up as a train wreck because people don't know how to program, or for other reasons?

Reasons do vary, but most often it is because people charge ahead and build a 9,000 line program without researching anything about how to code, or how to build and test all the individual functions separately. It "works fine" up to line 8,999, then one line breaks the whole thing because it's held together like a pile of Jenga blocks, and nobody can read it to debug it (including the programmer) because it's a jungle of bad style.

The forum has a search function where you can search for each component in your project and find many years of discussion on them. Does your linear actuator have an internal pot to indicate its position? Get each individual component working then work on combining the parts.

Look thru this thread.

Start with a schematic.

Modify the schematic and sketch as needed.

https://forum.arduino.cc/index.php?topic=674906.45

Final sketch for this thread.

https://forum.arduino.cc/index.php?action=dlattach;topic=674906.0;attach=356421

Adafruit DS3231 Precision RTC
AC light dimmer. Forward phase.
Aurduino uno
Pololu 5v 1a regulator
2 Chanel relay module
12v linear actuator
12v PSU

At sunrise the the linear actuator is provided power to retract for 3 minutes

PS with RGB leds you can control color as well as brightness, start and end days with shades of red. Birds can see UVA so maybe a UVA led here and there will give the girls a more daytime looking coop.
1 hour after sunrise, the lights are turned on to 100% brightness. Lights will remain 100% brightness for 12.5 hours and gradually dim to off over a 1 hour period.

At sunset the linear actuator is provided power to extend to 3 minutes.

I would go with led lighting and likely a different door scheme but you got parts already.
Most coop inventors put an external light sensor in somewhere.

Read this thread in this forum to pick up how to write OS-free task oriented code on Arduino.
Demonstration code for several things at the same time

From there your RTC code, coop door and lights tasks can run independently of each other and share/flag others through variables. You roll your own system a piece at a time, as long as they're non-blocking they should be able to run together.

The Arduino setup and loop functions fit the non-blocking do-something-else-come-back-later approach to a task waiting for something while not holding the rest up too. You just gotta pick up or make up techniques to be quick about it.

Start by writing a series of short programs to learn how to control each of your pieces of equipment one at a time. Don't try to build the integrated program until you can get all the parts to work separately.

If you get stuck it will be much easier to get help with a short single-purpose program.

When writing the individual programs keep in mind that you will want to integrate them in future so make sure that, for example, you don't try to use the same I/O pin to control a door and control a light.

...R

zoomkat:
The forum has a search function where you can search for each component in your project and find many years of discussion on them. Does your linear actuator have an internal pot to indicate its position? Get each individual component working then work on combining the parts.

It just has end travel limit switches. Closing the relay for 3 minutes is double the time it takes to traverse.

Thanks everybody. I'll dig into into once I have time away from outdoor projects. Or find somebody to write it for me:)

tsperry88:
Or find somebody to write it for me:)

If you want to do that then ask in the Gigs and Collaborations section of the Forum and be prepared to pay.

...R

If you're an experienced powershell user, you already know how to code, test and debug. Doing that in a new language and environment will be many times easier than the situation a novice finds themselves in.

With a time and delay based program, the first rule you want recognise is that unless you understand how it works, the delay() function is better left out of your software.
(Read: ‘blocking code’ is not helpful)

"It just has end travel limit switches. Closing the relay for 3 minutes is double the time it takes to traverse."

If it takes 1.5 min to open/close the door, then it probably won't trap/crush a chicken.

zoomkat:
"It just has end travel limit switches. Closing the relay for 3 minutes is double the time it takes to traverse."

If it takes 1.5 min to open/close the door, then it probably won't trap/crush a chicken.

It's the slowest I could find without going huge. I also made the pop door ledge uncormfortable to perch on.

You could sense an object in the door opening using IR leds and sensors and possibly capacitance sensing getting that a critter is close to the door which has more than one use.