Middle son has to do a school project (an EPQ" they call it). Having lost our last chicken to Mr. Fox, he wants to make a light-activated chicken coop door opener. The door works like a sash window, and the idea is to have a light sensor that opens it when it's daylight and closes it when it's night.
There's a geared DC motor with a pulley on it at the top. It winds a piece of string up or down, depending on the direction in which the motor is running. There's a microswitch top and bottom, so that the Ardunio knows whether the door is up or down. The only other complication, is a solenoid latch that works like a house door. When the chicken house door is on the way down, there is a hasp on the bottom of it. The solenoid latch has a bevelled edge, and is spring-loaded, so when closing the door, the striker just pushes it out of the way. Before opening the door, therefore, a 12V pulse has to be applied to the latch for a second or so, to pull the striker back.
Essentially, (in words, at least!) the program is supposed to work like this:
Check light level.
If light level > 400, go to "opening door" subroutine. If light level < 300, go to "door closing" subroutine.
Door opening subroutine:
apply power to solenoid latch,
run motor forwards for 1 second,
remove power from solenoid latch,
run motor forwards until top limit switch closes.
Door closing subroutine:
run motor backwards until bottom limit switch closes.
Somehow, it's not working though. It doesn't stop the motor when the top limit switch is reached. It's a software problem, I think. (I've put a meter on the switches and they do open and close correctly). I'd be grateful for any thoughts anyone might have. I can help him with the mechanical bits, but I'm hopelessly out of my depth with the programming!
Is there anyone on here who might be wise in the ways of the Arduino, and could maybe cast an eye over the program if I post it up on here, please?
There's a geared DC motor with a pulley on it at the top. It winds a piece of string up or down, depending on the direction in which the motor is running. There's a microswitch top and bottom, so that the Ardunio knows whether the door is up or down. The only other complication, is a solenoid latch that works like a house door. When the chicken house door is on the way down, there is a hasp on the bottom of it. The solenoid latch has a bevelled edge, and is spring-loaded, so when closing the door, the striker just pushes it out of the way. Before opening the door, therefore, a 12V pulse has to be applied to the latch for a second or so, to pull the striker back.
Essentially, (in words, at least!) the program is supposed to work like this:
Check light level.
If light level > 400, go to "opening door" subroutine. If light level < 300, go to "door closing" subroutine.
Door opening subroutine:
apply power to solenoid latch,
run motor forwards for 1 second,
remove power from solenoid latch,
run motor forwards until top limit switch closes.
Door closing subroutine:
run motor backwards until bottom limit switch closes.
Somehow, it's not working though. It doesn't stop the motor when the top limit switch is reached. It's a software problem, I think. (I've put a meter on the switches and they do open and close correctly). I'd be grateful for any thoughts anyone might have. I can help him with the mechanical bits, but I'm hopelessly out of my depth with the programming!
Is there anyone on here who might be wise in the ways of the Arduino, and could maybe cast an eye over the program if I post it up on here, please?