Vin pin of ATmega328

Hello everyone I am building a project and i am very confused about the usage of Vin pin. In arduino board what's the role of Vin pin and which pin of ATmega328p IC is corresponding to it?

Vin does not go to the atmega328 directly. It is the rail that supplies an on-board regulator, which outputs the desired operating voltage (usially 5 or 3.3v) allowing the board to be powered with a voltage higher than that. (The barrel jack on the uno is connected to it by a diode to protect against reverse polarity on the barrel jack).

DrAzzy:
Vin does not go to the atmega328 directly. It is the rail that supplies an on-board regulator, which outputs the desired operating voltage (usially 5 or 3.3v) allowing the board to be powered with a voltage higher than that. (The barrel jack on the uno is connected to it by a diode to protect against reverse polarity on the barrel jack).

I have build a drone and I am powering the uno with a 3s Lipo battery through Vin pin. I decided to make my own pcb using the ATmega328p IC instead of uno board. I have just connected the battery through a 5v voltage regulator to power the IC but the motors seems not to working. In my original project using uno I am connecting the battery through Vin pin and everything works perfect. I am guessing that this is my problem.

And what are the motors themselves powered from? Is this the same in both cases?

Did you remember the two 0.1uF decoupling caps (one between Vcc and Gnd, one between AVcc and Gnd, right next to the '328p)? These are required for stable operation (though chips often sort-of-work without them, but are much more sensitive to sudden changes in load, such as from turning on and off a large load, like a motor, and can hang or reset themselves in that situation).

Are the required input and output caps on the regulator present? Without them, the regulator will not produce regulated output voltage, with particularly poor transient response, and may oscillate depending on the operating conditions.

Have you verified that the sketch is running successfully, and it's just the motors not working?

DrAzzy:
And what are the motors themselves powered from? Is this the same in both cases?

Did you remember the two 0.1uF decoupling caps (one between Vcc and Gnd, one between AVcc and Gnd, right next to the '328p)? These are required for stable operation (though chips often sort-of-work without them, but are much more sensitive to sudden changes in load, such as from turning on and off a large load, like a motor, and can hang or reset themselves in that situation).

Are the required input and output caps on the regulator present? Without them, the regulator will not produce regulated output voltage, with particularly poor transient response, and may oscillate depending on the operating conditions.

Have you verified that the sketch is running successfully, and it's just the motors not working?

I have took the Atmega328p IC from the uno where the drone works and I have replaced the uno with that schematic:

P.S. That's the schematic of drone:

The battery should be connected to Vin pin but I didnt know which pin is in the ATmega328p so I just connected it before the 5V regulator.

  1. You are missing the two 0.1uF caps I mentioned above.

  2. You are missing the 10k resistor to Vcc on reset.

  3. Are those loading caps on the crystal the right value? Should be 18~22pf, but on breadboard, sometimes you need to use lower value loading caps, or remove them entirely (depending on how much parasitic capacitance the breadboard has).

  4. Do you know whether your sketch is running at all? Put an LED on some pin and blink it, so you can see that your sketch is at least running (and diagnose, say, a problem with the crystal not oscillating, which would cause the chip to do nothing.

  5. I assume the connection to the input voltage (which isn't shown on that board) is present, and the negative side of the battery voltage is tied to ground?

  6. The other side of the reset switch should be tied to ground directly, not via a resistor.

  7. AVcc and Vcc should be connected to 5v. AREF should NOT!

From your breadboard picture above:

Add the two decoupling caps like DrAzzy suggested and remove the connection from AREF (pin 20) to the +ve buss. You can add a 0.1uF cap from AREF to ground.

I do not think you have the reset button wired correctly. The pull-up goes to ground - it should go to +ve. Check the switch orientation and make sure you are not holding the reset (pin 1) at ground level.

I did not check the power supply wiring but you have two floating leads going to the left. Did you check that you have the correct voltage on the power pins?

Willem.

Edit: DrAzzy posted while I was typing - I am a bit slow.

DrAzzy:

  1. You are missing the two 0.1uF caps I mentioned above.

  2. You are missing the 10k resistor to Vcc on reset.

  3. Are those loading caps on the crystal the right value? Should be 18~22pf, but on breadboard, sometimes you need to use lower value loading caps, or remove them entirely (depending on how much parasitic capacitance the breadboard has).

  4. Do you know whether your sketch is running at all? Put an LED on some pin and blink it, so you can see that your sketch is at least running (and diagnose, say, a problem with the crystal not oscillating, which would cause the chip to do nothing.

  5. I assume the connection to the input voltage (which isn't shown on that board) is present, and the negative side of the battery voltage is tied to ground?

  6. The other side of the reset switch should be tied to ground directly, not via a resistor.

  7. AVcc and Vcc should be connected to 5v. AREF should NOT!

  1. I didn't understand exactly how to place the 0.1uf caps. Can you please provide me a schematic?

2.6. Should I connect one side of the reset switch to Vcc via a 10k resistor and to reset pin(pin 1 of ATmega), and the other directly to Gnd? Did I understand correctly?

  1. I am using two 22pf for the crystal according to the schematic. I am not using a breadboard I am soldering everything in pcb.

  2. Yes I am pretty sure that the sketch is running but i have a hesitation that I should connect resistors through SDA, SCL of mpu-6050 because the code will not leave setup routine if not the gyro found. If i must connect resistors what value should I use? 4.7K?

  3. I can't understand clearly what you are saying there . :frowning:

  4. Yes you are right. In another post one sir told me that I should disconnect Aref from Vcc and AVcc and connect it to Gnd through a 0.1uf cap. I did it and still not works.

I really want to thank you for your interest, help and time!

Don't have access to way to draw atm (posting from phone). One side of cap to Gnd, other side to Vcc. On other side, a second cap, one site to gnd, other side to AVcc. Those caps should be ceramic caps, and located right next to the chip.

2,6 - Correct.

  1. Okay, that ought to work.

  2. Don't be "pretty sure" - be totally sure! Verify this.

  3. 4.7k pullup resistor (from SCL to Vcc and Gnd to Vcc) is appropriate; the exact value isn't critical - most of those modules have a pair of 10k ones on them already, so I'm surprised you find that you need them, especially when you previously didn't.

  4. Your diagram above did not show any connection between the positive side of the battery and the input terminal of the regulator. You also didn't show any connection between the negative side of the battery and ground. Both of these are of course required.

  1. The circuit diagram for the model GY-521 gyro board shows built in 4.7k pull-up resistors for SDA and SCL. You should not add any in that case. As DrAzzy said, if it was working before without them it should now. Check your gyro circuit.

  2. AVCC must be connected to +5V else ADC does not work. AREF must not be connected to 5V, the cap to ground is optional (just for noise decoupling)

Check the RESET pin is measuring 5V with the 10k pull-up added. A common problem is the pushbutton orientation causing the reset pin to be permanently grounded.

Willem.

Wow I am just impressed. I just connected the reset button as you said and everything works!
So that schematic with the barebone arduino is completelly wrong? It's from a paid course, it's impossible.
Can you please explain me why the Aref pin should not be connected to power and where it should? Furthermore I didn't connected the two caps from Vcc and AVcc to Gnd(I don't know but this sounds to me so wrong to connect Gnd with power).Is it necessary to connect the 2 caps, what's their job?

The capacitor is not "connecting power and ground" - if current is flowing through a capacitor, you need to replace it with a working capacitor :wink:

You already have a cap between power and ground, in two places - on the input and output of the regulator!

The purpose of the 0.1uF ceramic capacitor between power and ground right next to every power pin is for "decoupling". The current that a digital IC will draw can change almost instantly from near zero to tens or hundreds of mA (if, say, you wake from sleep and then switch on a bunch of pins each connected to a ~20mA load) almost instantly. This can cause the voltage at the power pins to drop - potentially enough to glitch the chip - because the trace or wire supplying power to the chip has non-zero inductance, hence the current doesn't change instantly in response to the load suddenly trying to draw more power. This parasitic inductance is usually very low, but it's not nothing - and it's enough that the '328p can reset or hang due to that brief drop in the supply voltage. The decoupling cap will supply power during this brief moment. Basically all digital IC's need one, and 0.1uF is the usual default value to use (sometimes the manufacturer will specify something else). Without it - sometimes it works, other times it may hang or reset unexpectedly. I once made a board where I put it too far away (it was physically close, but I forgot to put a closer connection to the trace, so the actual path was much longer) and when I tried to program via ICSP, it would write one page, then reset itself when it tried to commit the page; threw out the dozen copies of the board I got and that's why I make a point of telling people about this when I see people not doing it.

There are a LOT of tutorials that don't include them (probably because they threw something together and it worked for a simple test and they were like "okay, I'm done here, it's all good" - without reading the datasheet or really putting the device they made through it's paces. FFS, the official arduino Arduino-to-Breadboard guide omits them, despite many people pointing it out over the years (it's almost as if they have a vested interest in people's breadboard arduino being unreliable, like they were selling their own boards or something).

The 5v rail should be connected to AREF when, and only when, you want to be able to burn out the analog reference by calling analogReference(). Otherwise, AREF should only be connected to a 0.1uF cap, with the other side connected to ground (this isn't even necessary if you're not using the ADC, or if you're not particularly concerned about ADC noise)

Those are the top two mistakes I see in arduino wiring diagrams; for me, they are a red flag that the source of said diagram doesn't know what they're doing, and may be giving other incorrect advice.

akiskaps:

  1. I didn't understand exactly how to place the 0.1uf caps. Can you please provide me a schematic?

You probably have already gotten it figured out, but in case it might help someone else who has the same question and finds this thread, here's a picture of a breadboard setup with the decoupling capacitors right next to the chip, as they should be: