Show Posts
Pages: [1] 2
1  Using Arduino / Project Guidance / Arduino controlled camera? on: January 31, 2013, 05:02:10 pm
I am attempting to build a camera.  The camera will be mounted on the rail of a handgun immediately in front of the trigger guard, with the intent of providing evidence of whether or not a shooting was justified.  The subject of firearms is controversial in some places, but I ask that you are as respectful of my rights as I am of yours, and that we keep this thread on the topic of electronics except where more information might be needed to better judge the requirements of the electronics (although I will be more than happy to civilly discuss, or respond to polite criticism of, firearms via PMs; provided that it doesn't violate any laws on your end).

What I want the camera to do:

1) Record monaural audio and black&white video (although color would be preferred) of at least 640x480 for a minimum of one hour.  10 frames per second should be sufficient.

2) Ideally, it would be resistant to physical shock so that anything after the first shot is recorded.  Video being blurred or scrambled with each shot is anticipated and acceptable, but I do want it to keep recording between and after shots if there are multiple attackers.

3) Fit in a space measuring a maximum of 1.1" wide, 1.5" high and 2.5" long.

Is this possible using one of the microcontrollers that come on Arduino boards?  I feel very comfortable with the programming of these controllers, and I'd rather not learn (or adapt to) another programming language right now if I don't need to.  Obviously, due to the space constraints, I will be designing all the circuitry and and the housing myself, which I have some experience with and feel comfortable at least trying.  Contrary to what the size requirements are, I would prefer to use a microcontroller with through-hole mounting, but I can learn to solder SMDs if needed.

If this is not possible using Arduino hardware, could someone point me in the right direction?  And if you have suggestions for individual components that would be best for this, I would appreciate that input as well.

Thanks,
Jason
2  Using Arduino / Project Guidance / Re: Arduino as an engine control module? on: February 08, 2012, 02:48:02 am
I know what you're saying and I know that the steam (or anything else) does not create energy.  The heat used to make the steam is mostly heat that would normally be lost into the radiator.  By having a water control valve instead of a traditional thermostat, I can keep that heat in the engine and use it to make the steam.  There is a great deal of heat dissipated by the radiator, and using that energy to push the piston down is better than losing it in the radiator.  Even if there is less force acting on the piston than a regular power stroke.  I would also modify the exhaust manifold to heat the water to a bit above boiling (it will be pressurized) before injecting it into the cylinder, saving some of the heat that is lost into the exhaust as well.  The steam could not possibly condense back into water; the water will be injected already above it's atmospheric boiling point, and be inside a cast iron cylinder which would be no less than 250ºF with aluminum on both ends of the cylinder at a similar temperature.  If I find that the engine does cool down using an every-other power stroke using steam, I can just increase the number of regular power strokes to keep the engine in the ideal range.  I could even redo the cooling system to heat the engine using heat from the exhaust if the temperature drops below 250ºF.

I know this will be a complicated system, but taking heat that normally disappears into thin air and using it to push the pistons down just a little bit is better than letting it go without using it at all.  It may not be as good as a power stroke from gasoline/petrol, but some force from energy that is otherwise lost is force that's not really directly from fossil-fuels.  It is, but it isn't. 

Good to know MegaSquirt is open source.


I appreciate all the comments from everyone.  I just wanted to know if the Arduino would be capable of controlling this system, whether it works or not.  I have some time to spend at an auto repair shop I'm starting, and until we get going, I'm often there with nothing to do for a few hours at a time.  I've got all the parts but the injectors, I may as well try to use them for something.  I'd rather do this than nothing, and hey, I get to play with electronics and engines at the same time smiley
3  Using Arduino / Project Guidance / Re: Arduino as an engine control module? on: February 07, 2012, 02:41:31 am
It takes heat to turn water into steam.    If you inject cold water at the top of a compression stroke, some may turn into steam, but the process of turning cold water into steam absorbs the heat from the compressed air, and the pressure will DROP, not rise.  It will consume mechanical power to do this.   As the piston starts down, the cooled air cools even more as the pressure drops, which can cause water to condense, further reducing the pressure against the piston going down.   It will take far more power to push the piston up, inject the water, than will be recovered on the way down.   

