CEB Press/Manufacturing Instructions/Controller Box/Arduino Control of CEB Prototype 2
- 1 System Requirements
- 2 Arduino
- 3 Design Rationale
- 4 Implementation procedure
- 5 Timing Adjustment Considerations
- 6 Hardware
- 7 Implementation and Discussion
- 8 Control Logic
- 9 Automation Testing Procedure
- 10 40 GPM Solenoid Valves
- 11 Discussion
Starting with the installation of Arduino on Mac OS X 10.3.9 - http://arduino.cc/en/Guide/MacOSX - we move on to examine system requirements:
- Computer and USB connection for programming
- Arduino for control
- 2 Solenoid Valves --relays to drive solenoid from arduino (12V 3.5A required?) Arduino max sink/source is 20mA.
- 1 limit switch
- Power supply to arduino
- Power supply to solenoid valves
We have Arduino Duemilanove:
- Power plug (after done with USB programming)
- 2 signal outputs to control solenoid valve power (via 5V_in power solenoid?)
- Analog input from limit switch (after open-loop configuration is tested)
- Analog input from CEB timing control - 5 channels
- Build CEB press
- Secure Arduino, limit switches, power and control cables, solenoid valves, power solenoids for solenoid valves
- Wire up hydraulics for quick attach
- For automatic control, start with limit switches. Design and program their logic. Source all the components and have them on hand.
Timing Adjustment Considerations
- Field-controllable adjustment of the CEB press timing should be feasible - to accommodate for different hydraulic power levels. For example, if the CEB is powered by MicroTrac, 10 GPM fluid flow is available, but with LifeTrac, it may be up to 29 GPM. This means different pressing rates in bricks pressed per minute.
- The above is too complex, so a simple solution is limit switches - with completely pre-programmed logic and states determined by tripping of limit switches. Therefore, there should be 3 limit switches for each cylinder. This should be visible from the pressing steps below.
The timing logic from CEB Pressing Steps is:
- Start with brick ejected, main cylinder in up position, and hopper at the left (see CEB Pressing Steps)
- Move main cylinder down to the bottom until for time=t_m1
...I quit here, because there is far too many adjustments to be made. Move right into position sensing, and do everything with closed loop logic.
- Arduino - 
- NOTE: a more recent set of solenoid valves are listed on the Bill of Materials page.
- Solenoid valve - 
- Double acting solenoid valve is needed - 
- Connectors for solenoid valve - 
- Limit switch - 
Implementation and Discussion
October 2, 2009
- Arduino connected to Mac OS X 10.3.9 computer via USB cable.
- Requires Java 1.5, Mac OSX 10.3.9 supports up to Java 1.4 only. Time to move on to Linux.
- Arduino Desktop Environment downloaded for Ubuntu 8.04 from Arduino site, by following the test installation for Ubuntu 6.06.
- Installation on Ubuntu 8.04 was troublefree using the above instructions. Here is our adaptation for Ubuntu 8.04:
- Run Synaptic Package Manager (in "System > Administration").
- In the Synaptic Package Manager, first find the 3 files, and then mark for installation: "sun-java5-jre", "gcc-avr", "avr-libc". (If these are not installed already)
- We installed the 3 packages, which were downloaded in about 15 minutes - as in the 6.06 instructions.
- Follow the rest of the instructions to configure the newly installed Java packages, using Terminal. Then download and run the Arduino environment:
- Installation on Ubuntu 8.04 was troublefree using the above instructions. Here is our adaptation for Ubuntu 8.04:
- Here is the sample light:
- After discussion with Lawrence, we decided to do automation without limit switches, due to the high precision (1/32 of an inch) required in a dirty environment. We decided to do preprogrammed timing, which can be adjusted in the field for brick thickness and engine power.
- Updated circuit based on feedback from Ralf
- Circuit suggestion from Ralf:
- Ben Gatti arrived, and we began by took IRFP260N power MOSFETs out of a broken inverter. We began the day with the idea of using IRF510A 16 amp power MOSFETS, which Ben got for $2 at Radio Shack:
50 amp IRFP260N ($2.75) simply because we had them available:
- Circuit being built by Ben:
- Circuit tested with a dummy load. Transsistors (MOSFETS) are driving the LED light:
- Circuit tested with a battery, like will be used with the CEB machine:
- Finally, the circuit was tested with a real load on one of the transistor channels, a 1 amp light:
- We wired up all of the 4 MOSFET channels, and added indicator lights to see the logic transitions. Ben programmed the Arduino for the correct CEB pressing sequence.
- Here is the final circuit, ready to be attached to solenoids:
- The rest of the MOSFETS were wired up
C1=Main Pressing Cylinder, C2=Secondary Hopper Cylinder
To run the CEB machine, one should turn on the hydraulic power source first. Then, the electronics should be turned on.
Electronics power-up includes:
- Powering up the Arduino controller
- Powering up the relays
- Need snubber diodes for back-EMF of solenoid coils
- Need 4 transistors or relays because each double-acting solenoid valve has 2 solenoic coils
- Need optoisolation for back-EMF
Refer to pressing diagram. Define the 'zero position' as the position where all soil or the brick is ejected from the machine. Start by zeroing all positions - ejecting any remaining brick or soil left in the pressing chamber. This action is done irrespective of cylinder positions, assuming they are in the farthest position off zero. This means 3 steps:
- Move C2 all the way to the right (allows ejection of brick via C1)
- Move C1 all the way to the top (brick ejection from compression chamber)
- Move C2 all the way to the left (brick ejection from the machine)
Control logic involves the zeroing action upon startup at all times. This is done at the beginning of brick pressing :
- Under normal conditions
- After any power outage to the controller
- After CEB machine runs out of gas
- Any other contingency
The zeroing action also fills the loading drawer with soil, assuming that the hopper is filled with soil.
To begin brick pressing, start at the zero position (C1 at top, C2 at left). Then:
- Move C1 down all the way (8 inches) - this loads the compression chamber with soil
- Move C2 7 inches to the right (half of its stroke) - this closes the compression chamber in preparation for pressing
- Move C1 up half way (4 inches) - this is the compression stroke
- Move C1 down 1/4 inch - this relieves pressure against the loading drawer
- Move C2 right all the way (7 inches) - this opens the compression chamber for block ejection
- Move C1 up all the way (4 inches) - this ejects the block from the compression chamber
- Move C2 all the way to the left (14 inches) - this ejects the block from the machine
This completes a pressing cycle, and returns the machine to zero position.
Control Logic Rationale
The basic control principle is that the valve-open time determines the length of cylinder travel. The longer the valve is open, the longer the cylinder travel. This is both for the forward and reverse motions. It is also assumed that fluid flow is constant - or that the Power Cube is at maximum throttle for the lengh of the pressing session.
It should be noted, however, that the rate of cylinder travel will be slightly different in the forward (extension) and reverse (contraction) direction - by design of hydraulic cylinders. This is because one side of the cylinder contains the cylinder rod, which takes up cylinder volume. From a practical perspective, the rod reduces the effective working diameter of the cylinder. For example, our 5" cylinder has a 2.5" rod, or 1/4 the volume of the cylinder. Thus, the cylinder contracts 1.3 times as fast as it extends.
C1 is a large-diameter (5 inch) hydraulic cylinder. C2 is a thin (1.5") cylinder, and therefore, it moves about 10 times faster than C1 for a given hydraulic fluid flow. Therefore, its speed must be limited with a needle valve. Otherwise, timing of this cylinder may produce non-replicable motion. Moreover, this cylinder cannot move so fast that it produces damaging stresses. The practical speed of C2 must be determined in field testing. The faster C2 moves, the more favorable this is for overall rate of brick pressing. Also, the faster C2 moves, the more difficult it is to make it stop at the same location for a given valve-open time.
To control the CEB machine, programmable timing is sufficient to control cylinder motion completely. However, field testing will determine practical limits. If C2 motion is slowed down excessively to allow for complete control, it may be necessary to use limit switches - which allow for replicable stopping position of the cylinder at any cylinder speed. This is not likely to be necessary for C1, but C2 may require a limit switch. For now, we will assume that no limit switches are required, which simplifies hardware requirements for the control scheme.
Under the assumption that the hydraulic circuit is incompressible, we may calculate the accuracy of cylinder motion based on the turn-on and turn-off time of the solenoids. We assume that the accuracy is deternmined by these times. Assuming 50 ms turn-on and turn-off time, we calculate the maximum inaccuracy as the length of travel that could occur during the 100 ms of total solenoid state transition time. We multiply cylinder speed by this transition time to determine the accuracy limit.
V (in/sec) = [Q (cu in/sec)]/[A (sq in)]
= 5.4 in/sec
V = cylinder speed Q = hydraulic flow rate = 10 gallons/min = 1/6 gallons/sec = 38.5 cu in/sec A = area of cylinder = pi * radius^2 = 7.1 sq in
Thus, accuracy = V * .1 sec = .54 in
This result indicates that timing could possibly work.
Given that the cylinder rod is 1" and the cylinder is 1.5" in diameter, the velocity of contraction is 1.8 times that of expansion. Thus, maximum inaccuracy of relevant contraction is about 1". This could be unacceptable, unless the timing is adjusted to accommodate transition time - in which case the limit of inaccuracy would be the variation of transition time. The variation of transition time should be a small fraction (10% or less). Therefore, control of cylinder contraction should be achievable down to 0.1", which is acceptable for good performance without using limit switches. Note that this is without using a needle valve - so using a needle valve to reduce the flow rate to, say, 5 gallons per minute - would double our accuracy.
The timing should be adjustable in the field. Timing adjustment should also be the means to brick thickness control. Timing steps should be as follows for 4" bricks:
- TC10=zeroing time for Cylinder 1= length of time expected for 8 inch extension of C1
- TC1d=time for C1 to contract 8 inches (d for downward) = TC10/1.3
- TC1c=time required for compression using C1 (c for compression) = TC10/2 + TC10*.05
- Second term accommodates for slowdown of cylinder upon reaching full brick compression, where 0.05 is an arbitrary fractional time increase
- TC1b=time for C1 to go from compression position back to relieve pressure against drawer (b for back) = TC10*.05
- TC1e=time for C1 to go from compression position to ejection of block from compression chamber (e for ejection) = TC10/2 + TC10*.05
- Second term accommodates for unusually thick bricks, under the condition of abnormally incompressible soil, where the travel to ejection is longer than 4 inches
- TC20=zeroing time for cylinder 2=length of time expected for 14 inch extension of C1 = TC10/11.1 (based on thicknesses of both cylinders, 5 and 1.5 inches)
- TC2p=time for C2 to close compression chamber by moving 7 inches to the right = TC20/3.6
- Note: this must be exact, and maximum acceptable error is 1/2" in either direction from exact 'closed compression chamber' position, because the 'closing lid' is 1" wider than the compression chamber.
- TC2o=time for c2 to open the compression chamber by moving 7 more inches to the right = TC20/3.6 + TC20*.05
- Second term accommodates for inaccuracies resulting from TC2p
- v1.01 - code by preprogramming motion times, not by scaling motion times by respective factors - see CEB Control Source Code v1.01
- v1.02 - same as above, but scaling from a base value of BaseTime; more annotations - CEB Control Source Code v1.02
- Testing of up-down and variation on main cylinder = testcodemainy v1.0
Pressing Test Code
- Testing of actual pressing (see video at http://blog.opensourceecology.org/?p=1259) = presstest v1.0
Automation Testing Procedure
The solenoids should be arriving 10.13.09.
Our experimental procedure will be:
1. Test solenoids working with the CEB machine. Use preprogrammed timing. Adjust the timing with the computer.
2. Determine if human-adjustment (no sensors) is capable of producing the 7 brick per minute theoretical efficiency of the machine - ie, that the machine stops in the correct cylinder positions. To do this, adjust the timing within the code based on one scalar, the hydraulic fluid flow rate - given that the cylinder speeds can all be calculated from this single scalar.
3. Then, adjust the flow on the small cylinder with a needle valve to get the correct position for pressing, which is the only critical adjustment that needs to be made. To be in the correct position, it has to stop within 1/2" accuracy of a certain point. Test whether this is achievable with preprogrammed control, based on the acceptable 50 ms response time of the hydraulic solenoids.
4. Perform all tests at full throttle, and determine replicability by pressing about 50 bricks. If performance is replicable, the test is complete. If replicability is not achieved, sensors should be added.
5. Acceptable performance is that consistent with theoretical predictions based on fluid flow - or 7 bricks/minute - minus .5 second time lost per brick because of lack of sensors. This translates to 1/2 brick lost per minute over optimal performance.
6. At this point, we may decide the acceptability of this for product release.
40 GPM Solenoid Valves
has a circuit (the voltage depends on the relay you use). You absolutely need the diode parallel to the relay. It will short-circuit the negative voltage when turning off the relais. A cheap 1N4148 will do ($0.02). Don't connect the relay directly to the arduino without a diode. If you intend to connect the relais directly make sure it doesn't draw more that 40mA.
I'd still use the L298N for driving the valves. You need only one for two valves and some external diodes. Be sure to use a heatsink. If you can't come up with the circuit I can help you.
As written earlier turning large current for an inductive load on and off very often (of a valve) will probably wear relais quite fast, so using a solid-state switch (L298N) ist better.
How much do the valves draw? You have 2?
> Q1. Power source for Arduino. Just use a 5V wall transformer?
You have the duemilanove, it takes 7-12V input, I'd recomment to stay below 10. DON'T go over 12, if you use a 12V transformer and produce DC from it, this will be about 14V !! See http://arduino.cc/en/Main/ArduinoBoardDuemilanove for the specs. You need stabilized DC. I've used a wall-plug switching power supply of 9V, similar to that one: http://shop.conrad.at/ce/de/product/510821/
You don't need so much power, so for the arduino only (I've used that to power the motor of my chicken door, too, see http://blog.runtux.com/2009/01/08/9/ (in german).
During development the arduino works well with power over the usb connector. So I'd recommend starting with the software (pointer below) while building the hw.
> Q2. If I want to go power a 120v air solenoid, how do I do it? Use a relay > with signal out of an arduino output, and I'm done? Can you draw a circuit > for this?
Note: Question applicable to water pump, not CEB controls. CEB solenoids are 12V
I'd use a solid-state relay with a Triac and an Opto-Triac with zero crossing. I'm using the MOC 3041 here with 240V mains -- you will want to use the MOC 3031 for US. See PDF Datasheet on that page: http://www.fairchildsemi.com/pf/MO/MOC3031-M.html The datasheet has a "Hot-Line Switching" circuit on P.6 in Fig. 12 which you can use unmodified. If you're not concerned about noise on the line (you don't have neighbors using your mains power :-), you can leave out the 39 Ohm and 0.01 µF (10 nF) parallel to the Triac.
For the Power Triac in that circuit I've used the BT139/800H, this can switch up to 16 A and won't be destroyed by high voltage due to inductive load. Datasheet: http://www.nxp.com/acrobat/datasheets/BT139_SERIES_4.pdf but you can use almost any Triac.
You connect an output-pin of the arduino to a 220 Ohm resistor in series with Pin 1 of the MOC3031. Pin 2 of the MOC3031 is Arduino ground. (the MOC3031 needs 15mA, the Diode needs 1.8 V, Arduino is 5V, so you need R = U / I = (5 - 1.8) / 0.015 = 213 Ohm).
Switching inductive load with a relay won't fit your lifetime-design goals as it will burn its contacts sooner or later. But a relay circuit
- is* a little easier:
arduino output pin -----+----+ +----- mains
| | | Relais ^ * | | |Relais switch | | | -+- -+- *----Valve --- mains-
you need a 5V Relais that can switch 115V mains which might be hard to get. Parallel to the relais you need a diode (e.g. 1N4148) that will short-circuit the relais when turned off (inductive load of relay will produce a negative voltage when turned of which could kill the arduino)
The relay shouldn't draw more than 40mA on the I/O pin of the Arduino. Otherwise you'll need a transistor circuit to drive the relay: 4k7 from arduino out to the basis of an NPN-Transistor (BC 237 or similar) Emitter to ground, Collector to Relay, Relay to +5 (or +9 depending on relay) Volts. Parallel to the Relay again the diode as in the circuit above or you'll kill the transistor.
> Q3. How do I program the code? I want 5 seconds on, and 30 seconds off on > the air solenoid. Can you write the code or help me write it? Thats simple and is covered by one of the early arduino examples:
I wouldn't connect the LED without a resistor in series as in the photo, though. But you're lucky, the arduino has a small yellow led on board connected to pin 13 (with resistor :-), as used in the example-code. The example code will blink the led one second on, one second off. The delay function call takes microseconds as parameter. So modifying that to 5 seconds on and 30 seconds off is left as an execercise to the reader.
Later you connect the power-switching circuit instead of the led -- I'd recommend to use a pin different from 13 (because 13 already has a led on board which will draw some power and you want the full 40mA on the pin if necessary). That can be modified with the assignment to ledPin before the setup function.
> It would be nice to get this so we can have water in winter if the > greenhouse storage freezes. We have a well, but no pump.
Let me know how things are going and if you have further questions.
> CEB: > > Q1. If I want to power a 12V hydraulic high pressure solenoid, using the > same strategy as above would work with minor corrections. Just need to > connect to 12v on the Power Cube. You need another power circuit than for mains current -- this is true for Relay-Circuit, too, the Relais for switching high current is different from a mains relay. How much current will the solenoid draw? There are ready-made H-Bridge circuits for switching low-voltage, e.g., the L293D for up to 1A, the L298N for 2A (two circuits in one which may be switched in parallel for up to 4A), english datasheet is attached to that page: http://shop.conrad.at/ce/de/product/156128/ (Conrad has very high price for this part, you can get ist for less than 3 Euro) these are usually used for driving a motor, because you can change the direction with two half-circuits. If you only need power/no power you can use one circuit for driving two valves.
For higher currents you can use a TLE 5206 (5A 40V), but there may be some with even higher current.
> Q2. I will have mechanical limit switches, 3 of them on the main cylinder, > and 3 on the hopper cylinder. Do I have any issues with doing that on > Arduino?
You can use digital inputs on the Arduino for reading the switches. Be sure to debounce the digital inputs in software (with high electro-mechanic interference you may get wrong readings from the switch). The arduino tutorial has code for that and I've written a library for it. Debounce time depends on your requirements how fast the switch should trigger an action.
> Q3. If you point me to some hints on Q3 on the water pump, I can figure out > the rest. There is a very good tutorial for learning the things you need to know with the arduino: http://arduino.cc/en/Tutorial/HomePage
But if you have any questions, don't hesitate to contact me.
> I've just never done this stuff before, so a basic tutorial would be > appreciated. This is good to document, and allow full controls at anyone's > fingertips, with Arduino as a good choice.
Yep, see above for getting up speed with the arduino. Incidentally the blinking led example is also the first in the tutorial. And you don't need much more for the pump above.
> I started documenting at > http://openfarmtech.org/index.php?title=Arduino_Control_of_CEB_Prototype_2 Reading that I guess for the 12V 3.5A valves you can use the L298N, you should use a heatsink and in addition you need four external fast diodes, e.g., SB 390 http://shop.conrad.at/ce/de/product/160221/ (datasheet in english available through that link) You can use *one* L298N for driving two valves and you need 4 diodes. Be sure to take a look into the data sheet of the L298N, mine has a motor control circuit in fig 6 p. 6/13 and a diagram how to parallel two half-circuits in fig 7 p. 7/13. You want to combine these. There are 4 circuits in the L298N, you parallel two each and use only the left half of Fig 6 (with two parallelled circuits) the right connector of the moter (the valve in our case) is connected to ground.
If you can't figure it out, I can draw a circuit.