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
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)
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
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 )