It sounds like you wired the switch up to create a direct short (hot to neutral). This will of course trip the breaker every time you flip the switch on.
You want to switch just the hot wire, and connect the neutral through to the next box. Do you know where power enters these boxes?
I see two obvious possibilities:
Power at the ceiling box
Do you have an electrical tester? In your ceiling box, test the black/white pair that enters that box in the same cable (14/2 or 12/2 NM cable, probably). If that cable is hot, then you are going to:
- Connect the white wires in the ceiling box with a 6" pigtail (the pigtail will connect to the light fixture)
- Connect the red wire to your light fixture (this will be your switched "hot" conductor)
- Connect the black wires straight through the ceiling box (no pigtail).
- Connect the white wires in the switch box with a pigtail (this is your neutral, cap off the pigtail if your current switch doesn't use the neutral, and leave it for future use)
- Connect the black wires with a pigtail, then connect the pigtail to one of the poles on your switch.
- Connect the red wire to the other pole of your switch.
- Connect the white and black to your receptacle in the wall outlet box (observe proper polarity).
- Connect all the grounding wires to each other and to all devices.
Power at the wall outlet box (unlikely based on your description)
This seems a lot less likely based on your description. It looks like you are saying that there are only two conductors in the wall box (one black, one white). Nevertheless, if power is entering the wall outlet box on one pair of wires, then going to the switch on another pair (two blacks and two whites plus grounds in the wall box), do the following. Test the wires, of course, to see if this is where power is feeding into this part of the circuit.
- Pigtail both the black and white in the wall outlet box, and connect the pigtails to the receptacle (observe proper polarity)
- in the switch box, connect the black wires with a pigtail, connect the the pigtail to one pole on the switch.
- Connect the red wire to the other pole on the switch.
- Connect the white wires with a pigtail, cap off the white pigtail for future use (unless your current switch uses the neutral)
- In the ceiling box, connect the white wires with a pigtail, connect the pigtail to your light fixture.
- Connect the red wire to your light fixture (this is your switched hot wire).
- Presumably the other black/white wire pair in the ceiling box is taking power on to another non-switched outlet elsewhere (else there would be no point in the 3-conductors from the switch).
- So...connect the black wires together in the ceiling box.
- Connect all the grounding wires to each other and to all devices.