CEB Press/Manufacturing Instructions/Controller Box/Arduino Control of CEB Prototype 2

From Open Source Ecology
Jump to: navigation, search

System Requirements

Starting with the installation of Arduino on Mac OS X 10.3.9 - - 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:


Design Rationale

  • 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

Implementation procedure

  1. Build CEB press
  2. Secure Arduino, limit switches, power and control cables, solenoid valves, power solenoids for solenoid valves
  3. Wire up hydraulics for quick attach
    1. One attachment via manual control from Power Cube valve
    2. Second attachment is a series connection from Power Cube valve to automatic solenoid control
  4. For automatic control, start with limit switches. Design and program their logic. Source all the components and have them on hand.

Timing Adjustment Considerations

  1. 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.
  2. 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:

Pressing steps.jpg

  1. Start with brick ejected, main cylinder in up position, and hopper at the left (see CEB Pressing Steps)
  2. 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.



  • Solenoid valve - [2]
CEB Solenoid 1.jpg

  • Double acting solenoid valve is needed - [3]
DA Solenoid.jpg

  • Connectors for solenoid valve - [4]

  • Limit switch - [5]

Implementation and Discussion

Development Log

October 2, 2009

  • Arduino connected to Mac OS X 10.3.9 computer via USB cable.

Turnkey Arduino Duemilanove from Marcin Jakubowski on Vimeo.

    • 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:


Arduino Says "Hello World" from Marcin Jakubowski on Vimeo.

        • Here is the sample light:

From LED to CEB from Marcin Jakubowski on Vimeo.

    • 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.

October 3

  • Updated circuit based on feedback from Ralf


October 4

  • 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:

Ben on CEB Control 1 from Marcin Jakubowski on Vimeo.

and moved on to the bigger (50 amp IRFP260N ($2.75) simply because we had them available:

Ben on CEB controls 2 from Marcin Jakubowski on Vimeo.

  • Circuit being built by Ben:

CEBCircuit3.jpg Only one solenoid section is shown. For 2 double-acting solenoids, this means 4 MOSFETs.

  • Circuit tested with a dummy load. Transsistors (MOSFETS) are driving the LED light:

CEB Control Part 3 from Marcin Jakubowski on Vimeo.

  • Circuit tested with a battery, like will be used with the CEB machine:

CEB Control Part 4 from Marcin Jakubowski on Vimeo.

  • Finally, the circuit was tested with a real load on one of the transistor channels, a 1 amp light:

CEB Control Part 5 from Marcin Jakubowski on Vimeo.

October 5

  • 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.

CEB Control Part 6 from Marcin Jakubowski on Vimeo.

  • Here is the final circuit, ready to be attached to solenoids:

CEB Machine Controller v1.0 from Marcin Jakubowski on Vimeo.

October 5

  • The rest of the MOSFETS were wired up

Control Logic

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:

  1. Powering up the Arduino controller
  2. Powering up the relays

Proposed Circuitry (see description of symbols used) drawn with Solve Elec free software:


Review Comments

  1. Need snubber diodes for back-EMF of solenoid coils
  2. Need 4 transistors or relays because each double-acting solenoid valve has 2 solenoic coils
  3. 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:

  1. Move C2 all the way to the right (allows ejection of brick via C1)
  2. Move C1 all the way to the top (brick ejection from compression chamber)
  3. 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 :

  1. Under normal conditions
  2. After any power outage to the controller
  3. After CEB machine runs out of gas
  4. Any other contingency

The zeroing action also fills the loading drawer with soil, assuming that the hopper is filled with soil.

Brick Pressing

To begin brick pressing, start at the zero position (C1 at top, C2 at left). Then:

  1. Move C1 down all the way (8 inches) - this loads the compression chamber with soil
  2. Move C2 7 inches to the right (half of its stroke) - this closes the compression chamber in preparation for pressing
  3. Move C1 up half way (4 inches) - this is the compression stroke
  4. Move C1 down 1/4 inch - this relieves pressure against the loading drawer
  5. Move C2 right all the way (7 inches) - this opens the compression chamber for block ejection
  6. Move C1 up all the way (4 inches) - this ejects the block from the compression chamber
  7. 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.

Timing Logic

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:

  1. TC10=zeroing time for Cylinder 1= length of time expected for 8 inch extension of C1
  2. TC1d=time for C1 to contract 8 inches (d for downward) = TC10/1.3
  3. TC1c=time required for compression using C1 (c for compression) = TC10/2 + TC10*.05
    1. Second term accommodates for slowdown of cylinder upon reaching full brick compression, where 0.05 is an arbitrary fractional time increase
  4. TC1b=time for C1 to go from compression position back to relieve pressure against drawer (b for back) = TC10*.05
  5. TC1e=time for C1 to go from compression position to ejection of block from compression chamber (e for ejection) = TC10/2 + TC10*.05
    1. Second term accommodates for unusually thick bricks, under the condition of abnormally incompressible soil, where the travel to ejection is longer than 4 inches
  6. 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)
  7. TC2p=time for C2 to close compression chamber by moving 7 inches to the right = TC20/3.6
    1. 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.
  8. TC2o=time for c2 to open the compression chamber by moving 7 more inches to the right = TC20/3.6 + TC20*.05
    1. Second term accommodates for inaccuracies resulting from TC2p

Source Code

Testing Code

Pressing Test Code

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


Ralf 1:

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?

Ralf 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 for the specs. You need stabilized DC. I've used a wall-plug switching power supply of 9V, similar to that one:

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 (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: 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: 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: (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:

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 > 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 (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.