Hi guys, looking at this thread, I get the feeling that you're both talking at cross-purposes?
Flemmard, I think you're asking about connecting your sensor to an
ADC pin of your PIC and then using some code to differentiate between 5V and 1.5V voltage levels on it.
you are correct.May i know how do i do that in PIC C ?
Eric OTOH, I think you're talking specifically about connecting the sensor directly to a
digital IO pin of the PIC, and relying upon the thresholds being ok for the PIC?
Eric, isn't it the case that having voltage levels a bit close to the thresholds is a little iffy in terms of power consumption or such? Or is that only when the input pins are left floating? I forget. Presumably with the adjustment described it's probably ok anyhow.
Flemmard, if you use what I think Eric's technique is (digital IO pin), you don't really need special code to tell the PIC to set any ranges, the PIC
can't directly alter its own threshold levels for the digital pins. Eric's description with the potentiometer is for adjusting the voltage range of the sensor to fit the PIC, rather than the other way round. I think.
If OTOH you still prefer to use an ADC pin, then after reading the ADC port (which IIRC is a little bit more involved, but I've not got that far in my PIC experiments yet
) you would simply compare the ADC value to some constant that would lie firmly in-between the values corresponding to each voltage, if that makes sense. Eric's digital IO method is probably better for what you're asking for. Less programming