There is nothing to gain here.  NOTHING.   It will consume water, fuel, and time, and you'll have a severe loss in fuel economy.  You could, in theory, inject superheated water under high pressure, but that consumes large amoutns of fuel to heat the water and keep it compressed (not flash to steam).   There is no efficiency to be gained here.  None. 
 

How does the pressure drop as water expands into steam?  I agree that the pressure will decrease as the piston travels down, but it does with burning fuel as well.  The water would not condense, as the piston and cylinder walls will still be hot.  Water expanding into steam can create extremely high pressure.  Are you telling me that steam engines don't work?  The only difference here is that I will be using the heat from the previous combustion to make the steam.
4  Using Arduino / Project Guidance / Re: Arduino as an engine control module? on: February 07, 2012, 02:33:04 am


#4, unless this engine is very old and worn, everything you do ( and I mean everything) will not improve and may worsen your losses.  There are very few lubricants that can beat oil.  You can use a synthetic oil, look for independent tests to see which ones actually make an improvement by reducing friction losses in a real motor. 

#3, the injectors fire while the air is moving through the port, and it doesn't get on the manifold wall to any signficant degree.   The reduction in efficiency... Or perhaps more appropriately, the increase in consumption between a cold cylinder and a hot one varies signficantly, but generally we're talking losses of anywhere from 10 to 40%.   Google for "cold engine vs hot engine fuel consumption" or something like that, to find information on it.  Injecting water before the compression stroke means that you will have to use fuel to heat the water, push the piston up against TDC and then it loses energy again as the piston drops and the water may or may recondense, but the heat is lost to the cylinder walls and combustion chamber, piston, etc. 

As to the idea of an 8 stroke motor... the friction and pumping losses for the 'non power' extra revolutions could not possibly be made up by anything you do.  Pumping losses - that is the effort required to pull a vacuum on the closed throttle plate and to try to shove the exhaust or air out the exhaust system are the single largest factor in poor fuel economy at cruise.  When you close the throttle, the amount of fuel consumed per horsepower absolutely skyrockets.  Look up BSFC for throttled engines, and note how efficiency is improved when you open the throttle and produce more power.   

This is why tall gears at cruise work so well, because you have to open the throttle a lot, reducing pumping losses by reducing intake vacuum (raising manifold absolute pressure) while moving the car at highway speeds.     

As for engine controllers, look at MegaSquirt, which is a wholly programmable generic engine controller.   I believe it may be open source, too, not sure.   It's not cheap, but it's also not expensive. 

This engine has 196,000 miles on it, but is in pretty good shape.  The compression is toward the low end of "good".  I'm just seeing if I can gain anything.

The fuel injectors in this engine are actually pointed at the opposite side of the runner at a fairly square angle.  I had this engine, and hundreds or thousands of the same design, half way apart to replace the lower intake manifold gasket.  The lower intake runners and the head are always clean on the bottom from the fuel spraying/dripping on it, no matter how chunky the deposits are on the top and sides.  I know some of the fuel is caught in the moving air, but it looks like a lot hits the metal.

The reduction in fuel efficiency in a cold engine is mostly due to the engine running rich until it is up to temperature.  Vehicles with automatic transmissions will also raise the shift points and disable the torque converter clutch until the desired temperature is reached.

In the 6 stroke engines, the steam stroke produces nearly the same power as the regular power stroke, and the same displacement 6 stroke engine is 30%(? from memory) more powerful than the same size 4 stroke.  It's just recovering the heat that would otherwise be lost into the cooling system.

From what I have read, the water injected into the cylinder should produce pressure slightly less than burning fuel does.  A reduction in power on that stroke would require the throttle to be opened further for the overall power to remain the same.  This would raise the MAP, and may have an affect I didn't think about.

