I want to use 2.56 voltages from my mega2560. What I did is as follows:
int PE = 2;
int CE = A1;
int temp_val_PE = 0;
int temp_val_CE = 0;
analogWrite(CE,0); //reduction for blue
temp_val_PE = analogRead(A0);
val_PE = temp_val_PE*(2.56 / 1024.0);
analogWrite(CE,128); //oxidation for bleach
On serial monitor it is continuously showing 2.56 while when I measure the voltages at A0 with multimeter it shows 5 volts.
What could be the problem?
thanks for reading my problem.
If you've got 5V on the input pin, then you would expect to see 2.56V printed with a 2.56V reference..
Please use code tags when posting code.
More generally an ADC cannot measure anything higher than it's reference voltage. Anything higher will max out the ADC reading. In the case of the ATmega328p, that's 1023, which your formula will calculate to be 2.56 volts.
Thanks AWOL for replying me.
@AWOL I did not understand what do you mean by 5V on the input pin? I am powering up mega2560 with USB i.e. 5V from laptop. I am using analog pin A0 and want to read its voltages after writing some input on that.
2nd: Can I use analogWrite on analog pins? as you can see that I used analogWrite(A0,128); because I need to apply varying voltages something around 2 V on A0 pin.
3rd: How I can implement some voltages which are continuously increasing from 0 to 2 volts?
4th: what are code tags?
I did not understand what do you mean by 5V on the input pin?
when I measure the voltages at A0 with multimeter it shows 5 volts.
The input put on which you measured 5V.
2nd: Can I use analogWrite on analog pins?
Code tags are explained in the “How to use the forum” thread.