In the first box, connect the two black wires together and add the black wire from the smoke detector connection. Now tie all the white wires together. Tie the bare copper ground wires together and run a pigtail
to bond it to the box. Connect the red wire to the interconnect wire from the smoke detector. This wire will usually be marked and is usually a yellow wire. Make each connection with a wire nut big enough to cover all exposed wires.