I won't be needing a different ECU, the stock PCM will allow me to do what I need to do.  The MegaSquirt is not open source, I had looked at that as a possibility for another vehicle at one time, had it been open source, I may have used it.
5  Using Arduino / Project Guidance / Re: Arduino as an engine control module? on: February 07, 2012, 01:56:39 am
You'll find out one way or the other soon enough, but dropping a cylinder is very obvious on mine. Having a 50% misfire I think would be quite unpleasant. But once you have your system working, it's entirely under your control whether you run the 'steam cycle' every other cycle or every third cycle or whatever.

Since you're injection into the chamber at TDC you'll have a lot of pressure working against you. Have you worked out how you're generate enough water pressure

It sounds as if you have got the petrol injection cut-off sorted out but I'm still not clear how you're going to time the water injection. I get that you can trigger it from the spark, but you need to know which of the pair of cylinders is in the compression stroke. I suppose you could monitor one of the fuel injection pulses and work the engine phase out from that, if you know where the fuel injection pulse occurs in the engine cycle.

I assume you would enable this whole water injection system when the load and revs corresponded to cruise conditions and leave the engine to run normally the rest of the time.

Do you have any sort of cat system or EGO feedback system on this car? One thing EGO sensors don't like is having fluid dumped on them, and the missed firing cycle would throw any EGO sensing out of wack. Suppressing the fault codes is one thing, but if your ECU relies on an accurate EGO signal then it won't be happy.

Given your experience working on engines, I'm sure you must be tempted to try the full 6-stroke conversion. smiley

I mean a miss on one cylinder with little load is not noticeable, this is a fairly large engine for the size of the car.

I was thinking about the possibility of using a pressure washer pump, adapted to run off the serpentine belt.  Injectors designed for direct injection are all that I think would work for the heat and temperature.  A corrosion inhibitor/lubricant combined with periodic removal and cleaning with something such as CLR (calcium, lime, rust) might be sufficient.  I would also have a filter to remove some of the contaminants from the water.

Whichever cylinder's fuel injector fires is on the intake stroke, so that cylinder will be the recipient of the next useful part of the spark.

It's very likely that this will be used only at cruise, but I'll have to see what power it has, it's likely it would work at idle, and even possible under light acceleration.

It does use O2 sensors, one pre-cat and one post-cat.  The affect on this engine's performance due to faulty O2 sensor readings is minimal.  If it's a problem, I can build a second controller that feeds a good signal into the PCM when this system is active.

I'm somewhat tempted to do a full 6 stroke conversion, but since they run rough until they are hot enough for a steam cycle, it's not that practical for a vehicle IMO.
6  Using Arduino / Project Guidance / Re: Arduino as an engine control module? on: February 06, 2012, 03:10:21 am
Hi, Have you seen this stuff:

http://ecomodder.com/wiki/index.php/MPGuino
http://www.waterduino.com/

Some of the MPGDuino guys are involved with an Open Source ECU project...


I had seen the MPGuino, but I have a scan gauge II which does the same thing.  I had that for years before I ever heard about the Arduino, I feel pretty silly now for spending well over $100 for it.

That waterduino looks really cool and could have saved me tons of time, I wish I'd seen that before I built the water/methanol injection system for my other car.  Thanks for the link tho, I like that more than what I built and I may do that anyway.
7  Using Arduino / Project Guidance / Re: Arduino as an engine control module? on: February 06, 2012, 03:05:01 am
Your idea is interesting, but let me make some points.    

1.  Does the engine have individual valve lockout?    If not, this idea (6 stroke) is impossible.  

2.  If you do not let the exhaust out after the combustion cycle, all ( and more) energy will be lost recompressing the now hot and expanded products of combustion.   This means leaving the valve open well past TDC, or you have a severe backpressure issue.  

3.  Cooling the combustion chamber after the exhaust stroke, by injecting water on the next compression stroke will cause your engine to be extremely inefficient with very large heat loss to the pistons, cylinder walls, and combustion chamber in the head at the next cumbustion cycle.   Additionally, the cold ( cooled ) cylinders will cause the actual combustion to be much less efficient.  

