How can I control each piston of a pile of 8 pistons?

Assuming the pistons are pointed to the right, do the following (note, I am using four pistons, however, you can repeat this as many times as desired):

For horizontal:

Place blocks and redstone like this: step 1

Then, cover the redstone on the ground so it doesn't touch the elevated redstone like so: step 2

Now you can test this by placing blocks above the ends of the elevated redstone and placing levers on them (note that you can also place blocks behind the ends and place levers on those blocks). For the redstone on the ground, place the levers directly next to the ends like this: step 3

In the following picture, the levers with bricks behind them are on. Notice that the corresponding pistons are extended: testing

For vertical (Note, as of now, as gnovice explained (thank you), it is impossible if you want to retract the bottom first):

Like in the horizontal method, start by placing blocks and redstone like so: vertical step 1

Then place blocks in the following locations: vertical step 2

To test this, place blocks and levers in the following locations: vertical step 3

As before, levers with brick behind them are on: vertical testing

Please note: as stated before and explained by gnovice, currently pistons can't retract until the piston above it has retracted (please upvote his answer for that). So as long as they retract top down, you'll be good to go.

That's all there is to it. Now you can add as many pistons as you want repeating steps 1 and 2. Hope this helped. Happy red-stoning :D

PS: Pistons have had updates so this may not work in older versions such as 1.7


I don't believe this is currently possible with respect to controlling each piston in a completely independent manner from all the other pistons. It is possible to isolate the inputs to each piston such that they can be independently extended, but the problem arises when you want to independently retract them. Here is the key point from the "Bugs" section of the Minecraft Wiki for Pistons:

If two extended pistons are one above the other, the lower one cannot retract until the upper one retracts (video explanation). If the top one will start extending while bottom one is still retracting, the last will start extending as well.

The only possible solution I can think of would be to retract all higher pistons whenever a given piston needs to retract, then return them to their previous state (if they were extended) after a brief delay. This is the only way to ensure that a given piston can retract, but would require more complicated redstone circuitry. It would also mean that the pistons aren't acting in a completely independent fashion, since changes to lower pistons would transiently affect the states of higher pistons.

To illustrate proof of concept for this solution (transiently resetting all higher pistons to their retracted state) I built a simple 2-piston stack:

enter image description here

The lever on the left controls the lower piston, and the lever on the right controls the upper piston. Here's a view from the top showing how it's all wired up in back:

enter image description here

The left lever drives the lower piston directly, but the right lever drives another piston that opens and closes a circuit delivering power to the upper piston (basically, an AND gate). The "power" in this case comes from two OR-ed signals: one is the left lever signal passed through a repeater with a 1-tick delay (coming from the left in the image) and the other is the left lever signal inverted then passed through a repeater with a 2-tick delay (coming from the top in the image).

This design creates a scenario whereby power is continuously supplied for use by the upper piston if the lever for the lower piston is in the on state, off state, or transitioning from off to on. However, when transitioning from on to off, the power to the upper piston will be temporarily disconnected. If in the extended state, the upper piston will momentarily retract long enough for the lower piston to retract before returning to the extended state.

Extending this solution to a larger stack of pistons is an exercise I will gladly leave to the reader. I for one am hoping they will simply correct the bug.;)