0

So I'm a bit at a loss. I'm trying to set up a suite of environmental sensors to run off of the breadboard, and input analog data to my Mega. I have a potentiometer hooked up to the 5v and ground pins of the Power Supply Module, with the output of the potentiometer hooked up t0 A3. I have the AREF pin also connected to the positive 5v output on the PSM.

schematic

simulate this circuit – Schematic created using CircuitLab

As a bit of test code, I have the following:

void setup() {

  Serial.begin(9600);
  analogReference(EXTERNAL);
  pinMode(A3, INPUT);

}

void loop() {

int j=0;

while (j<1){

Serial.println(analogRead(A3));
delay(500);
j++;

}

As is, that gives me an output that looks like this (cyclical and repeating, without me adjusting or touching the potentiometer):

573
480
398
0
0
0
0
0
0
0
45
0
0
296
162
263
222
526
597
584
593
667
711
642
612
632
407
0
0

I don't understand why this isn't giving me a consistent value. I also tried running the setup without calling analogReference() and without the AREF pin connected and got a similar result. The weirder part is that I accidentally ran this bit of code without calling analogReference(EXTERNAL), with the AREF pin connected, and it gave me a correct value. From what I'm reading though that can apparently cause damage to the board, but it's the only way I'm getting consistent and accurate reads from my sensors when the sensors are powered off the PCM. Can anyone fill me in on why this is happening? Will doing this damage my board?

Jacob
  • 1
  • 1
    You are connecting the grounds of these things together, right? – timemage Feb 02 '23 at 19:34
  • Hopefully PSM negative is conbected to GND! You also must supply 5V to the AVCC pin. What board exactly do you use? – datenheim Feb 03 '23 at 17:10
  • I'm using the Mega 2560. I haven't been grounding them together, as none of the instructions I've seen have included any mention of grounding. I tried that and it worked! Thank you! – Jacob Feb 05 '23 at 06:22

0 Answers0