I struggle with electronic concepts - help!

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

The concept to Google is "floating input'

1 Like

Normally the switch is connected between the input pin and ground without a resistor. You would change INPUT to INPUT_PULLUP as the needed resistors are built in. Your code you would become:
if (digitalRead(Switch1) == LOW)

A floating input will read both HIGH and LOW depending on its mood and will change rapidly and randomly.

1 Like

This is not what you have in your circuit. Pin2 is connected to two places in your circuit. One place is a resistor that is connected to ground. The other place is to a switch that can be either connected to nothing or to 5V depending on the state of the switch.

So when the switch connects pin 2 to nothing, and you read Pin2 with a digital read it will then return a LOW state. On the other hand if the switch connects Pin 2 to 5V then the pin will read as HIGH.

The reason is that 5V overwhelms the voltage given by a connection to ground through a resistor.

It sounds like you don't know how to read the circuit on a breadboard. The five holes on a horizontal line are all connected together. The outer two verticals outer strips on each side are connected vertical.
The central break has no connection across it, so the five horizontal holes on the left are not connected to the five horizontal holes on the right.

2 Likes

Firstly, thank you to everyone for the astoundingly quick responses. I'd like to say that I'm being overly simplistic, but truthfully, nothing about electronics comes easily to me even though I find it fascinating.

Further to @Grumpy_Mike's comments, behold my absolutely awful circuit diagram. Forget the LED etc. for a moment, but this is how I'm visualizing PIN2 - just a wire coming off the main circuit that terminates at the pin. In my head, everything needs to be a 'complete circuit. The LED part of the diagram makes intrinsic sense to me because you can follow the flow of electricity. Similarly, everything about the switch/resistor/ground circuit makes sense except for the single wire that just connects to an input pin that seemingly doesn't complete a circuit anywhere.

Behold my hand sketched diagram. I really wish I was trolling but this is how much I struggle. Thank you.

I don't understand your question. Can you please rephrase it more clearly? If you mean the green wire, it doesn't connect directly to ground, but the resistor is at ground voltage unless there is current going through it. Then, when the switch is closed, 5V is applied across the resistor and so there is 5V on the green wire.

It terminates at the pin, however on the Arduino board it connects to the processor, which is also connected to 5V and ground. So it's definitely not flying around in space.

To make more sense, you should include the Arduino in that diagram.

Have you studied basic electric circuits at all? If you do, it will become clear very quickly.

I really want to understand what is actually happening from an electronic point of view.

Perhaps this kit is not itself sufficient for the learning you want to do.

Thank you @anon57585045 for your perseverance.

I have tried and will continue, but I'm a terrible learner. Not because I can't learn, but because somewhere between 18 and 40 years of age I became obsessed with getting to the 'source of the spring' and every time I try and learn electronics I end up frustrated in the weeds of electromagnetism etc.

Those are not weeds, they are the spring. It is called Electronics because it's all based on electrons (who would have thought?). It's 100x easier to understand circuits if you do understand the physics. So don't quit on that. All the good schools and training courses start you there.

However, what I was really asking for was a clarification of your question. It's hard to fill in an area of misunderstanding if you don't know where it is.

I suggested theory because focusing on a specific circuit that also embraces digital logic is not approaching it in its simplest form.

Let's start easy - do you "get" Ohm's Law?

Thank you @anon57585045 for your perseverance

I'm only here because my brain can't handle any more MC6801 assembly language programming. :slight_smile:

@anon57585045 that's very kind of you.

I think clarifying my question is 90% of the battle.

To my original issue, when I was doing this exercise, I was thinking "Why do I need to place a resistor in between the connection to input2 and Ground. And then I just kind of overthought the process and I was looking at input 2 and thinking, where exactly does that connect to the main circuit - a wire is connecting to it in between the switch and the resistor, but what is input2 connecting to internally that allows it to form a complete circuit to ground etc.

I understand Ohms law, but in an elementary way - it seems intuitive but if you asked me to explain what is happening at an atomic level I'd end up sounding like someone having a stroke.

