Can someone explain to me why the ADC keeps printing values on the serial monitor without anything connected to the analog input pin (arduino is basically connected to laptop USB only). Attached is the code (found in arduino website) and the output from serial monitor. Is arduino damaged :S ?
How would you determine if a pin was "working" when there is nothing connected to it? How would even define "working" for a pin with nothing connected to it?
Is it necessary for the pin to output 0 when nothing is connected?
If you want the pin to go to a particular value when it is not connected, you need to connect an external pull-up or pull-down resister to stop it floating. Or, you can enable the internal pull-up resister.
The internal pull up resistor can only be enabled to digital pins right? I am using the analog pin, if so can I still declare the analog pin as an input?
When I put the analog pin to HIGH or LOW, the analog pin A0 outputs 14 on the serial monitor. Is it normal?
int analogPin = A0; // potentiometer wiper (middle terminal) connected to analog pin 3 // outside leads to ground and +5V
int val = 0; // variable to store the value read
void setup()
{
Serial.begin(9600); // setup serial
pinMode(analogPin, INPUT);
}
void loop()
{
//val = analogRead(analogPin); // read the input pin
analogWrite(analogPin, HIGH);
Serial.println(analogPin); // debug value
delay(300);
}
Yes that is normal, you are printing the value of a variable you created called analogPin which is set to A0 which is an alias of the number 14. This has nothing to do with what voltage is at pin 14 either reading or writing.
By the way the statement:
analogWrite(analogPin, HIGH);
Is bogus. You can only perform analogWrites to digital output pins that are associated with PWM capabilities. To use a analog pin as a digital output pin you can use only digitalWrite commands.
When I put the analog pin to HIGH or LOW, the analog pin A0 outputs 14 on the serial monitor. Is it normal?
Analog pins are input only. You can't set them to HIGH or LOW. Analog pins as digital pins can be set HIGH or LOW, if you have declared them to be output pins, and you reference them using the correct numbers (or aliases).