I've got an ATMEGA328P-PU in a circuit (using 16MHz crystal oscillator, external), where the PC3 pin (equivalent - A3) is connected to a voltage divider which has a 12v source going through a 100kOhm resistor to the pin, then a 47kOhm resistor to ground (5v source and 14V max (the whole circuit is for charging a 12v NiCD battery) source share a ground, only connected in one place). I made a program to read the value of this pin and stop a certain operation when it reached 1023 or greater. I was having problems with this, so I set up PC1 (A1) to output whatever PC3 (A3) was reading, and even when I ground PC3, PC1 still outputs 5V (1023). I've tried changing around which ADC pins I was using, but same results each time. The actual voltage at the PC3 pin is 4.33v.
Any ideas? I'm probably missing something obvious. The rest of the code works great, just this measuring the value at the ADC pin part is temporarily stumping me.
int drvd = 5;
int drvc = 6;
int cLED = 7;
int dLED = 8;
float b;
float a;
void setup() {
// initialize digital pin LED_BUILTIN as an output.
pinMode(drvd, OUTPUT);
pinMode(drvc, OUTPUT);
pinMode(cLED, OUTPUT);
pinMode(dLED, OUTPUT);
}
void loop() {
digitalWrite(drvc, HIGH); //drvc low-time
a = analogRead(A3);
b = a * (6.00/1023);
analogWrite(A1, 0);
delayMicroseconds(b * 1000);
if(a < 1023)
{
digitalWrite(drvc, LOW); //control from low, drvc hightime
delay(1);
digitalWrite(dLED, LOW);
digitalWrite(cLED, HIGH);
analogWrite(A1, a);
}
else
{
digitalWrite(dLED, HIGH);
digitalWrite(cLED, LOW);
delay(100);
analogWrite(A1, 0);
digitalWrite(dLED, LOW);
digitalWrite(cLED, LOW);
delay(100);
analogWrite(A1, a);
}
}