It's documented on this site. Go to the UNO product page and hunt around, you can download a schematic that shows exactly what components and connections each pin is connected to on the board.

If that isn't enough, you can download the MCU data sheet, which shows you where the signals go, inside the chip.

1 Like

The circuit is completed by the connection to the Arduino. A digital input is an input that will sense a voltage as being high or low. You have to give it enough voltage to make sure it is recognised as high or low. There is an area of uncertainty in between these voltages where it is not guaranteed to be one or the other.

For a low it must be less that 0.7V, for a high this is 3..8V. This is for a 5V powered Arduino. So pin 2 is not just an arbitrary pin going nowhere, it is going into the Arduino and that is what completes the circuit.

Hi,
This might help;

Tom.. :smiley: :+1: :coffee: :australia:

1 Like

Thank you again for taking the time to respond @Grumpy_Mike It all really helps

Thank you @TomGeorge You're a legend for editing my diagram like that to help. I appreciate it.

Maybe this is simpler to understand. By showing the Arduino in a box you make it be a single thing. So you can see that pin 2 has some connection with the Arduino ground, because it is part of the Arduino.

Thank you @Grumpy_Mike. Really appreciate. it.

I guess I'm now wondering why we need to ground the circuit after the connection to PIN2 because (and correct me if I'm wrong), PIN2 would be grounded anyway (I did look up schematics but couldn't understand them completely).

I'm now wondering why we need to ground the circuit after the connection to PIN2

Several posters have touched on this above, but I'll take the opportunity to elaborate a bit.

The corrected diagrams above showed that PIN2 has some sort of connection to ground, though the Arduino.

In reality, this is not a direct connection, the path winds its way through the complicated internal circuitry of the Arduino.

By design, PIN2 (along with the other inputs), do not allow much current to flow in through the Arduino. Their job is not to let all the electricity flood in through the pin, but rather to "sip" just the bare minimum current required to measure the voltage at the connection point.

There will be a very small amount of electricity flowing through PIN2 to ground, via the Arduino. Consequently there will (ideally) be only a small change in the voltage as a result of the measurement.

Because the INPUT pins tread so lightly, their tiny connection to ground is overwhelmed by the "spooky, mystery, background-noise electric charges" hovering around your Arduino (*not a technical term). This background noise will be coming from all sorts of different sources, but it isn't relevant to try identify it at this point.

An unconnected pin, which would read these phantom signals, is known as a "floating input", as mentioned above. That is to say, the input is "floating" around, rather than connected to a solid voltage source.

To prevent PIN2 floating, at the point it is measuring, you have connected a resistor to ground. This resistor allows a modest amount of current to flow to ground. This is just enough current to prevent any of those spooky mystery voltages accumulating; they will all take the path through the resistor to ground.

When the switch is closed, a large source of 5V is connected to PIN2. A modest amount of this heads directly to ground through the resistor, however the 5V source is large enough that this trickle to ground does not significantly lower the 5 Volts.

This resistor is known as "Pulldown Resistor", because it "pulls the pin down" to ground.

In your schematic I see that your pull down resistor is 220Ω? (Red Red Brown Gold)
This would be an inappropriately low value for a pulldown resistor; it would do the job when the switch is open, but when it is closed it would allow an awful lot of current from the 5V to flow. I wouldn't like to give an exact number, but I would say that pulldown resistors for 5V would usually be roughly 10x to 100x higher.

I should mention that this is only my rough understanding of the topic, so take it all with a grain of salt.

3 Likes

No.
PIN2 is only connected to ground when the push button is not pressed. When it is pressed then PIN2 is connected to 5V.

I am unsure what you are failing to understand.

A schematic is a graphical representation of a circuit, made by many connections between many components. It is an abstract representation with no relationship to where the components are.

Unless you can read, you can't really write. Both for language and electronics.

Amazing @Grumpy_Mike. A lightbulb just went off in my head (very dimly lit though :smiley: )

I had an assumption that PIN2 was grounded through the microcontroller somehow.

Thank you for your patience with my questions.