Abstract. Using Heegaard Floer homology, we construct a numerical invariant for any smooth, oriented 4-manifold X with the homology of S 1 × S 3 . Specifically, we show that for any smoothly embedded 3-manifold Y representing a generator of H 3 (X), a suitable version of the Heegaard Floer d invariant of Y , defined using twisted coefficients, is a diffeomorphism invariant of X. We show how this invariant can be used to obstruct embeddings of certain types of 3-manifolds, including those obtained as a connected sum of a rational homology 3-sphere and any number of copies of S 1 × S 2 . We also give similar obstructions to embeddings in certain open 4-manifolds, including exotic R 4 s.