Turn off the circuit breaker for your smoke alarm circuit. This is very important. You will get shocked and possibly seriously injured if you attempt to work on a circuit that is not turned off.
Find the first junction box on the smoke alarm circuit. This most likely will be in the alarm location closest to your breaker box. The junction box will have 14-2 NM cable (white wire, black wire and bare ground wire) coming in from the junction box and 14-3 NM cable (white, black and red wires plus a bare ground wire) going on to the next box.
Strip about half an inch of the sheathing from each of the colored wires (white, black and red) in the junction box.
Look at the smoke alarm you are going to install at the junction box. It will have a black wire, white wire, bare ground wire and one other wire that usually will be either red or yellow.
Use a wire nut to connect the two bare ground wires in the junction box to the bare ground wire on the smoke alarm.
Connect the two black wires in the junction box to the black wire on the smoke alarm with another wire nut.
Connect the two white wires in the box to the white wire on the smoke alarm.
Connect the red wire in the box to the red or yellow wire on the smoke alarm. This wire is the so-called traveler. Connecting it means that if this smoke alarm is tripped, all of the other alarms on the circuit also will sound. This is one of the major advantages of hardwired smoke alarms.
Proceed to every other junction box on the circuit and hook up each alarm by connecting all the wires in the box to the same-colored wires on the alarm.
Go back to the breaker box and turn the smoke alarm circuit on.