Technical Description
Malfunction of Vehicle Speed Sensor “B”
This diagnostic trouble code (DTC) is a generic powertrain code, which means that it applies to OBD-II equipped vehicles, including but not limited to Ford, Toyota, Dodge, BMW, Subaru, Honda, Lexus, Mazda, etc.
Although generic, the specific repair steps may vary depending on make/model.
What does that mean?
In simple terms, the P2158 code indicates that the vehicle’s speed as detected by the Vehicle Speed Sensor (VSS) “B” is not functioning as expected. The VSS input is used by the vehicle’s main computer called a PCM/ECM powertrain/engine control module along with other inputs for proper operation of the vehicle systems.
Typically, the VSS is an electromagnetic sensor that uses a rotating reluctor ring to complete an input circuit to the PCM. The VSS is mounted in the transmission housing at such a position as to allow the reluctor ring to pass by it; in close proximity. The reluctor ring is attached to the output shaft of the transmission so that it spins along with it. As the reluctor ring passes by the electromagnetic tip of the VSS, notches and grooves serve to complete and interrupt the circuit rapidly. These circuit manipulations are recognized by the PCM as transmission output speed or vehicle speed.
A typical VSS or vehicle speed sensor:

Symptoms
Symptoms of a P2158 DTC may include:
Causes
A code P2158 may mean that one or more of the following has happened:
Possible Solutions
A good first step to do as a vehicle owner or DIYer is to search for technical service bulletins (TSBs) for your particular vehicle make/model/engine/year. If a known TSB exists (as is the case for some Toyota vehicles), following the instructions in a bulletin can help you save time and money in diagnosing and repairing your issue.
Next, visually inspect all wiring and connectors that lead to the speed sensor. Look closely for any chafing, bare wires, broken wires, melted, or otherwise damaged areas. Repair as required. The location of the sensor depends on your vehicle. The sensor could be on the rear axle, transmission, or perhaps the wheel hub (brake) assembly.
If the wiring and connectors are OK, then check the voltage at the speed sensor. Again, the exact procedure will depend on your make and model of vehicle.
If everything looks OK, replace the sensor.