Registers arduino nano

I just started with arduino nano. At the beginning, I was measuring voltage using analogRead() , which gave me values in the range of 0-1023. I wanted an 8-bit resolution, so I tried to program with registers. Unfortunately, I have no idea about this. I tried to change ADCSRA and ADMUX . Now, I can't perform any measurements, and the values returned by analogRead() are very small. Is there a simple way to restore initiall settings?

To restore settings, cycle the power and upload a program that does not mishandle the registers.

ADC tutorial

Tell me if i understand correctly? I only cycle power and then upload program where i'm not using registers. if yes? I did it, but it doesn't working.

Changing registers is not permanent. When you cycle the power they default back to normal settings.

Maybe you damaged your a Nano with circuits connected to it?

Try another Nano.

Hello sebastiano1234568

Use the map() function simply.

sensorRead = map(analogRead(SensorPin),0,1023,0,255); 

Why do things the hard way?
It makes a lot more sense to simply take the 10-bit result, add 0x2 to it (i.e. round up) and then shift it 2 bits to the right.

1 Like

It is very weird but now I'm getting values form analogread() like 0,1,15,6,1,1,0,6. I don't know what to do

You could follow the forum instructions, described in the "How to get the best out of this forum" post, and post the code, along with a wiring diagram (hand drawn is preferred).

I guess there is nothing to describe. After changing the registers i make a new sketch where i have only used function analogread() from pin A0. I get following output " 0, 1,6, 15, 6,1, 0 , 0,1 ,6"

just divide your result by 4 and you will loose 2 bits. --> 8bit

1 Like

Now i have problem with analogread(), because it return weird values as i wrote earlier.

Then forum members can't help. Your choice!

1 Like

int adcWartosc = analogRead(A0);
Serial.println(adcWartosc);

what is very important this code was working before i tried programming on registers. Pin A0 is connected to ktir0711s and it read the value of measured light.

It's hard to describe my program because it is line follower with pid, so it is quite large. But now my problem is with simple one function which is analogread(). Is it possible that i broke my arduino?

You can write the simple code that will contains the analogRead() function only and test your board with this code.

Unfortunately it
doesnt work

please show the code

output is totally not correct because i measured voltage which was almost in the entire range

Try to connect A0 to GND first and then to VCC
Measure the values in both cases