Features at a glance
Having your own egg laying chickens in times of food scandals like the latest dioxin scandal is a fine thing. Although these chickens from my little cousin on the pictures here are not some fancy bred "hybrid chicken", they lay almost one egg a day during summer and live a happy life. They have a large area to peck and paw and sleep inside a beautiful coop.
However, keeping chickens has one major drawback: You have to get up with them in the early morning and open the door at the coop. Everyday. Including Sundays and holidays. It can be quite tedious sometimes. That's why my litte cousin asked me to construct an automated door for his chicken coop that opens at the break of dawn and closes at dusk.
The actuator raising and lowering the door is a strong gear motor from a wiper. I bought it at a local scrap merchant for 10 euros. The motor includes a worm drive so it holds its position when powered off.
Two switches in a parallel arrangement recognize when the door is open or closed. Because of the parallel arrangement, the microcontroller can only recognize that the door has reached an end position but not which one. However, this saves me one input/output on the microcontroller.
The sensor for the brightness is a photoconductive cell.
The whole system gets its power from a 12 V / 7 Ah accu. It can be charged by a small 2.1 W solar panel.
All circuitry is assembled on a circuit board. There, all devices run together to be powered and controlled. Later there's a separate chapter with information about what the circuit board does exactly.
The "brain" in the system is a MSP430 microcontroller from TI which runs on the popular LaunchPad development board. It can be programmed in C to handle and process all inputs and outputs of the system. There's also a push button on the LaunchPad that can be used to program new brightness thresholds. It is directly connected to the circuit board.
Altogether there are 4 inputs and 4 outputs to deal with.
The inputs are:
and the outputs:
The motor driver is a so called H-bridge. I use the BTS7741G driver from infineon, as it can handle up to 10 A (the wiper motor consumes up to 3.5 A nominal current depending on the direction).
The combinations are:
However, because of my thick cables the current exceeds 10 A during start-up of the motor. I had to put a 1 Ohm resistor in series with the motor. This is a quick and easy way to reduce the current flow. A more elegant solution would be a motor start-up with a PWM.
The charging relais is a bistable. That means it holds its position even when powered off. This way, all the power from the solar panel goes into the accu and no power is wasted on the relais. However, a bistable relais has two coils to control and therefore i need two pins from the microcontroller as outputs.
You can see the whole setup here:
In the following picture you can see the schematics of the circuit board. On top there's a pin header to connect the board with the MSP430 LaunchPad. Since there's already a push button connected to the pin 1.3 of the LaunchPad, pin 4 of the pin header is left unconnected.
C2, C5 - 10 µF
C3, C4 - 100 nF
R1 - 22 kOhm
R2, R3, R4 - 4.7 kOhm
R5, R6 - 1 kOhm
OPH1 - VT93N1, 24 kOhm
S1, S2 - Cherry D44Y snap switches
Q1, Q2, Q3, Q4 - BSS138 N-channel MOSFET
K1 - bistable relais NAIS DE2a-L2-5V
D1, D2 - 1N4148 diodes
furthermore a 3 V and a 5 V voltage regulator (LM2936) as well as a BTS7741G motor driver.
All parts could be replaced by similar components. Tolerances of the resistors and capacitors are not an issue.
A description of the circuitry
For an explanation of the circuit board, I use simplified schematics without the connector for the MSP430 and the BTS7741G. I hope it gets a bit more clear by this.
1. Accu and voltage divider
To charge the accu with the solar panel, I use a bistable relais with two coils. The two diodes in the picture are so called free-wheeling diodes. Depending on which coil from the electromagnet is switched on by the MOSFETs Q3 and Q4, the switch K1 connects the solar panel with the accu or not. As the relais is bistable, the relais holds its position even after the electromagnet is cut off.
To measure the voltage of the accu, the two resistors R1 and R2 divide the voltage in such a way, that the microcontroller can deal with it. The voltage between both resistors and the negative terminal of the accu is equal to (R2/(R1+R2))*V_bat. This is supposed to be less than 3 V even if the battery is fully charged. An analog-digital-converter (ADC) from the MSP430 reads this value.
2. Voltage regulator, 3 V
To power the MSP430, I use a 3 V voltage regulator. On the input pin, there are the 12 V from the accu. On the output pin are just 3 V. The capacitors act as buffers, whereas C1 is chosen pretty big as it also has to buffer the battery power when the motor is running. After all, accus don't like it when suddenly a large current drains.
3. Voltage divider with photoconductive cell
This voltage divider is used to measure the brightness. The Voltage between the connectors of R3 is proportional to the resistance of the brighntess sensor and is measured . Another AD-converter reads this value.
4. Door switches
The switches are directly installed at the door, whereas the capacitor and the resistor are on the circuit board. They help to debounce the switches.
5. Voltage regulator, 5 V
As some parts of my circuitry require 5 V instead of 3 V, I need a further voltage regulator that provides these 5 V. It's similar to the one before.
6. MOSFETs to control the motor driver
I found out that the H-bridge of the BTS7741G motor driver works better when I run the gates with 5 V instead of 3 V. These two MOSFETs Q1 and Q2 act like switches and convert the 3 V output signal of the microcontroller to a 5 V signal for the motor driver. Be aware that this also inverts the signal!
7. Bistable relais
Since the BTS7741G motor driver is a SMD part (SSOP-28) I had to etch a small breakout board. You can see the layout below. The wiper motor consumes around 3.3 A when running, so the wires must be wide enough. But since the motor is only running for a short time, the layout is sufficient.
Find the latest version at the bottom of this page!
My source code is based on the low-power tutorial from TI's "getting started with the MSP430 LaunchPad" . Since it was the first time for me to program the MSP430, it took me a while to figure out how all this works. All those clocks, timers and register bitfields are much more complicated to handle compared to the programming of my arduino. But when you use the tutorial source codes as a starting point for new programs, most work is reduced to some adjustments of the interrupt routines. As I commented most lines of my source code, I don't want to go into much detail. I just want to summarize the main functionality with some bullet points.
I wrote the program in Linux, so it can be compiled with the MSPGCC suite. For further information on programming the MSP430 with Linux, I recommend the article  on hackaday.com. However, to compile the program with TI's Code Composer Studio, there are just a few simple changes necessary. It's all described in the source code.
The door-opener worked quite well when some days ago all of a sudden the 1-Ohm-resistor burned through and also the motor driver broke. I don't know why this happened, but I guess that there was an unintended change of state from "open" to "closed" due to some insufficient debounce of the switches at the door. Then, when the door was already up, the controller gave the fatal command to open the door again. Of course, this was not possible but the motor gave its very best - and overloaded the 1-Ohm resistor as well as the motor driver. Now to me, this explanation still leaves some questions open, i. e. why didn't the driver shutdown and prevent its destruction and why did the microcontroller change its state, as the switches were debounced by the RC-circuit?
Well, I fixed the board and in order to prevent such failures in the future, I changed some parts of the software. In version 1.1, the state "open"/"closed" can only change, when the motor is running. But as soon as it's changed, the motor is set to halt. Furthermore, the motor is only allowed to run for 20 seconds. If a door switch is not pressed in the meantime, the motor stops and the programm calls an error-function, blinking slowly the green LED (which is attached to the charging relais).
The Launchpad is a cheap but versatile development board for the MSP430 microcontroller from Texas Instruments.
Getting started with the MSP430 LaunchPad - Tutorial from TI
chrisatronics by Christian Wolpert is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.