Toyota Repair: Code P0171 1998 Rav4, throttle position sensor, air flow meter


Question
I have 1998 Toyota Rav4 4cyl,4wd, 120000 miles and am trying to sort out a problem.The engine is intermittently running terribly. There seems to be no logic to it and of course stops doing it everytime i bring it to the mechanic. It can be what feels like a misfire at all speeds sometimes when the engine is cold and sometimes hot. Here is what i have done so far. New plugs and wires, new fuel filter,new airfilter. The Code p0171 lean fuel bank 1 has several parts it would seem to indicate, but all of those if malfunctioning would trigger a different code  unique to that part. I am at a loss because there a so many sensors that would cause this problem. There is one other symptom that may help. The car idles high on cold start around 2000 rpm for a long time, also after it has warmed up it will sometimes idle normally around 1000 rpm and sometimes at 300 rpms. Could this problem be the throttle position sensor?  Also the throttle body was sticking so i cleaned that out.Why would it not set the code for anything but p0171.  We have cleared it and it has been reset many times.The car is also getting terrible gas mileage around 10 mpg,  thanks i look forward to your answer. Nathaniel

Answer
The erratic idle is caused by a sticking idle speed control valve, it's located on the throttle body and it can be removed and cleaned.
The PO 171 code is a lean fuel trim condition, while cleaning the ISC valve remove the air flow meter located between the air cleaner and throttle body on the intake and try cleaning it with some electronic cleaner, make sure the cleaner gets to the small platinum sensor wires inside the opening of the MAF(air flow meter) or just replace it, this will take care of the 171 code.