Analog input pin “outputting” 5 volts - not floating

One of my five analog input pins shows 5 volts, or 100% input value no matter where the potentiometer is set; other than 5% or less of potentiometer position. 10k pot, once I turn it up to about 5% it just maxes the value (255). I’ve tried different pots too. The four other inputs work fine. I can move the pin to another A pin in the program and it works, but I can’t figure out why this particular pin is behaving this way.

A1 is the faulty pin. I can move it to A7 and it’s happy with the rest of them. This is also being prototyped on a breadboard, nothing soldered yet.


#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <ArducamSSD1306.h>

//***********************************************************************

//DEFINE I/O TAGS AND PINS
const int trigPin=PIN5;
const int echoPin=PIN6;
const int stopLight=PIN2;
const int driveLight_1=PIN3;
const int driveLight_2=PIN4;
const int DL_1_Low_Pot=A0;
const int DL_1_High_Pot=PIN_A1;
const int DL_2_Low_Pot=A2;
const int DL_2_High_Pot=A3;
const int stopLight_Pot=A6;

//***********************************************************************

//SET INTERNAL TAGS AND VALUES
float duration, distance;
int stopSetPoint = 0; //stop light on less than this distance
int driveLight_2_LOW = 0; //drive light 2 on greater than this distance
int driveLight_2_HIGH = 0; //drive light 2 on less than this distance
int driveLight_1_LOW = 0; //drive light 1 on greater than this distance
int driveLight_1_HIGH = 0; //drive light 1 on less than this distance
int driveLight_1_lowValue = 0; //placeholder value for analog input
int driveLight_1_highValue = 0; //placeholder value for analog input
int driveLight_2_lowValue = 0; //placeholder value for analog input
int driveLight_2_highValue = 0; //placeholder value for analog input
int stopLight_Value = 0; //placeholder value for analog input

//***********************************************************************

//LCD SETUP
#define OLED_RESET  15  // Pin 15 -RESET digital signal
ArducamSSD1306 display(OLED_RESET); // FOR I2C

//***********************************************************************

//FUNTIONS SETUP
void callUltraSonic(int num);
void callStopLight(int num);
void calldriveLight_1(int num);
void calldriveLight_2(int num);
void call_analogValueScans(int num);
void call_OLED_Print(int num);
  

//***********************************************************************

void setup() {
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(stopLight, OUTPUT);
  pinMode(driveLight_1, OUTPUT);
  pinMode(driveLight_2, OUTPUT);

  // initialize OLED with I2C addr 0x3C
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  Wire.begin();

}
//***********************************************************************
void loop() {
callUltraSonic(1);
callStopLight(2);
calldriveLight_1(3);
calldriveLight_2(4);
call_analogValueScans(5);
call_OLED_Print(6);
}

