0

I am having some major issues with my Arduino Yun.

When attempting to read a value from the analog pins, the Yun is giving me incorrect constant values.

I have attached everything to a common ground, and I am supplying 3.3 volts to the A0 pin on the Yun.

The weird thing is, the pins all give constant values in ascending order, no matter what is connected to them, or if nothing is connected at all.

  • A0 - 18
  • A1 - 19
  • A2 - 20
  • A3 - 21
  • A4 - 22
  • A5 - 23

The code I am running is a very simple script.

float i;

void setup()
{
  Serial.begin(9600);
}

void loop() {
  i = A0; 
  Serial.println(i);
  delay(1000);
}

1 Answer 1

2

You are not reading from any analog pins. You are just printing out the digital pin number of the analog pin.

Look at some basic examples on how to read analog values.

/*
  AnalogReadSerial
  Reads an analog input on pin 0, 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.
*/

// 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);
  // print out the value you read:
  Serial.println(sensorValue);
  delay(1);        // delay in between reads for stability
}
1
  • oh my goodness, wow I feel like an idiot; I had it set up with "analogRead" at first but I must have removed my code without noticing it. At first, I was reading analog values just fine, then this happened out of no where Anyhow, thank you! Commented Mar 16, 2017 at 1:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.