only 1.5V out of 5V pin when powering through Vin?

Hi there, i’m working on my first project but ran into an issue.

Material in issue:
Arduino NANO
L298N dual H-bridge
my logic

when supplying 8.26V to the Vin pin of the NANO, i expected it to go through the 5V regulator and power the IC while also supplying voltage through the 5V pin. for some reason i only get 1.5V out of the 5V pin and can’t wrap my head around the reason behind it.

I hope the attached images and code are enough, thank you for your time.
see code below:

//sensor connections
#define ldr_LEFT 0
#define ldr_RIGHT 1
#define led_Warning 5 //this led blinks if both ldr's are 'activated'

//motor connections (L298N)
#define enA 9
#define in1 8
#define in2 7

int fadeLeft = 5;
int fadeRight = 5;

boolean goingLeft = false;
boolean goingRight = false;

void setup() {
  Serial.begin(9600);
  pinMode(led_Warning, OUTPUT);

  // Set all the motor control pins to outputs
  pinMode(enA, OUTPUT);
  pinMode(in1, OUTPUT);
  pinMode(in2, OUTPUT);

  // Turn off motors - Initial state
  digitalWrite(in1, LOW);
  digitalWrite(in2, LOW);
  delay(1000);
}

void loop() {
  directionControl(); //handles direction booleans & warning led
  speedControlLeft();
  speedControlRight();
}

void directionControl() {
  int val_LEFT = analogRead(ldr_LEFT);
  int val_RIGHT = analogRead(ldr_RIGHT);

  if (val_LEFT < 500 && val_RIGHT < 500) {
    goingLeft = false;
    goingRight = false;
    Serial.print("never tickle both armpits\n");
    digitalWrite(led_Warning, HIGH);
    delay(200);
    digitalWrite(led_Warning, LOW);
    delay(200);
    digitalWrite(led_Warning, HIGH);
    delay(200);
    digitalWrite(led_Warning, LOW);
    delay(200);
    digitalWrite(led_Warning, HIGH);
    delay(200);
    digitalWrite(led_Warning, LOW);
    delay(100);
  }

  if (val_LEFT < 500) {
    Serial.print("LEFT LEFT LEFT\t");
    goingLeft = true;
  }
  if (val_RIGHT < 500) {
    Serial.print("RIGHT RIGHT RIGHT\n");
    goingRight = true;
  }
  if (val_LEFT > 600) {
    Serial.print("STOP LEFT\t");
    goingLeft = false;
  }
  if (val_RIGHT > 600) {
    Serial.print("STOP RIGHT\n");
    goingRight = false;
  }
}

void speedControlLeft() {
  if (goingLeft = true) {
    digitalWrite(in1, HIGH);
    digitalWrite(in2, LOW);

    //slowly build up speed
    if (fadeLeft < 255) {
      if (fadeLeft >= 245) {
        fadeLeft = 255;
      }
      else {
        fadeLeft++;
      }
      analogWrite(enA, fadeLeft);
      delay(20);
    }
  }
  //if hand is moved away, initiate braking:
  if (goingLeft = false) {
    fadeLeft = 5;
    // Turn off motors
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    delay(20);
  }
}

void speedControlRight() {
  if (goingRight = true) {
    digitalWrite(in1, LOW);
    digitalWrite(in2, HIGH);

    //slowly build up speed
    if (fadeRight < 255) {
      if (fadeRight >= 245) {
        fadeRight = 255;
      }
      else {
        fadeRight++;
      }
      analogWrite(enA, fadeRight);
      delay(20);
    }
  }
  //if hand is moved away, initiate braking:
  if (goingRight = false) {
    fadeRight = 5;
    // Turn off motors
    digitalWrite(in1, LOW);
    digitalWrite(in2, LOW);
    delay(20);
  }
}

You never use a voltage divider to supply any power for anything. As you draw extra current through the top resistor the voltage at the centre drops.

If you measured your "12V" or your "8.26V" you did it with nothing connected. If you try again when everything is connected you'll find they are nowhere near what you're expecting.

Steve

|500x318

Hi, Ops pic; |500x318 Using R3 and R4 potential divider as a power supply source is not the way to do it. Using R1 and R2 potential divider as a 12V power supply is also not the way to do it.

It looks like you are being over cautious about your supplies.

[u]Forget the R1 and R2, 12.38V will not damage your L298 circuit.[/u] [u]If you use a 5V regulator on the 12.38V line you can supply 5V directly to the 5V pin of the Nano.[/u]

Potential dividers will not supply a constant regulated voltage in the circuit you have.

Thanks.. Tom... :)

slipstick:
If you measured your “12V” or your “8.26V” you did it with nothing connected. If you try again when everything is connected you’ll find they are nowhere near what you’re expecting.

this is exactly what was happening, thank you for your explanation Steve!

TomGeorge:
It looks like you are being over cautious about your supplies.

Forget the R1 and R2, 12.38V will not damage your L298 circuit.
If you use a 5V regulator on the 12.38V line you can supply 5V directly to the 5V pin of the Nano.

i was indeed afraid that i’d create magic smoke/blow up the house and what not hehe… thanks for the help Tom i’ll change the layout!

And while you may get away with it if the only thing of note connected to your Nano is a couple of LDRs and the inputs of a L298, it is generally a very bad idea to power an Arduino (UNO, Nano, Mega, Pro Mini, Leonardo, Pro Micro ...) via "Vin" or the "barrel jack" as the on-board regulator, lacking a significant heat sink, is not capable of providing much current without overheating and (hopefully temporarily) shutting down. :astonished: