Need help with Arduino mega

Hello everyone
this is my first post so I don't know much
I have just gotten a new Arduino mega for one of my projects but I realized that the analog inputs are not showing properly so I made a simple test circuit(a pot connected to pin A0 vcc and gnd) and code(just printing the value of A0) but when I run the code all that the analog pins(yes I did try with other pins) read is 0 can anyone tell me what I'm doing wrong?
Also if it helps the microchip on my Arduino warms up more than my uno board

edit:one of the pins of the microcontroller was broken I'm screwed

Looks like something wring either in cables or the code.
A picture (as detailed as possible) of the real project could help much, together with the code (mark it using the "CODE" tags).
Show us both please.

If you connected the pot to the Arduino in the order you listed (A0, VCC, Gnd), that's incorrect. The middle leg (the wiper) goes to A0, the outer legs can be either VCC or Gnd

I haven't connected it in that order
It's
Gnd A0 Vcc

And by VCC you mean the 5V pin, not VIN, right?

Are you using this test sketch? It's the one in the Arduino IDE.

/*
  ReadAnalogVoltage

  Reads an analog input on pin 0, converts it to voltage, and prints the result to the Serial Monitor.
  Graphical representation is available using Serial Plotter (Tools > Serial Plotter menu).
  Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.

  This example code is in the public domain.

  http://www.arduino.cc/en/Tutorial/ReadAnalogVoltage
*/

// the setup routine runs once when you press reset:
void setup() {
  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.println(voltage);
}

While I'm thinking of it, if you're new to Arduino, something I always make sure to do, even with example sketches (I make a copy if necessary and rename it "myExampleSketchName", is to add a Serial.println() that has the name of the sketch in it. It's easy to use the wrong sketch when you're busy thinking of other things like double checking your circuit. I'm forgetful, so I find that it really helps. Plus, how are you to remember a year from now what code revision you had if you want to look at the code again and make changes based on something new you learned about? (That's me - my elaborate builds are almost all Hallowe'en things, so it's a year apart at a time usually before I make new code revisions)

Anyway, to avoid keep wasting our (and your) time, please do what I asked you before:

A picture (as detailed as possible) of the real project could help much, together with the code (mark it using the "CODE" tags).
Show us both please.

1 Like

Void setup() {
Serial.begin(9600);
pinMode(A0,INPUT);
}
Void loop() {
Serial.println(analogRead(A0));
}

Somehow when I run this it just keeps printing 0 and nothing else no mater how much I change the pot value

Ik it have a simple code and circuit it's not my main project and I'm pretty sure it a problem with my Arduino mega but I still want to be sure

Sorry if I'm wasting your time

This is the one I'm using

Void setup(){
Serial.begin(9600);
pinMode(A0,INPUT);
}
Void loop(){
Serial.println(analogRead(A0));
}

And ty for your advice I saved it to be able to look back at it :blush:

1 Like

You don't need pinMode to do an analogRead.

What output do you get if you remove the pot and short A0 to 5V or GND ?

No, that looks to be a clone though. I've heard clones can come with dodgy 5V regulators and other issues.

It still gives 0
I tried making it input pull-up but it's still only printing 0

Yes it is a clone since we don't have the original In Iran but I haven't seen anyone else have a problem with this type of clone but you might be right
Is there another way for me to read analog sensors?

If the output is 0 whether the input is connected to 5V or GND then it looks very much as though there is a problem with the Mega, but you would be unlucky of all of its analogue inputs were broken

int potPin = A0;
int potReading = 0;

void setup() {
  Serial.begin(9600);
  Serial.println(F("myPotentiometerTest"));
  Serial.println();
  delay(500);
}
void loop() {
  potReading = (analogRead(potPin));
  Serial.println(potReading);
  delay(500);
}

run this instead. I just traded yours and added a couple usual conventions to slow the monitor and give your eyes a second to watch closely.
If it doesn't work, it's either your 5 volt regulator or the potentiometer or one of your wires. Test each situation individually, only change one thing at a time.
(Edit: added the earlier suggestion about embedding the sketch name in the setup)
(Edit edit: corrected for my bonehead mistake. Thanks for the spot, @Delta_G :grinning: )

it's still the same

Try the 3.3V regulator or set a digital pin to high in setup and swap out the 5 volt pot pin for that.

after isolating for all the potential issues I mentioned?