This paper considers a method of coding the sensor outputs in order to detect stealthy false data injection attacks. An intelligent attacker can design a sequence of data injection to sensors that pass the state estimator and statistical fault detector, based on knowledge of the system parameters. To stay undetected, the injected data should increase the state estimation errors while keep the estimation residues in a small range.We employ a coding matrix to the original sensor outputs to increase the estimation residues, such that the alarm will be triggered by the detector even under intelligent data injection attacks. This is a low cost method compared with encryption over sensor communication networks. We prove the conditions the coding matrix should satisfy under the assumption that the attacker does not know the coding matrix yet. An iterative optimization algorithm is developed to compute a feasible coding matrix, and, we show that in general, multiple feasible coding matrices exist.