Noob question involving circuits and voltage?

I've got the arduino beginner project book and I'm reviewing it in preparation for a project that I'd like to do.

It's a small program that does some digital read/digital write to light some lights when a button is pressed.

The strange (to me) thing is that the circuit behaves differently when connected to the Arduino (5v) PWR/GND versus a 9v PWR/GND

I suspect this is because of the difference between 9v and 5v and so I'd need to switch out the resistors, but I'm so newb at electronics that I don't understand what kind of change to make.

Here's the project code:

int switchState = 0;

void setup() {
  pinMode(3, OUTPUT);
  pinMode(4, OUTPUT);
  pinMode(5, OUTPUT);
  pinMode(2, INPUT);
  Serial.begin(115200);
  Serial.println("Hello!");
}

void loop() {
  // put your main code here, to run repeatedly:
  switchState = digitalRead(2);

  if(switchState == LOW) {
    //switch is not pressed
    digitalWrite(3, HIGH);
    digitalWrite(4, LOW);
    digitalWrite(5, LOW);
  } else {
    digitalWrite(3, LOW);
    digitalWrite(4, LOW);
    digitalWrite(5, HIGH);

    delay(250);
    digitalWrite(4, HIGH);
    digitalWrite(5, LOW);
    delay(250);
  }
}

video of project when connected to 9V:
9V google drive link

EDIT:
Circuit diagram from the project

In the version that works differently, the only thing that is different is that PWR/GND are connected to a 9V battery instead of the 5V Arduino

Please show an exact circuit diagram.

What do you mean by 'differently? Describe the behaviour. Describe what should happen and what does. Show us a schematic of your circuit, hand drawn and photographed is fine.

What are you connecting where? 9V should go to Vin or the barrel jack, 5V to the 5V pin.

Neither of your videos will play on my PC. However, in the preview before I try to play them, both your Unos appear to be powered from the USB port, so 5V.

I took videos to try to show the difference in behavior. I'm stymied by the restrictions on what I can put in a post as a new member (only 2 links, no pic uploads). Here's a link to the behavior that represents "working". The diagram and the "broken" behavior are in the post itself.

unfortunate- and yes, it does kind of look that way, but the broken behavior is definitely attached to 9V, I could have moved the wires out of the way better

Please post a description of your observations

Please, just describe it, forget the videos, they won't play on my PC.

Please post here.

@TheMemberFormerlyKnownAsAWOL @PerryBebbington

Observations:

Attached to 5V Arduino:

  • Unpressed button == green light on, red lights off
  • Pressed button == green light off, red lights blinking back and forth

Attached to 9V:

  • Unpressed button == no lights on
  • Pressed button == green light on, red lights blinking back and forth

I still do not know to what the 9V is attached. And what is the source of 9V? The ONLY place to attach 9V is the Vin pin or barrel jack, period. Any other place is likely to cause damage. If not right away eventually.

Based on the limited information, you are powering the Uno from 5V from the USB port. Nothing I have seen suggests you are powering it from 9V, certainly not the photo of the page of the book. We want to know how YOU wired it, not what it says in the book. Some photos posted here please and a schematic you have drawn (well, 2, one for 5V, one for 9V)

both the Arduino 5V and the battery 9V are attached in the same location, the top left of the breadboard. That's the only difference between the two setups.

I wired it the same, the only difference is that in the broken example PWR and GND are coming from a battery instead of the Arduino

Then you have connected 9V to where 5V should go and you might have damaged the Uno.

If you connected 9V where you say you have not followed the instruction in the book, no where on that page does it show 9V connected anywhere.

Post an image of the 5V connection and the 9V connection.

Definitely true- I am/was hoping to find some way for my UNO to detect a switch in a circuit NOT powered by the UNO.

Beginner question

As I understand it, Voltage is the measurement of current between two points in a circuit.

Somewhat contradictorily (in my mind) the digital read on Arduino takes information from a single point in a circuit.

How can a single point in a circuit be said to have any voltage?

...with respect to ground (aka 0V)

1 Like

The digitalRead() values are WRT the Arduino system "ground" point.
You can't reliable read a value if there isn't a common ground.

common grounds are more common than you might think. If you have two Arduinos plugged into the USB port of your computer, they'll share a ground that goes through the USB ports and the computer...

1 Like

Actually it measures the potential difference between two points in a circuit. The current is measured in amps (or milliamps, usually).