0

enter image description here

I have made circuit where you can see that it is reading some signal from a button.

I've found in Arduino tutorials that there should be a pull-down resistor, which I don't really understand well.

I've read tons of articles on the subject of open-drain/collector and haven't got the idea. This is why I don't understand what happens in this circuit. Maybe someone can explain me entire process.

When I measure voltage on the wire which goes to pin 12, I see 0V. When I read the voltage on the resistor (10 kiloohm,) I see almost 5V. How does pin 12 understand that I pass it a high if there no voltage going to pin 12?

const int buttonInputPin = 12;
const int ledPin =  13;

void setup() {
  pinMode(buttonInputPin, INPUT);
  pinMode(13, OUTPUT);
  Serial.begin(9600);
}

void loop() {
  int buttonState = digitalRead(buttonInputPin);
  
  Serial.println(buttonState);

  if (buttonState == HIGH) {
    digitalWrite(ledPin, HIGH);
  }else {
    digitalWrite(ledPin, LOW);
  }
}

I am using an Arduino Uno (ATMEGA 328PB.)

JRE
  • 67,678
  • 8
  • 104
  • 179
  • 1
    Please show a schematic. – Andy aka Mar 30 '23 at 14:23
  • @Andyaka I connect to + on the breadboard 5v source from arduino and same connect GND to - , then white wire from 1 leg of button goes to +5v from other leg on bottom part goes resistor 10kOM and from leg of this resistor it goes to GND , and on the top you see white wire which goes from second leg to 12 pin, you can find also scheme here https://docs.arduino.cc/static/73702ee121860fa04c7f6db5bc77183b/29114/circuit.png – Andrey Radkevich Mar 30 '23 at 14:32
  • 1
    That is not a schematic and neither is the linked cartoon. – Andy aka Mar 30 '23 at 14:35
  • schematic to what ? i new to this , and just want to investigate on it , maybe you can help me ? if not then I don't know what else should I provide – Andrey Radkevich Mar 30 '23 at 14:42
  • @AndreyRadkevich: Does the circuit work properly? (Does the LED light up when you press the button?) – JRE Mar 30 '23 at 14:53
  • yes, It is lighting up when resistor is in circuit (pull down ), but when I remove it and just connect button to ground without this resistor (10 kOm) , seems like short circuit happens when I press button , or something strange , it seems like reset system , it doesn't work without this resistor , also thing which I don't understand why , big current ? but can it generate big current from arduin +5v source ? – Andrey Radkevich Mar 30 '23 at 14:56
  • Welcome on EE.SE. FYI this is not a site *aimed* at total newbies in electronics. Although newbies are welcome, we require that people asking questions here have at least a glimpse of the basics. You saying you don't know what a schematic is, is like going on Stack Overflow and asking a question about a , say, Python program without knowing even the basic syntax of Python. Or maybe worse: without knowing how a piece of code looks like. – LorenzoDonati4Ukraine-OnStrike Mar 30 '23 at 15:13
  • An electronics circuit's schematic diagram, or simply "schematic" or "circuit diagram", is a codified graphical language used in EE field to describe precisely what components are in the circuit and how they are connected. The Internet is full of resources for newbies that describe what are schematics and how to read them and how to draw them correctly and neatly. – LorenzoDonati4Ukraine-OnStrike Mar 30 '23 at 15:14
  • After you learn the very basics you may want to review [this classical thread](https://electronics.stackexchange.com/questions/28251/rules-and-guidelines-for-drawing-good-schematics) that will further help you draw good schematics. – LorenzoDonati4Ukraine-OnStrike Mar 30 '23 at 15:16
  • "How does pin 12 understand that I pass it a high if there no voltage going to pin 12?" - It doesn't. It goes to 5V when you press the button and then it's high. When you don't press the button it gets 0V and that's low. – user253751 Mar 30 '23 at 15:20
  • @LorenzoDonatisupportUkraine read what I've written pls , it isn't that I don't understand what schematic is , I didn't get which one I have to provide , but thanks for your comment , link you attached will be useful will read it – Andrey Radkevich Mar 30 '23 at 15:33
  • @AndreyRadkevich The schematic representing your circuit that you mounted on the breadboard and the connection to the Arduino board. Sorry, but you seem you didn't do any research whatsoever on this site on similar questions and tried to understand what is required for a good question here. We definitely frown upon a breadboard setup without an accompanying schematic. – LorenzoDonati4Ukraine-OnStrike Mar 30 '23 at 19:41

2 Answers2

3

From the ATMEGA328P datasheet:

ATMEGA328P GPIO Diagram

The GPIO (General Purpose Input Output) pins are connected to internal circuitry which can pull up the pin through a resistor and PFET, or pull down the pin to ground using an NFET. In the diagram, when the pin is configured as an input, the 'RPx' signal enables the output of the flip-flops to be read by the microcontroller, as the flip-flops latch the input value upon a clock trigger. The important part here is the NFET, which may be the reason why you are reading a 0V on the pin (as the NFET is turning on, and your meter is averaging the voltage to zero) while the MCU can still read a proper input voltage.

md-raz
  • 50
  • 9
3

I'm going to draw a couple of schematic diagrams illustrating what you've explained in the comments. Schematics make the function clearer than the wiring diagrams you've been using.

Original circuit:

schematic

simulate this circuit – Schematic created using CircuitLab

When the button is open (not pressed,) the resistor connects the GPIO pin to ground - this is a pull down. The Arduino "sees" 0V - this is a "low."

When you push the button, the 5V from the Arduino is connected to the GPIO pin. The Arduino "sees" 5V - this is a high.

Try it with your voltmeter - you should get the voltage readings as I've described them. Connect the red lead to the GPIO pin and the black lead to ground.

Resistor replaced with a short:

schematic

simulate this circuit

Here I've taken out the 10k resistor and replaced it with a wire, like you described in the comments.

The "low" is the same as before. When the button is up (not pressed,) the GPIO pin is connected to ground (0V) and the Arduino registers a low.

If you press the button, you will connect the Arduino's 5V power supply to ground through a wire. This is known as a short circuit. The Arduino cannot function when its power supply is shorted. The LED will never light when you do this.

If you use your voltmeter on this modified circuit, then you will see that the GPIO pin never changes - it is always at 0V.

The 5V regulator on the Arduino can supply several hundred milliamperes of current. That's not really a lot, but probably more than the pushbutton is designed for. If you keep short circuiting the 5V supply through the pushbutton, then you will destroy it.

The 5V regulator should have built in protection against a short circuit, so it shouldn't be damaged.

There's always the chance, though, that the regulator will be damaged despite the protection.

Stop short circuiting the 5V output of the Arduino.

JRE
  • 67,678
  • 8
  • 104
  • 179