I will present through this blog how to create a henhouse door that opens automatically depending on the sun. In the project I’m going to treat, the door will open in the morning at 9 am and close depending on the sun. You will be able to adapt this project according to your needs. The purely electronic part will be treated in this article.
Background
I own 12 chickens and my father intends to put a rooster. The door is used to prevent him from singing and bringing up the whole neighborhood at 6 am. So I offered to manufacture all the control part for his engine.
Equipment required for engine control
– A nano Arduino
– A card for welding
– An L298
– Two terminal blocks
– A small solar panel
-An old 12 V recovery engine
Introduction
I decided after various tests to use the nano Arduino to manage the sun, sending commands to the engine.
What is the nano, Arduino?
The Arduino Nano is a free printed circuit board including a Microcontroller. The Microcontroller is the little black chip with lots of legs. It’s a bit like the brain of an electronic object, a miniaturized version of a circuit with lots of components. It is also on this component that the program is stored.
Technical specifications
Microcontroller | Atmel ATmega328 |
Operating voltage (logic level) | 5V |
Supply voltage (recommended) | 7-12V |
Supply voltage (maximum) | 6-20 V |
Digital I / O | 14 (of which six can provide a PWM output, denoted by a white line) |
Analog I / O | 8 |
Current available by I / O pin | 40mA |
Flash memory | 32 KB (including 2KB used by the bootloader) |
SRAM | 2 KB |
EEPROM | 1 KB |
Clock speed | 16 MHz |
Dimensions | 44mm x 18mm |
It’s all well and good, but what does it do?
In truth, many things. Analog I / O can retrieve information and send information. Digital I / O allows them to send a 0 or 5V output. The PWM makes it possible to vary for example the speed of a motor but also the intensity of a lamp. TX / RX pins (transmit/receive) allows dialogue with other components, eg, radio frequency module.
Setting up the Arduino-nano
For the control of the light, we must recover the information of the solar panel thus use of the analog I / O. I chose to use the pins D2 and D3 (personal choice).
Engine control
To control a motor with an amperage greater than 1A it becomes a little more complicated … (You can find the indication of amperage on the transformer of your motor. Be careful because a high amperage is dangerous!)
We can not control the engine going directly through the nano-Arduino. Why?
- Because the current is so low that your engine will not even turn.
- When the motor finishes running when it is no longer powered, it generates a current. This current arrives on your Arduino and can, according to the intensity to grill it. Great!
So we will use an intermediate component called the “H bridge.” I will not go into details, but this component can run a motor in both directions without the risk of grilling all your components.
So we connect this small component on the digital I / O pins and also on the 5V Arduino because it must be powered to operate.
Here is my little card that I created for this component. But I will replace it with an L298 for more power.
For ease and power, use the L298D. The card does not become necessary anymore.
Programming your nano-Arduino
Install on your Arduino IDE pc downloadable here
Configuration:
- Open it, go to Tools-> Boards and select Arduino nano / ATmega 328
- Go to Tools-> serial ports to select the port.
Your Arduino is ready to be programmed!
Copy and paste the following code:
const int potar = 0;
int D2 = 2;
int D3 = 3;
security boolean = 0; // Reset the security value
// variable to store the value read after conversion
int valueLue;
// convert this value to a
float voltage voltage;
void setup ()
{
// we just start the
Serial serial link . begin (9600);
pinMode (D2, OUTPUT );
pinMode (D3, OUTPUT );
// At each reset, the program starts again and runs the motor in the up direction (opening at 8 o'clock)
digitalWrite (D2, HIGH );
digitalWrite (D3, LOW );
delay (3000); // wait for 3 seconds
// Stop
digitalWrite (D2, LOW );
digitalWrite (D3, LOW );
delay(3000); // wait for 3 seconds
}
void loop ()
{
valueLue = analogRead ( potar );
// convert the voltage read at the output of the potentiometer to the binary number
// translate the raw value into voltage (cross product)
voltage = value Read * 5.0 / 1023;
// the value read on the
Serial serial link is displayed . print ( "valueLue =" );
Serial . println (readValue);
// we display the calculated
Serial voltage . print ( "Tension =" );
Serial . print (voltage, 2);
Serial . println ( "V" );
// we skip a line between two
Serial displays . println ();
// wait half a second so that the display is not too fast
if (voltage <0.48 && security == 0) // Detection of the night and the door is open
{
security = 1; // security indicating that the door is closed
//
DigitalWrite closure (D2, LOW );
digitalWrite (D3, HIGH );
delay (4000); // wait for a second
// DigitalWrite
stop (D2, LOW );
digitalWrite (D3, LOW );
delay (1000);
}
delay (500);
}
Adapt this code according to your needs. When you click on the small magnifying glass at the top right, you can see the values read on your solar panel.
That’s it your motor drive is over!
Be careful, here I did not use opening contact or closing. I strongly advise you to use it. At a few cents a unit, why deprive yourself? We connect them to the Arduino.
When activated, the door has reached the stop and the power to the motor is turned off. It’s much cleaner and generates fewer problems.
Leave a Reply