Linear potentiometer changing values without me even touching it

Hi! Im SomeOriginalName! A 13 year old nerd that is just starting out with Arduino. I have a big problem! My linear potentiometer is changing values without me even touching it and it does not rect when i move it... :frowning: If Anyone can help me i would be insanely thankful!

My Code:

const int analogInPin = A0;  
const int analogOutPin = 9; 

int sensorValue = 0;        
int outputValue = 0;     

void setup() {
  pinMode(analogInPin, INPUT);
  Serial.begin(9600);
}

void loop() {

  sensorValue = analogRead(analogInPin);

  outputValue = map(sensorValue, 0, 1023, 0, 255);

  analogWrite(analogOutPin, outputValue);

 
  Serial.print("sensor = ");
  Serial.print(sensorValue);
  Serial.print("\t output = ");
  Serial.println(outputValue);

  delay(500);
}

Here is the video where you can see the problem: YOUTUBE

Thank you! :slight_smile:

Hi, You need to pinMode your OUTPUT PIN!

See: analogWrite() - Arduino Reference

Arduino pins Default to INPUT but OUTPUT must be set with pinMode..