The analog pins are only analog inputs but digital outputs (and inputs too). You use digitalWrite() to control a pin's HIGH or LOW state.
ànalogWrite() is for use with the PWM pins (I hate the name the chose for that function it's so wrong on so many levels).
Also this powering trick only works for things that need very small currents (< about 20mA) since that is the maximum an IO pin can deliver.
Incidentally, you can use analogWrite() on a non-PWM pin, but it's either fully on (analog value >= 127) or fully off (analog value < 127). The macros HIGH and LOW are 1 and 0 respectively, so that equates to "fully off" and "fully off" on a plain non-PWM pin.
How do analog Pins? How do they measure input and what characteristics do they have?
arduino uno - Using Analog Pins for Power - Arduino Stack Exchange
How do I use the Arduino analog pins as outputs? | UDOO Forum
Analog Output Problems with Analog Pins
So i have been trying to make sense of the the electrical side of the whole arduino thing, but i am not quite getting it. Simple example: I connect the 5V Pin and two 1k Ohm resistors in series and then i put another cable into one of the analog pins. What i can measure is 5V. What i was expecting is atleast a slight drop in voltage, because i learned that over a resistor, the voltage drops. Then i asked ChatGPT and it told me that the analog pins have a very high resistance value. That would mean that almost no voltage would drop over the other two resistors. But if that is the case, i do not understand how ,when i set up a very simple voltage divider with the analog pin connected in the middle and the other end to the ground, the analog pin would not somehow influence the voltage value measured in this scenario. The voltage here splits exactly like expected so that i can measure 2,5V at the analog pin.
Maybe i just have a "knot" in my brain, but i am not able to make sense of it. Would love to hear an explanation from you guys. :)