Anakog Input not going zero

Hello All,
Arduino Uno user here

I am building a project with 4 analog inputs A0 dose not work. A1 A2 and A3 work perfectly fine! But for last input when I connect to A4 or A5, then they do not go to zero. They are stuck between 400 to 900. Even when connected to arduino ground it gives 400 instead of 0.

Am I missing something here cause the circuit for A4 connected to A3 gives perfect input value. They both work fine as output. Same situation with A5.

Is there another way to get one more Analog Input without multiplex?

Thank you!

abhishrant:
Am I missing something here cause the circuit for A4 connected to A3 gives perfect input value. They both work fine as output. Same situation with A5.

Is there another way to get one more Analog Input without multiplex?

Yes, remove your I2C device that is using A4 and A5 (and the I2C code).

Arduino Leonard has 12 analog inputs.
http://arduino.cc/en/Main/arduinoBoardLeonardo

Paul__B:
Yes, remove your I2C device that is using A4 and A5 (and the I2C code).

Oh, I A4 and A5 are used as SDA and SCL.

How to remove I2C device (I am not using any) and use the input as normal analog input?

Peter_n:
Arduino Leonard has 12 analog inputs.
http://arduino.cc/en/Main/arduinoBoardLeonardo

I need only 4.. Uno has 6 so I will stick to uno... The problem is A0 is fried and I am not getting to work A4 and A5. :frowning:

Perhaps there is a Wire.begin() in your sketch. Can you show us your sketch.
Or perhaps A4 and A5 are also fried :confused:

Peter_n:
Perhaps there is a Wire.begin() in your sketch. Can you show us your sketch.
Or perhaps A4 and A5 are also fried :confused:

Here is the code

const int numReadings = 50;

int readings[numReadings];
int bassReadings[numReadings];
int midReadings[numReadings];
int highReadings[numReadings];/// the readings from the analog input

int index = 0; // the index of the current reading

int total = 0;
int bassTotal = 0;
int midTotal = 0;
int highTotal = 0;// the running total

int average = 0;
int bassAverage = 0;
int midAverage = 0;
int highAverage = 0;// the average

int value = 0;
int bassValue = 0;
int midValue = 0;
int highValue = 0;

int inputPin = A5;
int bassPin = A2;
int midPin = A1; ;
int highPim = A3;

int led = 9;
int bassLed = 3;
int midLed = 11;
int highLed = 10;

void setup()
{
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(5, INPUT);
digitalWrite(8, HIGH);
digitalWrite(SDA, 0);
digitalWrite(SCL, 0);
for (int thisReading = 0; thisReading < numReadings; thisReading++)
readings[thisReading] = 0;
}

void loop() {
total= total - readings[index];
bassTotal= bassTotal - bassReadings[index];
midTotal= midTotal - midReadings[index];
highTotal= highTotal - highReadings[index];
readings[index] = analogRead(inputPin);
bassReadings[index] = analogRead(bassPin);
midReadings[index] = analogRead(midPin);
highReadings[index] = analogRead(highPim);
total= total + readings[index];
bassTotal= bassTotal + bassReadings[index];
midTotal= midTotal + midReadings[index];
highTotal= highTotal + highReadings[index];
index = index + 1;

if (index >= numReadings)
index = 0;

average = total / numReadings;
bassAverage = bassTotal / numReadings;
midAverage = midTotal / numReadings;
highAverage = highTotal / numReadings;

value = map(average, 30, 255, 0, 255);
bassValue = map(bassAverage, 0, 255, 0, 255);
midValue = map(midAverage, 0, 255, 0, 255);
highValue = map(highAverage, 0, 255, 0, 255);

analogWrite(led, value);
analogWrite(bassLed, bassValue);
analogWrite(midLed, midValue);
analogWrite(highLed, highValue);

Serial.println(analogRead(inputPin));
delay(1); // delay in between reads for stability
}

I do not use wire... I still noticed that wire had enabled pull up resistance for SDA and SCL... So commented that out and disabled it here (set 0)... The values came down to 30.. I don't think they are fried as they take input correctly but with a offset of 30 to 50. I cannot manage the offset as it is not fixed but variable. But I still kept the low value as 30 in map.

I just used the smoothing example and modified it to requirements. All I need is another input and project is done!

Thank You.