4.  If your goal is just to improve efficiency of the motor,  re-write your advance and fuel curves and re-write them for maximum economy ( timing for peak pressures that don't detonate or just aren't too far advanced, never richer than the stoichiometric ratio for your fuel.  

Number 4 is worth anywhere from 5 to 30% fuel economy gain on modern emission controlled engines, current emissions calibrations rob your economy quite a bit compared to best economy calibration - and best economy calibration will generally only exceed Oxides of Nitrogen above limits occaisionally.  

1.  No, the engine is a typical OHV.  My idea for this is only based on a 6 stroke engine, mine would be 8 stroke, having intake and compression strokes between the exhaust and water injection strokes.

2. Answered in #1

3. The fuel injectors on this engine are pointed at the wall of the intake manifold runners, so a lot of the fuel would be vaporized there.  Do you have an estimate on how much less efficient the combustion might be due to decreased temperature in the cylinders?

4. I will be doing that very soon.  I added some stuff to the oil that's supposed to increase the seal between the rings and the cylinder wall and raise the compression.  I also wanted to see the power increase (iPod dyno app, not perfect but better than going by feel) from any gained compression, so I don't want to tune it before I can see these results alone.
8  Using Arduino / Project Guidance / Re: liquid level to 12 volt solonoid. on: February 06, 2012, 01:37:06 am
a diagram would help me if you could point me towards one.

I was under the impression that my mega 2560 which im learning about was suitable for 12 volts...or does this only apply to the input voltage.

Regards.
I think you should be fine with using a 5v output from the Arduino, running that to the switch, and having a return directly to the input pin.  You will want to use a pull-up or -down resistor to hold the voltage to a steady on or off so that noise picked up by the wire isn't seen as a the switch opening or closing.  If the switch is normally open, then have a pull-down resistor so that when the switch is open, the input is held at 0 volts.

The circuit I described is this:


That is if 5v doesn't work for some reason, but I believe it should.  The capacitor isn't necessary because you don't need to smooth an an/off signal, but I got used to putting them there on the projects I've done that used a variable DC input and didn't notice I'd put it there till after I looked at the preview.

The 12v is only the power supply.  The actual inputs to the chip (and possibly the whole chip) will be damaged if you apply more than 5v to them.  I accidentally put a pull down resistor to the power rail on my breadboard (12v) and it just took out one pin, but since you have one where you can't replace the chip, I would be very careful.
9  Using Arduino / Project Guidance / Re: Arduino as an engine control module? on: February 06, 2012, 12:58:30 am
Thanks for the replies!

Interesting project.

I'm trying to get my head around the 8-stroke cycle. Are you going to leave the cam alone and actually pull in a fresh charge at the start of the 'steam' power stroke? In this case you'd be throwing away the hot exhaust charge that contains most of the energy you're trying to recover, and the only thing powering your 'steam' phase would be the hot metal. In this case I'm sure that skipping half the power strokes and running water through the cylinder would cool the engine a lot, but I'm sceptical that you'll gain enough power during the steam phase to offset the friction and pumping losses. I suspect you'll end up with a very rough engine with about half the power and a dead loss cooling system.

But it's interesting enough as a concept that I'd like to see how it works in practice.

I suppose that to do this properly you'd need to replace the cam drive system with one that ran at 1/3 crankshaft speed instead of half crankshaft speed, and you'd need to change the cam phase/durations. Getting a custom cam grind isn't technically difficult but needs money and engineering skills. Changing the chainwheel/pulley sizes to change the cam speed is something that is easy in theory but may not be possible in practice, depending on the design of your cam drive. It seems to me that this is the only approach that is likely to work well, though.

How are you implementing the water injection? Are you injecting into the cylinder? What sort of injectors and water supply system are you planning?

What sort of duty cycle are you envisaging for the water injectors? The petrol injectors are probably batch fired, but your water injectors would need to be sequential and accurately phased, so they'll need to be sized to use a much shorter pulse. This may mean you can't simply drive them from the petrol injector signal. You could use the ignition LT pulse to give you a crude engine phase sensor but you still need some logic to decide which part of the engine cycle you're in and switch the fuel and water injection systems on and off.

Needing sequential injection also makes it harder to choose the ECU. There are several aftermarket systems that support sequential injection up to 6 cylinders, but it rules out the experimental systems such as Megasquirt/VSMS. It would be worth doing some research though to find what state MS is up to now - last time I was involved with this they were developing a SMD controller that was planned to support lots of drivers and probably do what you need here.

If you're running this setup in economy mode I guess you'll be around 3000 rpm which corresponds to 20 ms per crank revolution. If you wanted to complete the water injection within say a 45 degree period, that gives you 2.5 ms water injection duration. I wouldn't expect any difficulty achieving that with an Arduino. The pulse wouldn't need to be calibrated accurately as long as you have some scope to dial it up and down a bit to find the best compromise between water consumption and power. You'd also need outputs to disable the corresponding injector, and inputs for crank position (crank trigger wheel?), cam position (#1 spark LT?) and throttle (MAP?) so you could decide when to enable water injection and phase it correctly.

Yes, I'll be leaving the cam alone.  The 6 stroke engines do have a regular exhaust stroke, so they lose much of the heat in the exhaust as well.  Having the second intake/compression strokes will pull in fresh air and compress it, leaving it pretty warm.  I know this isn't as ideal as a specially built engine, but I have a feeling it should work, at least a little bit.  At highway speed, a dead miss on one cylinder isn't typically even noticeable on these engines, so hopefully having a little bit of a power stroke from the water will help.  I have also considered the possibility of disabling the system on idle and acceleration, but I'll figure that out if I come to it.

Another thought I had was to convert it to electronically controlled hydraulic valves, Fiat is working on those for the purpose of varying the lift and duration of the valves.  That would be expensive and complicated, but may be feasible in the near future. 

I'm thinking about the same water injector pulse width as the fuel injectors.  Most of the 6 cycles I read about used about the same quantity of fuel and water, but as the water injectors will probably flow more, the pulse could be shorter.  I will probably use fuel injectors for a direct injection engine as they are designed for high temperature and pressure.  They are becoming more and more common in newer production cars.  I won't be doing this for a while (but I'll probably start on the code), I just bought this car to have something to drive while I build up the engine in my street/track car and it is a cheap one to experiment on once my new engine is built.  I might need to find an additive for lubrication and corrosion protection, I was thinking maybe methanol and the lubricant they add in the engines that burn it.  I would need something for freeze protection in colder months (Iowa, USA) anyway, and that should probably work. I would machine a port for the water injectors into the top of the head.  I'm an automotive technician and have worked on and modified lots of engines, and I know I can do the mechanical and electrical parts, but I will likely need a great deal of help with the programming part.  I will detail the entire process if I end up doing this.  This engine is sequentially injected, so I won't have to do anything with the stock ECU.  I also have HP Tuners, a PCM tuning system that lets me control almost everything about how the engine runs.  I can even set it to not turn on the check engine light for the fuel injector circuit trouble codes that would probably set from opening the power supply to disable the injectors.

I don't think I should need a way to directly measure the crank position.  The stock PCM does this already, and fires a coil at "x" degrees before TDC.  At higher RPMs they have more advance because the fuel takes time to burn and build pressure, I think the water would take time to vaporize as well.  I'm hoping for the water to be injected as soon as the spark occurs for that cylinder.  For disabling the injectors, I'll be using a depletion mode MOSFET for each fuel injector.  Currently the fuel injectors have one power wire from a relay with a splice under the upper intake manifold that has 6 wires coming out of it, so all I have to do is run individual power to each injector.  For enable and disable RPM, I can just measure the time between  coil firings.  On this engine, 3 coils are used that fire on two companion cylinders at the same time.  Companion cylinders reach TDC at the same time, one on exhuast and one on compression, so coil pulses on one coil per minute equals RPM. I don't think I should have to measure the throttle or MAP, because the time the fuel injectors are commanded on is already calculated by the PCM based on these inputs.  I'm hoping to just multiply that by a number to get how long to fire the water injector (after measuring the flow rate), and it's possible it could even be the same time.

You'll need some additional way of telling whether the spark is for a particular cylinder, perhaps a flip-flop readable by the Arduino that is set by a spark to a particular cylinder and cleared by a spark to the next cylinder.

I think I should be able to tell what cylinder the spark is for by looking at which fuel injector fired most recently.
10  Using Arduino / Project Guidance / Arduino as an engine control module? on: February 05, 2012, 07:24:36 am
I've been reading about experimental 6-stroke engines, and would like to try to convert my existing vehicle(s) to run using this method.  Essentially, at TDC on the exhaust stroke in a regular 4 stroke engine, both valves close as the piston approaches TDC.  High pressure water is then injected directly into the cylinder which turns to steam and forces the piston downward again.  Then there is an exhaust stroke for the steam, and we're back to the regular intake stroke.  This eliminates a large portion of the energy that is wasted in the form of unused heat.  These engines use roughly half the fuel of a conventional 4 stroke engine, and many don't even have a cooling system.

What I would like to build would be an 8-cycle engine (having a "regular" intake and compression stroke essentially wasted), as it would be impractical to rebuild the engine(s) to be true 6-cycle.  One problem with the 6-stroke is that until it warms up, it coasts through 2 strokes which makes them run rough.  I would have mine run in 4-stroke mode until warmed up, at which time it would switch to 8-stroke.  The first car I would try this on is an '01 Impala with the 3.4L V6.  Sequential fuel injection with one coil per pair of companion cylinders.  It has a maximum RPM of 5,600 RPM.  The 3 coils fire once per revolution, one spark ignites the air/fuel mixture and the other one fires in the companion cylinder which is on the exhaust stroke.  The fuel injectors fire every-other revolution, one on each cylinder.

What I would have to do is disable the fuel injector for the cylinder that is having water injected into it and run the water injector solenoid when the PCM commands spark for that coil.  Then the next time the fuel injector is commanded on, it would be allowed to do so, and water would not be injected with the spark.  Obviously the 16Mhz could handle this if the timing didn't need to be extremely accurate, but I'm not too sure how fast it would make it through the program, a couple milliseconds could let it run very lean or miss a power stroke altogether.  I don't have a lot of experience with the Arduino or programming in general, however I do have considerable experience with electronics.  I did build a methanol injector controller using a standalone Atmega328, but it read the throttle position, two adjustment pots, and varied the pulse width to the transistor that controlled the pump based on these 3 inputs.  I also built a sun tracker for a solar panel, and lots of little things just for fun.  But the timing needs to be pretty close here, where timing was of little to no concern on everything else I've done. 

I would also like to be able to measure how long each fuel injector is on, and inject a proportionate amount of water to make the engine run smooth.  The fuel injectors are commanded on to hundredths of milliseconds.  The on-time seems to be roughly  .12 mS resolution, which I assume the Arduino would miss completely.

Can any of the microprocessors available on an Arduino do this?  I will be building a module using a standalone microprocessor, so I can use a 20Mhz resonator if using the Atmega328 or another IC that can use an external timing device if 16Mhz would be a bit short.  It would be perfectly acceptable to me to have a maximum RPM of about 3,000 while running in 8-stroke mode, but any lower than 2,000 RPM wouldn't be worth my time to build this.  Any guesses as to how long it would take to execute the code required to do everything I need?
 

Thanks in advance,
Jason
11  Using Arduino / Project Guidance / Re: liquid level to 12 volt solonoid. on: February 05, 2012, 06:31:15 am
If it's a switch (on/off), it seems to me that distance would be somewhat irrelevant.  Resistance and capacitance of the wires aren't a concern as they are for longer distances of data cable.  The resistance on the input pin to the Arduino is significantly greater than the resistance of the wire, so using Ohm's law, we know most of the voltage is present at the input.  Ethernet cable has a resistance of .188 ohms/meter, so the 200m in your cable has 37.6 ohms total, while the input has a resistance of 1M ohm.  You should have VERY close to the source voltage at the input.  Capacitance doesn't really do anything to a steady voltage, especially what little exists between the wires.

If you do have a problem with 5v for some reason, you could run 12v to the level switch, then have a resistor in series with the return wire and the Arduino.  You would also need a 5v zener diode in parallel with a fairly high resistance resistor to ground between this resistor and ground.  The series resistor would limit the current to something the wire and zener diode can handle, the zener diode would limit the input voltage to 5v after the series resistor, and the resistor in parallel with the diode would drop the signal voltage to zero when the switch opens.

Am I under-thinking this?
12  Using Arduino / LEDs and Multiplexing / Re: 4051 not working right on: April 07, 2011, 03:01:32 am
Thank you very much for your help and patience Korman.

This is a bit embarrassing, but hopefully admitting this will help someone else if they screw up too.  The jumper wire I had connecting the two ground rails on my breadboard had developed an open spot.  It's quite obvious just by feeling the wire, there's a very soft spot right where it bends.  Apparently I overlooked this in my sleep deprived state.  Pins 4,5,6,7 (1,2,4,5 on the DIP) were effectively connected to each other through a 2k resistor.

I'm not sure why reading pin 3 (on the side that was actually connected to ground) showed 00011111 in serial monitor, it may have something to do with the fact that the input pin on my Arduino was also using this "floating" rail as ground for the pull-down resistor, but that should make all pins read 1.  If I have time in the future, I may try to figure this out, but for now I've got it working as it should and that's all I care about right now.
13  Using Arduino / LEDs and Multiplexing / Re: 4051 not working right on: April 06, 2011, 02:24:48 am
I was very tired last night when I asked for help, let me re-type this in a slightly clearer state of mind.  I think I used up the last of my mental energy trying to figure out the problem myself smiley

While running the sketch below, Arduino's digital pins 2,3,4 are connected to the 4051 pins s0,s1 and s2, respectively.  I have power to pin 3 on the 4051, and ground on pins 6,7,8.  The 4051's multiplexed pins (A0-A7) are all connected to a 1k ohm pull-down resistor.  I have checked multiple sources and this appears to be the correct way to hook everything up.

I wrote a simplified sketch that doesn't use bitshifting or for(), and with the variables removed.  It's a bit easier to see the intended function.  All it does is write to the select pins, and send the value of the input pin to the serial monitor.  I tried it with and without using the commented-out "delay(200)" since before it behaved differently with and without delay().  It now makes no difference whether I use delay() or not.
Code:
int readPin = 9;
void setup() {
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(readPin, INPUT);
  Serial.begin(9600);
}
void loop() {
  digitalWrite(2, 0);
  digitalWrite(3, 0);
  digitalWrite(4, 0);
  //delay(200);
  Serial.print (digitalRead(readPin));
  digitalWrite(2, 0);
  digitalWrite(3, 0);
  digitalWrite(4, 1);
  //delay(200);
  Serial.print (digitalRead(readPin));
  digitalWrite(2, 0);
  digitalWrite(3, 1);
  digitalWrite(4, 0);
  //delay(200);
  Serial.print (digitalRead(readPin));
  digitalWrite(2, 0);
  digitalWrite(3, 1);
  digitalWrite(4, 1);
  //delay(200);
  Serial.print (digitalRead(readPin));
  digitalWrite(2, 1);
  digitalWrite(3, 0);
  digitalWrite(4, 0);
  //delay(200);
  Serial.print (digitalRead(readPin));
  digitalWrite(2, 1);
  digitalWrite(3, 0);
  digitalWrite(4, 1);
  //delay(200);
  Serial.print (digitalRead(readPin));
  digitalWrite(2, 1);
  digitalWrite(3, 1);
  digitalWrite(4, 0);
  //delay(200);
  Serial.print (digitalRead(readPin));
  digitalWrite(2, 1);
  digitalWrite(3, 1);
  digitalWrite(4, 1);
  //delay(200);
  Serial.println (digitalRead(readPin));
}

When I start serial monitor with all the 4051 input pins to ground through a 1k resistor, I see 00000000, as I should.  When I touch a 5v wire to the input pins on the 4051, I see the following:
5v to pin 0 shows 10000000 in serial monitor
5v to pin 1 shows 01000000 in serial monitor
5v to pin 2 shows 00100000 in serial monitor
5v to pin 3 shows 00011111 in serial monitor
5v to pin 4 shows 00001111 in serial monitor
5v to pin 5 shows 00001111 in serial monitor
5v to pin 6 shows 00001111 in serial monitor
5v to pin 7 shows 00001111 in serial monitor

5v to multiple pins shows up as you would expect based on the readings above, eg. power at 0,2,6 shows 10101111

I'm very curious why pins 0,1,2 on the 4051 are read correctly and the rest are not.

My goal, for now, is for the readout on serial monitor to be the current state of the pin, either high or low.  I just want to be sure that I know how to hook this up before etching the PCB the chips will be attached to.

Since you asked what I'm trying to do, I am building a methanol injection controller for my car.  Ultimately I will be using a 4051 (in conjunction with NAND and AND gates) to ensure that when the transistors are switched on, the controlled devices (pump and injectors) have power and, if commanded, ground.  I just ran out of pins, and the 4051 seemed like a good option
14  Using Arduino / LEDs and Multiplexing / 4051 not working right on: April 05, 2011, 02:40:20 am
I was playing around with my new 4051 (I bought 5 and have tried this same code on each one with the same results), and can't get it to work right.  A0-A2 will work correctly, but only if using delay().  I have tried this with and without pull-down resistors (10k and 1k) attached to the inputs on the 4051 and on the input pin on my Arduino.   When I run this code...
Code:
void loop() {
  for(int count = 0; count <=7; count++){
    r0 = count & 0x01;
    r1 = (count>>1) & 0x01;
    r2 = (count>>2) & 0x01;
    digitalWrite(2, r0);
    digitalWrite(3, r1);
    digitalWrite(4, r2);
    val = digitalRead(readPin);
    a,b,c,d,e,f,g,h =0;
    if(count == 0) a=val;
    if(count == 1) b=val;
    if(count == 2) c=val;
    if(count == 3) d=val;
    if(count == 4) e=val;
    if(count == 5) f=val;
    if(count == 6) g=val;
    if(count == 7) h=val;
  }
  Serial.print (a);
  Serial.print ("  ");
  Serial.print (b);
  Serial.print ("  ");
  Serial.print (c);
  Serial.print ("  ");
  Serial.print (d);
  Serial.print ("  ");
  Serial.print (e);
  Serial.print ("  ");
  Serial.print (f);
  Serial.print ("  ");
  Serial.print (g);
  Serial.print ("  ");
  Serial.println (h);

...I get the number on the right (in serial monitor) when a 5v wire is touched to the pin represented by the binary number on the left:
000 - 11000000
001 - 00001100
010 - 00110000
011 - 00000011
100 - 01010101
101 - 01010101
110 - 01010101
111 - 01010101

I then wrote a new sketch (which I accidentally closed without saving and I'm not going to re-write) that had a 5 second delay after S0,S1,S2 writes, then read the input and sent the serial out.  I went through and did each one manually so I could check the inputs/outputs with my voltmeter as the sketch progressed.  For example, using input 2:
    digitalWrite(2, 0);
    digitalWrite(3, 1);
    digitalWrite(4, 0); (of course I changed these values to select the correct pin)
    delay(5000);
    c=digitalRead(9);
    Serial.print("c");
With 5v only to the pin it was supposed to read, this sketch gave the output:
000- 10000000
001- 01000000
010- 00100000
011- 00011111
100- 00001111
101- 00001111
110- 00001111
111- 00001111

I wired it up as shown in the playground (http://www.arduino.cc/playground/Learning/4051), and verified on the manufacturer datasheet the the pins were the same.

Thanks in advance for any help!
-Jason
15  Using Arduino / Networking, Protocols, and Devices / Re: best way to communicate between 2+ standalone ATMEGA328s? on: March 05, 2011, 02:33:40 pm
It is my understanding that the analog to digital to converter needs 10mS between reads or the reading can be influenced by the last reading, 6 sensors 60mS.  Is that incorrect?
Pages: [1] 2