Hi. I'm new to Arduino and bought the inventr.io kit to learn about arduino/software and electronics. I'm only on the beginner lessons and I can get everything to work but I really want to understand what is actually happening from an electronic point of view.
In the third lesson, we use code to create a flashing LED if the input voltage to Pin 2 is High (i.e. 5V). The breadboard diagram as well as the code. The reference video is here
My question: What does input 2 connect to? I'm struggling to understand how I can have a random wire in the middle of my complete circuit (e.g. with the resistor connecting to ground) that just connects to an input pin, but at the same time, there is nowhere for that part of the circuit to connect to ground? It just seems like a random wire peeling off and connecting to an endpoint.
Bonus dumb-dumb Question: Why is it that if I unplug either end of the Pin 2 connection, the LED just flashes anyway? Surely Pin2 isn't reading "HIGH" if it's getting no input?
Thank you. I feel like an idiot and really need your help.
int LED = 12;
int Switch1 = 2; //pin 2 will be attached to our switch
void setup() {
//setup both an output AND an input on the HERO
pinMode(LED, OUTPUT);
pinMode(Switch1, INPUT);
}
void loop() {
//now within loop() we'll take actions based on the status of the input switch
//this is a conditional test...
if (digitalRead(Switch1) == HIGH){
digitalWrite(LED, LOW);
delay(1000);
digitalWrite(LED, HIGH);
delay(100);
digitalWrite(LED, LOW);
delay(100);
digitalWrite(LED, HIGH);
delay(100);
}
else {
digitalWrite(LED, LOW); // turn LED OFF
}
}
strong text