That can't be right. When the Wire.begin() is not called, the A4 and A5 don't have the pullup resistor enabled. They really don't.
The Arduino Uno is the easiest Arduino board, so everything should be straightforward and simple.

I don't know how you measure the A4 and A5.
At this moment I don't know if I can trust that Uno board :confused: and I don't know what to think of it.

You could do a test. Remove everything from the Uno board (keep usb connector). Print the analog inputs to the serial monitor. Apply an analog voltage to the analog pins.

Peter_n:
That can't be right. When the Wire.begin() is not called, the A4 and A5 don't have the pullup resistor enabled. They really don't.
The Arduino Uno is the easiest Arduino board, so everything should be straightforward and simple.

I don't know how you measure the A4 and A5.
At this moment I don't know if I can trust that Uno board :confused: and I don't know what to think of it.

You could do a test. Remove everything from the Uno board (keep usb connector). Print the analog inputs to the serial monitor. Apply an analog voltage to the analog pins.

Do you mean the board has gone bad or just the Atmega328?

Anyway here are the values...

A0 (Fried)
Open - 990
Ground - 990

A1
Open - 700 to 1000
Ground - 0

A2
Open - 700 to 1000
Ground - 0

A3
Open - 700 to 1000
Ground - 0

A4
Open - 990 to 1000
Ground - 27

A5
Open - 990 to 1000
Ground - 29

A4 (Pullup Enabled)
Open - 1000 to 1024
Ground - 143

A5 (Pullup Enabled)
Open - 1000 to 1024
Ground - 143

Open: Not connected to ground
Ground: Connected to Arduino Ground.

I only had 9v battery so did not apply any voltage to it.

Just the ATmega328P.

The open values can be anything. But if you short the analog input to ground, and the value is 27 or higher, the chip is bad.

Did you try the ATmeg328P in the Arduino Uno or in the breadboard ?
Some breadboards have bad (very) contacts. There are many problems with breadboards on this forum.

However if you are sure that one of the analog inputs is damaged, it is very likely that other analog inputs are damaged as well. The analog section is seperate part in the chip. It is possible to blow the analog section without damaging the rest of the chip.

Peter_n:
Just the ATmega328P.

The open values can be anything. But if you short the analog input to ground, and the value is 27 or higher, the chip is bad.

Did you try the ATmeg328P in the Arduino Uno or in the breadboard ?
Some breadboards have bad (very) contacts. There are many problems with breadboards on this forum.

However if you are sure that one of the analog inputs is damaged, it is very likely that other analog inputs are damaged as well. The analog section is seperate part in the chip. It is possible to blow the analog section without damaging the rest of the chip.

i have not opened the atmega from its jail yet... I planned to do it after the project is successful I testing.
If the board is damaged then I am screwed cause I can not replace it but can replace the atmega but its costly here so i can only buy it after the project ends.

A0 is fried cause by mistakenly without a diode I connected it to negative voltage. A1 to 3 work perfectly fine for the job. All I need is one more analog input and project is done.

I changed all potentiometer to RC filter circuits (low, high and band) which splits an audio input to bass, mid and high. This 3 work fine with A1 to A3. I need one more pin just to show a direct value without the filter. All input connect to a PWN led to show their value by brightness. Something like music led sync is the project.

Any more methods?

Thank You,

You could consider using an external AD converter.
But changing the controller (certainly if it's a DIP package) will likely be cheaper and easier.

MAS3:
You could consider using an external AD converter.
But changing the controller (certainly if it's a DIP package) will likely be cheaper and easier.

No external AD converters available here... Plus its just one pin.. :stuck_out_tongue:

I guess I will wrap it up with 3 inputs and I will see if the 4th input value can be emulated by other pins' input values.

I will buy another atmege328 when this completes.

Thank You for all your help guys. Really Appreciate it. :smiley:

If you can buy on Ebay and have PayPal, you can buy a cheap clone Uno R3 board for less than 5 dollars.

Peter_n:
If you can buy on Ebay and have PayPal, you can buy a cheap clone Uno R3 board for less than 5 dollars.

Cannot use paypal to make transactions in India (or outside). Which is the big downside. :frowning:

You could also consider using a multiplexer like 4053.
Google for its datasheet and see if that will do.
A 4053 offers you some similarity to 3 double throw switches at the cost of one control pin.
There's a whole family of these which differ to each other by the number of inputs and outputs.