//***********************************************************************
void callUltraSonic(int num) {
 // Write a pulse to the HC-SR04 Trigger Pin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Measure the response from the HC-SR04 Echo Pin
  duration = pulseIn(echoPin, HIGH);
  // Determine distance from duration
  // Use 343 metres per second as speed of sound
  distance = (duration / 2) * 0.0343;
  // Serial Print "out of range"
  Serial.print("Distance = ");
  if (distance >= 400 || distance <= 2){
      Serial.println("Out of range");
      }
// Serial Print "distance in cm"
  else {
    Serial.print(distance);
    Serial.println(" cm");
    delay(100);
    } 
}
//***********************************************************************
void callStopLight(int num) {
//Serial Print "STOP"
//Turn stop light on HIGH if less than setpoint
//Else turn stop light off LOW
  if (distance < stopSetPoint){
    digitalWrite(stopLight, HIGH);
    Serial.print(" STOP ");
    } 
    else {
      digitalWrite(stopLight, LOW);
    }
}
//***********************************************************************
void calldriveLight_1(int num){
  if (distance > driveLight_1_LOW && distance < driveLight_1_HIGH) {
      digitalWrite(driveLight_1, HIGH);
  }
  else {
    digitalWrite(driveLight_1, LOW);
  }
}
//***********************************************************************
void calldriveLight_2(int num){
  if (distance > driveLight_2_LOW && distance < driveLight_2_HIGH) {
      digitalWrite(driveLight_2, HIGH);
  }
  else {
    digitalWrite(driveLight_2, LOW);
  }
}
//***********************************************************************
void call_analogValueScans(int num){
  //*******
  //DRIVE LIGHT 1 LOW VALUE FROM POT
  driveLight_1_lowValue = analogRead(DL_1_Low_Pot);
  driveLight_1_LOW = map(driveLight_1_lowValue, 0, 1023, 0, 255);
  Serial.print("DL1Low = ");
  Serial.print(driveLight_1_LOW);
  //*******
  //DRIVE LIGHT 1 HIGH VALUE FROM POT
  driveLight_1_highValue = analogRead(DL_1_High_Pot);
  driveLight_1_HIGH = map(driveLight_1_highValue, 0, 1023, 0, 255);
  Serial.print("DL1High = ");
  Serial.print(driveLight_1_HIGH);
  //******
  //DRIVE LIGHT 2 LOW VALUE FROM POT
  driveLight_2_lowValue = analogRead(DL_2_Low_Pot);
  driveLight_2_LOW = map(driveLight_2_lowValue, 0, 1023, 0, 255);
  Serial.print("DL2Low = ");
  Serial.print(driveLight_2_LOW);
  //******
  //DRIVE LIGHT 2 HIGH VALUE FROM POT
  driveLight_2_highValue = analogRead(DL_2_High_Pot);
  driveLight_2_HIGH = map(driveLight_2_highValue, 0, 1023, 0, 255);
  Serial.print("DL2High = ");
  Serial.print(driveLight_2_HIGH);
  //******
  //STOP LIGHT VALUE FROM POT
  stopLight_Value = analogRead(stopLight_Pot);
  stopSetPoint = map(stopLight_Value, 0, 1023, 0, 255);
  Serial.print("StopLight = ");
  Serial.print(stopSetPoint);
}
//***********************************************************************
//OLED DISPLAY
void call_OLED_Print(int num){

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  //Drive Light 1 Low/High 
    display.setCursor(0,3);
  display.print("DL1L = ");
  display.print(driveLight_1_LOW);
    display.setCursor(67,3);
  display.print("DL1H = ");
  display.print(driveLight_1_HIGH);
  //Drive Light 2 Low/High
    display.setCursor(0,20);
  display.print("DL2L = ");
  display.print(driveLight_2_LOW);
    display.setCursor(67,20);
  display.print("DL2H = ");
  display.print(driveLight_2_HIGH);
  //Stop Setpoint
    display.setCursor(0,40);
  display.print("STOP = ");
  display.print(stopSetPoint);
  display.display();
  //Live Sensor Read
    display.setCursor(0,50);
  display.print("LIVE = ");
  display.print(distance);
  display.display();
}

Thanks for using code tags. There are some minor problems with your post. It's in the wrong sub forum, this is for IDE issues. You have a likely hardware problem but didn't give significant hardware details or wiring diagram. No mention of which Arduino you are using...

A thought. Did you write any simple test sketches that only utilize the faulty pin? Did you try reading it in digital mode?

Is this some new notation?

It could be defined in one of the libraries... not likely though...

I dumped a blank program in and the pin cleared. I should write up a little program just for a single analog input and see if it’s isolated to that pin.

I’m using a nano every.

I did look through the categories and this one said troubleshooting, so I plopped it here.

I am using Platform IO IDE.

Please do that. Also click on the flag icon and request that a moderator move your post. If it fails, please post a wiring diagram and clear, complete photos of your setup.

Please use complete sentences so we can be sure which question you are answering.

... the IDE.

Oh I see. Replying to a post doesn’t show exactly what you’re replying too. Got it.

It's because, if the pin nomenclature is supplied by PlatformIO, sure that is what you mean by the original and the edited post. But unless you already know that via some familiarity with PlatformIO, you might easily thing you were just supplying context. Fleshing out your replies with more specificity will definitely be helpful to us, it always is. For example, you could say,

"PlatformIO uses those pin designations" or something like that. See?

1 Like

PIN_A1 is somewhat likely to NOT be the same as A1 ((PORT, bit 1)=, vs Arduino Analog 1)
I'm not sure about that "PIN5" notation, either. Normally you'd just say "5"

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.