Toyota Repair: 2003 Camry Trouble code P-0031, air fuel ratio, oxygen sensor


Question
This is a 2003 Camry 4 cyl with 178,000 miles
We have been getting this code regularly for the last 2 years.  Took it to the mechanic recently and they replaced the Oxygen Sensor primary on the exhaust manifold.  The code continued and they advised replacing the signal at the ECM was irradic.  I replaced that with a used part and it did not set the code for about 5 miles since then it has set the code continually.  When the code sets the engine is idling rough until it starts a few times after setting the code then it smooths out for the long haul. Is there an idle relay or such that may cause the rough idling?   Not sure what to do now, thank you for your help.

Answer
This code is for the air/fuel ratio sensor in front of the catalityc converter:DTC P0031 OXYGEN SENSOR HEATER CONTROL
CIRCUIT LOW (BANK 1 SENSOR 1) I assume this is the sensor that was replaced, replacing the ECM didn't seem to help also so the only thing left is a problem in the wiring between the ECM and the A/F sensor.