Designing a communication protocol for sensor networks often involves obtaining the "right" trade-off between energy efficiency and reliability. In this paper, we show that network coding provides a means to elegantly balance these two goals. We present the design and implementation of SenseCode, a collection protocol for sensor networks---and, to the best of our knowledge, the first such protocol to employ network coding. SenseCode provides a way to gracefully introduce a configurable amount of redundant information in the network, thereby increasing reliability in the face of packet loss. We compare SenseCode to the best (to our knowledge) existing alternative and show that it improves reliability (in our experiments typically by 15%-20%), while consuming a comparable amount of network resources. We have implemented SenseCode as a TinyOs module, and evaluate it through extensive TOSSIM simulations.