This post was written for 1998-2004 Toyota Corolla. Starting in 2005+ the Corollas switched from an upstream oxygen sensor to an air fuel ratio sensor. Later models switched from drive by cable to drive by wire and do not have an IAC.
When you get error code P0171 it means that your engine is running lean. Running lean or rich refers to the amount of gas relative to the amount of air in the combustion chambers. Running lean means that there is more air than appropriate for the amount of gas. Running rich is the opposite and means that there is less air than is appropriate for the amount of gas.
Your engine control unit (ECU) tries to maintain stoichiometric 14.7:1 air to fuel ratio. This is the mass of air that is required to react perfectly.
The ECU relies on data from MAF (mass air flow sensor, some engines rely of a MAP sensor instead) to know how much fuel to inject. The MAF senses how much air is getting into the engine. The ECU uses the pre-cat (upper) O2 sensor to sense the amount of fuel in exhaust gasses and fine tune the amount of gas to inject.
Furthermore, the amount of air entering into an engine is controlled by the throttle body. An engine with a throttle plate closed with no other route for air to get into the engine would not run. Therefore on these vehicles there is an Idle Air Control (IAC) which lets into the engine. The IAC lets air measured by the MAF to bypass the throttle plate and the engine to idle.
Stepping on the “gas” opens the throttle plate, allowing more air in. The ECU senses the this change with a Throttle Position Sensor (TPS) and also sees the increase in MAF values and responds by injecting more fuel to maintain the 14.7:1 ratio. It uses O2 sensor data to fine tune via fuel trim and get as close to 14.7 to 1 as possible.
A vacuum leak lets more air into the engine. This additional air is not metered or measured by the MAF so the ECU initially injects less fuel than is needed for all the air in the engine. It senses this lean condition based on o2 sensor data and then ramps up the fuel trim to respond. These fuel trim levels become out of range for normal operation and the engine throws code P0171.
A lean code can also occur from insufficient fuel. In this instance the normal firing pattern of the fuel injectors is unable to keep the stoichiometric ratio at 14.7:1. The ECU senses this lean condition and ramps up fuel trim (injector firing time) to compensate. Think of a restricted garden hose vs unrestricted. To fill up a the same bucket with a clogged hose you will need to hold the nozzle open longer. An unclogged hose will fill it up faster. Poor fuel pressure will also force you to hold the nozzle open longer.
When the ECU throws a lean code it will record the values and engine parameters (called freeze-frame data). This is critical for diagnosis of p0171. Here’s why: The lean code for fuel problems will often be set at a higher RPM. Using live-data will also help you pinpoint the problem because fuel trims will get worse (further away from 0) with higher RPMs as the injector is unable to keep up with engine load demand.
A lean code due to a vacuum leak will have freeze-frame data set at lower RPM. Using live data to monitor fuel trims you will see that fuel trims will get better (closer to 0) with higher RPM as the amount of air leaking in becomes less significant compared to the amount of metered air going past the throttle plate.
If any of these sensors are not good you can have faulty or erroneous codes. The MAF could be shot as well as the O2 sensor.
Here are the appropriate MAF values if you’re connected to your vehicle with a scan tool featuring live data.
This is from the Toyota shop manual. If your scanner displays data in lb/sec you will need to convert to grams/sec.
Condition . Air flow rate (gm/s)
Ignition switch ON (do not start engine) . 0 gm/s
Idling . 4 to 6 gm/s
Running without load (2,500 rpm) . 13 to 20 gm/s
From idling to quickly accelerating . Air flow rate fluctuates
O2 sensors can also be bad. That’s why you need to look at the voltage of sensor 1 bank 1 and make sure it oscillates from rich high voltage to lean low voltage. The DENSO sensors on these oscillate from .8 to .1.
Once you’ve made sure your sensors are in working order you will need to figure out if the lean code is caused by insufficient fuel or too much air. These clues will then allow you to look for a vacuum leak or to look at the fuel supply as the cause of your P0171.