# UNO analog to digital data conversion

**URL:** <https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441>\
**Category:** General Guidance\
**Created:** [May 30, 2026, 5:20pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441 "2026-05-30T17:20:26Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaito\_kid1412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaito_kid1412/32/1126661_2.png) [@kaito\_kid1412](https://forum.arduino.cc/u/kaito_kid1412)\
**Post date:** [May 30, 2026, 5:20pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/1 "2026-05-30T17:20:26Z")

</div>

discussion about how to light up a LED using a water level sensor with an IDE sketch

---

<div class="post-metadata">

**Author:** ![Ron\_Blain](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ron_blain/32/1126393_2.png) [@Ron\_Blain](https://forum.arduino.cc/u/Ron_Blain)\
**Post date:** [May 30, 2026, 6:07pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/2 "2026-05-30T18:07:32Z")

</div>

Easy enough to do but you need to post what sensor(s) you plan to use? There is plenty of ways to detect a water level and make things happen, however, the type sensor needs to be known,

Welcome to the community.

Eon

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [May 30, 2026, 6:10pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/3 "2026-05-30T18:10:26Z")

</div>

Also, the type of Arduion (UNO/NANO/MEGA) you are using.

---

<div class="post-metadata">

**Author:** ![kaito\_kid1412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaito_kid1412/32/1126661_2.png) [@kaito\_kid1412](https://forum.arduino.cc/u/kaito_kid1412)\
**Post date:** [May 30, 2026, 6:21pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/4 "2026-05-30T18:21:19Z")

</div>

i'm using arduino UNO and the water level sensor that comes with the ARDUINO UNO set and also thank you for welcoming me here

---

<div class="post-metadata">

**Author:** ![anon95813201](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon95813201](https://forum.arduino.cc/u/anon95813201)\
**Post date:** [May 30, 2026, 6:33pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/5 "2026-05-30T18:33:04Z")

</div>

Does it look like this?

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/4/8/5/485ea1e4d66e83272e7c9dd68131253e5bb32465.jpeg)

Also, which Uno, the R3, R4 or Q?

---

<div class="post-metadata">

**Author:** ![ec2021](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ec2021/32/997272_2.png) [@ec2021](https://forum.arduino.cc/u/ec2021)\
**Post date:** [May 30, 2026, 6:36pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/6 "2026-05-30T18:36:01Z")

</div>

Ok. That's a sensor that works with measuring the resistance using an analog input correct?

Here is a simple sketch that uses

a) a slide potentiometer which can be replaced by an analog water level sensor (Edit: But read my comment below ... )

b) in parallel a digital switch that replaces a level switch (e.g. a float switch)

As the sketch measures once every second there is no need to debounce the switch.

```arduino
/*
  Forum: https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441
  Wokwi: https://wokwi.com/projects/465468745125615617

  2026/05/30
  ec2021

*/

constexpr byte ledPin {10};
constexpr byte analogPin {A0};
constexpr byte digitalPin {2};
constexpr uint16_t threshold {512};
constexpr unsigned long interval {1000}; // Check the water level every second (1000 ms)
unsigned long lastCheck;
byte ledState;

void setup() {
  Serial.begin(115200);
  pinMode(ledPin, OUTPUT);
  pinMode(digitalPin, INPUT_PULLUP);
  Serial.println("Start");
  ledOff();
}

void loop() {
  if (millis() - lastCheck >= interval) {
    lastCheck = millis();
    checkWaterLevel();
  }
}

void ledOn() {
  digitalWrite(ledPin, HIGH);
  ledState = HIGH;
}

void ledOff() {
  digitalWrite(ledPin, LOW);
  ledState = LOW;
}

void checkWaterLevel() {
  boolean digitalAlert = !digitalRead(digitalPin);
  boolean analogAlert = (analogRead(analogPin) > threshold); // or < threshold depending on realization
  if (digitalAlert || analogAlert) {
    if (ledState == LOW) {
      Serial.println("Water Level LOW");
    }
    ledOn();
  } else {
    if (ledState == HIGH) {
      Serial.println("Water Level HIGH");
    }
    ledOff();
  }
}

```

You can test it on Wokwi: [https://wokwi.com/projects/465468745125615617](https://wokwi.com/projects/465468745125615617)

> **Wiring**
>
> ![image](https://europe1.discourse-cdn.com/arduino/original/4X/2/1/1/2115ff9db7d195dc3f5f5ec0c3f39e25957a38f8.png)

Good luck!  
ec2021

BTW:

- Check the correct threshold for your sensor
- Check the values of your sensor
  - when it's dry
  - when it's wet

You may have to change something in the code to get the appropriate alert ... ;-)

---

<div class="post-metadata">

**Author:** ![kaito\_kid1412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaito_kid1412/32/1126661_2.png) [@kaito\_kid1412](https://forum.arduino.cc/u/kaito_kid1412)\
**Post date:** [May 30, 2026, 7:25pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/7 "2026-05-30T19:25:04Z")

</div>

yes that one and i use UNO R3

---

<div class="post-metadata">

**Author:** ![kaito\_kid1412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaito_kid1412/32/1126661_2.png) [@kaito\_kid1412](https://forum.arduino.cc/u/kaito_kid1412)\
**Post date:** [May 30, 2026, 7:25pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/8 "2026-05-30T19:25:38Z")

</div>

thx a lot

---

<div class="post-metadata">

**Author:** ![anon95813201](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon95813201](https://forum.arduino.cc/u/anon95813201)\
**Post date:** [May 30, 2026, 7:28pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/9 "2026-05-30T19:28:40Z")

</div>

Then see this tutorial.  
It explains everything you need to know and more.

> **[Interface Water Level Sensor with Arduino UNO – Circuit, Code & Working](https://circuitdigest.com/microcontroller-projects/interfacing-water-level-sensor-with-arduino)**
>
> Build an Arduino water level sensor project with full circuit diagram, ready-to-use code, pinout, specs, and 3-LED depth indicator. Works with UNO, ESP32 & NodeMCU.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/e/3/be37fecb18a081bbdfc5e1de635a75470c40a963.jpeg)

---

<div class="post-metadata">

**Author:** ![kaito\_kid1412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaito_kid1412/32/1126661_2.png) [@kaito\_kid1412](https://forum.arduino.cc/u/kaito_kid1412)\
**Post date:** [May 30, 2026, 7:30pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/10 "2026-05-30T19:30:19Z")

</div>

thank you very much for your help i appreciate it a lot

---

<div class="post-metadata">

**Author:** ![anon95813201](https://avatars.discourse-cdn.com/v4/letter/a/87869e/32.png) [@anon95813201](https://forum.arduino.cc/u/anon95813201)\
**Post date:** [May 30, 2026, 7:31pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/11 "2026-05-30T19:31:43Z")

</div>

If you have any problems just ask.

---

<div class="post-metadata">

**Author:** ![ec2021](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ec2021/32/997272_2.png) [@ec2021](https://forum.arduino.cc/u/ec2021)\
**Post date:** [May 30, 2026, 10:11pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/12 "2026-05-30T22:11:01Z")

</div>

The most important thing is:

> Try to understand how the code works

The example I posted works but not 1:1 with the sensor you have ...

It provides a lot of information but you will have to change a little bit for your application.

If you are interested in learning to write applications for Arduino you will surely find where to make changes.

Good luck and have fun with Arduino!  
ec2021

---

<div class="post-metadata">

**Author:** ![pert](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/pert/32/217111_2.png) [@pert](https://forum.arduino.cc/u/pert)\
**Post date:** [May 30, 2026, 10:51pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/13 "2026-05-30T22:51:10Z")

</div>

I moved your topic to a more appropriate forum category @kaito_kid1412.

The #UNO Family > UNO Breakout Carrier category you chose is only used for discussions directly related to the [**Arduino UNO Breakout Carrier**](https://docs.arduino.cc/hardware/uno-breakout-carrier/) product. You aren't using an **UNO Breakout Carrier** , so it was not appropriate to choose this category for your forum topic.

In the future, when creating a topic please take the time to pick the [forum category](https://forum.arduino.cc/categories) that best suits the subject of your question. There is an " **About the \_\_\_\_\_ category**" topic at the top of each category that explains its purpose.

Thanks in advance for your cooperation.

---

<div class="post-metadata">

**Author:** ![GolamMostafa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/golammostafa/32/239011_2.png) [@GolamMostafa](https://forum.arduino.cc/u/GolamMostafa)\
**Post date:** [May 31, 2026, 4:46am UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/14 "2026-05-31T04:46:00Z")

</div>

> [@anon95813201](#):
>
> ![image](https://europe1.discourse-cdn.com/arduino/original/4X/b/e/3/be37fecb18a081bbdfc5e1de635a75470c40a963.jpeg)
> 
> image750×500 67.7 KB

You did this experiment? Congratulatons!!

---

<div class="post-metadata">

**Author:** ![ec2021](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ec2021/32/997272_2.png) [@ec2021](https://forum.arduino.cc/u/ec2021)\
**Post date:** [May 31, 2026, 9:19am UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/15 "2026-05-31T09:19:30Z")

</div>

As you are beginning with programming you may try to get a copy of Michael Margolis Arduino Cookbook.

Just search the Internet for further information!

There are PDFs available for free (but probably not legal) ...

---

<div class="post-metadata">

**Author:** ![kaito\_kid1412](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/kaito_kid1412/32/1126661_2.png) [@kaito\_kid1412](https://forum.arduino.cc/u/kaito_kid1412)\
**Post date:** [May 31, 2026, 2:02pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/17 "2026-05-31T14:02:48Z")

</div>

wdym by "probably not legal" i don't get it

---

<div class="post-metadata">

**Author:** ![ec2021](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ec2021/32/997272_2.png) [@ec2021](https://forum.arduino.cc/u/ec2021)\
**Post date:** [May 31, 2026, 2:34pm UTC](https://forum.arduino.cc/t/uno-analog-to-digital-data-conversion/1446441/18 "2026-05-31T14:34:19Z")

</div>

There are sources in the internet where Michael Margolis book can be downloaded in PDF format.

It's a good possibility to have a look but I doubt that the copies are legally available.

If you want to be sure you better buy the book. It's worth the price, especially if you go for a used one.

Just search the Internet using the keywords

"Arduino Cookbook Michael Margolis"..

(I'm not a friend of illegal copies where people have spent a lot of time and effort to create a helpful document. The effort should honored.)
