How does an ECU vary the fuel mixture? When climbing to altitude? Is it just programmed to run at a set air/fuel mixture, based on power settings?
There is no O2 sensor in our example.
Note there are several answers to your question. Each answer represents a different way of looking at the question.
First, lets try to address "how" the mixture is varied which is your basic question. The injector is pulsed on and off at a very high rate of speed. The amount of time (%) the injector spends turned on per second is called its "duty cycle". An injector should not be over taxed by running it open 100% of that 1 second. Something like a max of 80% of the time is acceptable. If the injector must operate more than 80% to supply enough fuel, then a larger (more gph) should be substituted. If the injector is only open a minimal time, it may be too large and make tuning difficult to control at low rpms. In that case a smaller injector may be needed. You should realize that an injector opens and closes
hundreds of times per second. Making the mixture richer or leaner is controlled by how many times the ECU tells the injector to open each second.
How does the ECU tell the injector to open and close? I think most/all systems use a 5 volt current to control everything in the whole system. Basically the ECU measures changes in this voltage and compares that to a known/wanted algorythm. Its pretty much as simple as that. The ECU sends out a 5 volt reference signal and measures how many volts return. Most sensors are simply adapted resistance units. A quick way to explain this is the temperature sensor. Depending on the temperature of the engine, the resistance of current flowing thru the sensor will vary from the initial 5 volts.There is a target voltage that tells the ECU that the engine has reached a predetermined temperature. Most other sensors use this same premise to inform the ECU.....varying voltage. It is very important that the battery in your electrical system be in good condition and producing full voltage. A marginal battery can cause an incorrect reference voltage being sent out and therefore an incorrect return signal.
How does the ECU know how much fuel to send out? Here is where it begins to get involved somewhat.
First we need to define the two basic types of EFI systems. Then inject "open and closed " loop into the understanding.
One system is call "Speed Density". In a Speed Density system a MAF sensor isn't used. MAF stands for MASS Air Flow. Since it isn't used, I'll skip it for now. In the Speed Density system there are several sensors that affect why the ECU richens and leans the mixture. Most of these will also be used in the other (MAF) system and perform the same function.
Your system without a MAF will be a "Speed Density" system.
The main thing to remember is that the Speed Density system will use a sensor called a MAP sensor. That stands for Manifold Absolute Pressure.

The MAP sensor plugs into your intake manifold plenum and senses what is going on inside of it, and by varying the 5 volt reference signal (resistance) tells the ECU what is going on as far as air flow needs go. The ECU uses this info coupled with other sensor inputs to pick the correct preprogrammed algorythem for the condition. Its reading the amount of vacuum or boost inside the manifold.Changing atmospheric conditions do not affect its ability to sense engine needs. This sensor can be employed by itself or used in conjunction with a system also employing a MAF sensor.

This is an older style MAF sensor. It is NOT used in the "Speed Density" system. If you look at the inside of a MAF sensor you will see a fine wire. Air flowing over this wire cools it. The more air, the cooler the wire. As the temperature of the wire changes, so does its resistance and the 5 volt reference signal from the ECU changes. When the changed voltage returns too the ECU, the ECU compares the info to another algorythm. Now temperature of the air and temperature of the engine also play a part in the ECU choosing the correct algorythm.
So, we add a sensor that checks the ambient air temperature and send a variation of 5 volts to the ECU. We also add a coolant temperature sensor that tells the ECU what the engine temperature is.
The Ambient Air sensor is usually mounted in your air intake somewhere ahead of the throttle body. It uses air flow over a fine wire just like the MAF sensor.
The coolant temperature sensor can be screwed into the engine coolant system. It has a much thicker body but still works by temperature varying resistance to electrical flow.
Earlier, it was mentioned that a "Throttle Position Sensor" was not needed. I don't feel thats a correct statement. An engine will run and will change speeds based on readings from the other sensors. That part is correct. The reason you need a Throttle Position Sensor is for rapid changes in airflow such as at takeoff or during an aborted landing. The ECU needs to know that you suddenly went from an idling situation to a WOT situation. When you do that, your engine goes from running in Closed Loop to Open Loop. (Which I haven't discussed yet). For right now, what you need to know is that the ECU completely goes to a different set of algorythms and mode of operation. So, I think its best to have an operating Throttle Position Sensor. It does exactly what its name suggests. It is mounted on the side of the Throttle Body and as the valve rotates to open position, it moves a resistor and tells the ECU how far it is open....which helps the ECU compute the air flow, and how quickly the need changed. Its a rheostat.
Its getting late, so a couple more points that weren't mentioned.
The ECU is constantly monitoring many things which can cause it to lean the engine fuel. In factory OEM systems there is a sensor called a knock sensor. It senses when your engine is running too lean and begins to knock or ping. It can hear this noise long before your ears pick it up. The ECU is constantly advancing timing and leaning fuel until a knock is sensed, then it backs off and does it again. So when you are cruising, this is happening if your system is designed to do so.
MAF system (as opposed to a Speed Density system). A MAF system will as its name implies utilize a MAF (Mass Air Flow) sensor. All it does is send the computer information on the amount of air being consumed. It can be used in conjunction with a MAP sensor, or without one.
Open Loop and Closed Loop. Both systems operate in Open and Closed Loop.
When an engine is cold or cool,
the ECU gets a voltage signal from the engine (coolant) temperature sensor. This will
tell the ECU to ignore any signal from the O2 sensors. An O2 sensor is basically inserted into the exhaust and sends a voltage representing how much Oxgen is contained in the exiting exhaust. Conversely the amount of Oxygen present in the exhaust tells the ECU also what amount of fuel (excess or lean) is contained in the exhaust. When the engine is cold, it probably won't start on the usual fuel mixture, and it needs to be artificially enrichened. Everyone knows what a "choke" is on a lawnmower. It allows the engine to get more fuel than normal to start the engine. Well thats just what "Open Loop" does. The ECU ignores the fact that its being told by the O2 sensor that the mixture is too rich. It pulses the injectors more than normal and provides extra fuel. When the engine has warmed sufficiently, the ECU will change to "Closed Loop" and start accepting the signal from the O2 sensors. If you suddenly push the throttle wide open, the ECU will go into "Open Loop" and provide a precalculated richer than normal mixture. Thats why a throttle position sensor is needed. It might work OK without one, but all the OEMs employ them.
I know I've probably forgotten something but hopefully this helps you understand a little better.