You should post the schematic of your setup along with the code you are using. Without more info it is difficult to give you proper answers.

Al.