Skip to main content
Tweeted twitter.com/StackArduino/status/1370570546111512580
Copy edited (e.g. ref. <https://en.wikipedia.org/wiki/Arduino> and <https://www.elegoo.com/products/elegoo-uno-project-super-starter-kit>). Removed meta information (this belongs in comments).
Source Link

Why am I receiving random input values in my arduinoArduino?

This is definitely the noobiest question I've ever asked, but I'm really struggling. All I want to do is use a switch for my arduinoArduino using digitalRead(), but I keep receiving random inputs. Whenever I connect energy to that pin, it always returns HIGH, but otherwise it goes completely random. I

I have tried using a resistor for the input pin, but that didn't seem to help. II am using an elegoo unoElegoo UNO, and the input pin I am using is pin 2. Here's my code in case you need it:

const int switchPin = 3;

void setup() {
  // put your setup code here, to run once:
  pinMode(switchPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(switchPin) == HIGH){
    Serial.println("on");
  }

  else{
    Serial.println("off");
  }
}

Why am I receiving random input values in my arduino?

This is definitely the noobiest question I've ever asked, but I'm really struggling. All I want to do is use a switch for my arduino using digitalRead(), but I keep receiving random inputs. Whenever I connect energy to that pin, it always returns HIGH, but otherwise it goes completely random. I have tried using a resistor for the input pin, but that didn't seem to help. I am using an elegoo uno, and the input pin I am using is pin 2. Here's my code in case you need it:

const int switchPin = 3;

void setup() {
  // put your setup code here, to run once:
  pinMode(switchPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(switchPin) == HIGH){
    Serial.println("on");
  }

  else{
    Serial.println("off");
  }
}

Why am I receiving random input values in my Arduino?

I want to use a switch for my Arduino using digitalRead(), but I keep receiving random inputs. Whenever I connect energy to that pin, it always returns HIGH, but otherwise it goes completely random.

I have tried using a resistor for the input pin, but that didn't seem to help. I am using an Elegoo UNO, and the input pin I am using is pin 2. Here's my code in case you need it:

const int switchPin = 3;

void setup() {
  // put your setup code here, to run once:
  pinMode(switchPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(switchPin) == HIGH){
    Serial.println("on");
  }

  else{
    Serial.println("off");
  }
}
Became Hot Network Question
Source Link

Why am I receiving random input values in my arduino?

This is definitely the noobiest question I've ever asked, but I'm really struggling. All I want to do is use a switch for my arduino using digitalRead(), but I keep receiving random inputs. Whenever I connect energy to that pin, it always returns HIGH, but otherwise it goes completely random. I have tried using a resistor for the input pin, but that didn't seem to help. I am using an elegoo uno, and the input pin I am using is pin 2. Here's my code in case you need it:

const int switchPin = 3;

void setup() {
  // put your setup code here, to run once:
  pinMode(switchPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  if (digitalRead(switchPin) == HIGH){
    Serial.println("on");
  }

  else{
    Serial.println("off");
  }
}