DIFFERENCE BETWEEN ANALOG AND DIGITAL

HI. I have gone through a good amount of tutorials and "googles" but I still don't see the difference between analog(pins and reads) and digitals(pins and reads) and why you would use one rather than the other. Thank you!

Ethan

Analogue reads are very slow, but tell you fairly precisely what the (relative) voltage is on a pin.
Digital read tells you that the voltage is over or under some preset thresholds, (relative to the supply voltage) but is very fast.

This is not a programming question

A light switch is on or off. That is a digital device, and gets connected to a digital pin.

A potentiometer can have a range of resistances from none to some maximum value. That is an analog device, and gets connected to an analog pin.

digitalRead() returns HIGH or LOW.

analogRead() returns any number from 0-1023

Ok thanks @Groove! What would it be?

Thx for help and examples @PaulS!

Thx @hutkikz! I understand what it is used for but what exactly is the unit of the numbers 0 - 1023?

THANK YOU ALL!

It has no unit. It defines the ratio of Vref and the voltage applied to the analog pin. So on a normal Uno (with default settings) it defines the ratio between the voltage at the analog pin and 5V. So 1023 = 5V (just under but don't worry about that) and 512 = 2,5V etc etc

Thank you @septillion! How do you know how many volts you need to complete an output especially using an external source of power like a 9V adapter. If I were to experiment with one what type of battery would work best. Thx for time and everything! :slight_smile:

Ethan

What do you mean "how many volts you need to complete an output". The sentence does not make sens...

Just connect the Arduino to a power source, USB of via the plug (7v to 12V) and you can measure a voltage between 0v and 5V on a analog pin.

Note that the 5V when connected to USB is not really 5V. Because analog pins are referenced to that it influences the reading because it's referenced to that limb 5V. But as long as you use the (limb) 5V line of the Arduino itself (and not some external source) to power whatever is making the voltage (for example a potentiometer) you are just fine.