# Teensy 4.0, 'disabling' an analogRead pin

##### Well-known member
I have a 5v output analog pressure sensor. It does not output > 3.3V until 70psi. My system does not go over 60psi. BUT, just in case I do exceed 70psi, I was thinking that :

if (psi <= 69) { analogRead (sensorPin);}

if (psi>=70){ digitalWrite(sensorPin, LOW);}

this works, in that the pin is semi 'disabled' and pressure readings stop. but I think the sensor pin is not truly disabled. So can I still damage the Teensy 4.0 if >3.3v hits the sensor pin while in LOW setting?

and BTW, i built a 20/10k voltage divider w/cap and did a linear regression plot for converting the new 3.3v readings, and the code adjustments as needed. Even after multiple measurements and attempts, the pressure readings were always off compared to the pure 5v output readings and the initial plot.

aRef is 3.3v
alpha is .95

Code:
``````void calculatePsi() {
filteredVal = (alpha * filteredVal) + ((1.0 - alpha) * sensorVal);  // Low Pass Filter
voltage = (filteredVal / 1024.0) * aRef;   // calculate voltage
psiValInitial = (voltage - 0.4784) / 0.0401;  //linear regression calculation from sensor data plot, at 5v
//psiValInitial = (voltage - 0.4423) / 0.0295; //for voltage divider at 3.3v
psiVal = round(psiValInitial);  //so I don't see decimals on my OLED
if (psiVal != psiOldVal) {
psiOldVal = psiVal;
}
if (psiVal < 0) { psiVal = 0; }
}``````

transducer details:
Pressure transducer works for oil, fuel, , gas, water, air pressure, can be used in oil tank, gas tank, tank etc.
Material: Stainless steel
Voltage: DC 5V
Pressure: 100 psi
Accuracy: within 2% of reading (full scale).
Wiring: Red for +5V; Black for ground; Blue for signal output.
Output: 0.5V~4.5V linear voltage output.
Accuracy: within 2% of reading (full scale).
Wiring Connector: Water sealed quick disconnect. Mating connector is included.
Overload Capacity: 2-4 times of rated pressure
Working Temperature: -40℃~+120℃
Compensation Temperature: 0℃~+80℃
Protection Class: IP67
Pressure Medium: Oil, gas and water which is compatible with 316L stainless steel

Why don't you place two clamp diodes so the input cannot exceed the 3v3?

Switching the pin to low (which would only work if the pin is set to output mode) would short the incoming voltage to GND, via the Teensy. You have to physically prevent excess voltage reaching the pin.

Schottky clamp with series resistor is typically used for this. Add a cap on the analog pin to keep the impedance low, so 1k, schottky to 3.3V rail, 100nF to ground...

thx for replies! I read about the diode setup. I just don't have any on hand and was wondering about other options via code. I will give the diodes a try. Something like this? THX!

Like that, but with the top diode to the 3.3V rail, not 5V.

Shouldn't the 4k7 resistor go between the capacitor and the schottky diode jn?

Just lose it, you need the cap direct on the analog pin for best performance. The divider provides current limiting anyway.

Good point!

yep, the regulated 3.3v, not 5v. I will get rid of the 4k7. My voltage divider circuit is similar to above, but without the diodes. I thought the cap (mine is a 10nf) went from the divided resistors to ground? not the input signal to ground?? I have this as my voltage divider:

So I switched the cap over to the sensor input side of the voltage divider(Thx MarkT), and re-adjusted the slope calculation for the new voltage drop, and with a little tweaking of slope, I am now getting steady and fairly accurate readings. THX for everyone's help!