Arduino UNO Q - Rain Sensor

A rain sensor can detect rain or snow and measure rainfall intensity. It provides both a digital output (rain/no rain) and an analog output (intensity level). On Arduino UNO Q, the MCU's 12-bit ADC gives higher resolution intensity readings. With Bridge and Telegram, you get instant rain alerts on your phone.

In this tutorial, you will learn:

Arduino UNO Q Rain Sensor

Hardware Preparation

1×Arduino UNO Q
1×USB Cable for Arduino Uno Q
1×Rain Sensor
1×Jumper Wires
1×Recommended: Screw Terminal Block Shield for Arduino Uno
1×Recommended: Sensors/Servo Expansion Shield for Arduino Uno
1×Recommended: Breadboard Shield for Arduino Uno
1×Recommended: Enclosure for Arduino Uno
1×Recommended: Prototyping Base Plate & Breadboard Kit for Arduino UNO

Or you can buy the following kits:

1×DIYables Sensor Kit (18 sensors/displays)
Disclosure: Some of the links provided in this section are Amazon affiliate links. We may receive a commission for any purchases made through these links at no additional cost to you.
Additionally, some of these links are for products from our own brand, DIYables .

Overview of the Rain Sensor

The rain sensor has two parts: a sensing pad and an electronic module.

Rain Sensor Pinout

Sensing pad: Placed outdoors (on a roof or window ledge). Has alternating power and sensor copper lines — water bridges these lines when rain falls.

Electronic module: Converts the pad signal into readable outputs:

  • VCC pin: 3.3V to 5V power supply
  • GND pin: Ground
  • DO pin: Digital output — HIGH = no rain, LOW = rain detected. Sensitivity set by onboard potentiometer.
  • AO pin: Analog output — lower value = more rain, higher value = less rain. Potentiometer does NOT affect AO.

It also has two LEDs:

  • PWR-LED: Power indicator
  • DO-LED: Lights up when rain is detected (DO pin LOW)

How It Works

  • DO pin: The potentiometer sets a threshold. If rain exceeds the threshold, DO goes LOW. Adjust the potentiometer to set sensitivity.
  • AO pin: Continuously outputs an analog voltage proportional to the water on the pad. On Arduino UNO Q the MCU reads this as a 12-bit value (0–4095) — lower values mean more rain.

※ NOTE THAT:

Connect VCC to a digital output pin (not always-on 5V) and power the sensor only during readings. This reduces electrochemical corrosion and extends sensor lifetime.

Wiring Diagram

The wiring diagram between Arduino UNO Q Rain Sensor

This image is created using Fritzing. Click to enlarge image

Rain Sensor Pin Arduino UNO Q MCU
GND GND
VCC D3 (controlled power)
DO D4
AO A0

How To Program For Rain Sensor

  • Set up pins:
pinMode(POWER_PIN, OUTPUT); pinMode(DO_PIN, INPUT);
  • Power sensor, read both outputs, then power off:
digitalWrite(POWER_PIN, HIGH); // power on delay(10); // stabilize int do_state = digitalRead(DO_PIN); // HIGH = no rain, LOW = rain int ao_value = analogRead(AO_PIN); // 0-4095, lower = more rain digitalWrite(POWER_PIN, LOW); // power off
  • Check rain from digital output:
if (do_state == LOW) { Serial.println("Rain DETECTED"); } else { Serial.println("No rain"); }

Arduino UNO Q Code

The Arduino UNO Q has two processors working together:

  • The STM32 MCU reads both DO (digital) and AO (analog) outputs from the rain sensor every second
  • The Qualcomm MPU runs Debian Linux and handles Wi-Fi, Python, and cloud connectivity
  • In this section, only the MCU is programmed — the Linux side stays idle. A later section shows how both processors work together via Bridge.

※ NOTE THAT:

The Arduino UNO Q MCU uses a 12-bit ADC (0–4095). The AO intensity values will be in this range — adjust detection thresholds accordingly.

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rain-sensor */ // COPYRIGHT newbiely.com // AUTHOR: newbiely // This code is made available for public use without restriction. // For complete instructions, tutorials, and further information, visit: // https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rain-sensor // Rain sensor has two outputs: // DO: digital — HIGH = no rain, LOW = rain detected // AO: analog — lower value = more rain (12-bit ADC: 0-4095) // POWER_PIN: power sensor only when reading to reduce corrosion #define POWER_PIN 3 // The Arduino UNO Q MCU pin providing power to the rain sensor #define DO_PIN 4 // The Arduino UNO Q MCU pin connected to DO of the rain sensor #define AO_PIN A0 // The Arduino UNO Q MCU pin connected to AO of the rain sensor void setup() { Serial.begin(9600); pinMode(POWER_PIN, OUTPUT); pinMode(DO_PIN, INPUT); digitalWrite(POWER_PIN, LOW); // start with sensor powered off Serial.println("Arduino UNO Q Rain Sensor ready"); } void loop() { digitalWrite(POWER_PIN, HIGH); // power the sensor delay(10); // allow sensor to stabilize int do_state = digitalRead(DO_PIN); // HIGH = no rain, LOW = rain int ao_value = analogRead(AO_PIN); // 0-4095: lower = more rain digitalWrite(POWER_PIN, LOW); // power off sensor // Digital output if (do_state == LOW) { Serial.print("Rain DETECTED | "); } else { Serial.print("No rain | "); } // Analog output Serial.print("Intensity (AO): "); Serial.println(ao_value); delay(1000); }

Detailed Instructions

First time with Arduino UNO Q? Follow the Getting Started with Arduino UNO Q tutorial before proceeding.

  • Connect: Wire the rain sensor to the Arduino UNO Q MCU as shown in the wiring diagram.
  • Open Arduino App Lab: Launch Arduino App Lab and wait until it detects your Arduino UNO Q.
  • Create a new App: Click the Create New App button.
Create New App in Arduino App Lab on Arduino UNO Q
  • Give the App a name, for example: RainSensor
  • Click Create to confirm.
Arduino App Lab App folders and files on Arduino UNO Q
  • Paste the sketch: Copy the MCU code above and paste it into sketch/sketch.ino. Keep other files as default.
  • No library required — uses only the built-in digitalRead() and analogRead().
  • Upload: Click the Run button in Arduino App Lab.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Place a few drops of water on the sensing pad and observe the output in the Serial Monitor.
  • Adjust the potentiometer on the module if the DO LED does not respond correctly.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-04-29 09:00:01] Arduino UNO Q Rain Sensor ready [2026-04-29 09:00:02] No rain | Intensity (AO): 4090 [2026-04-29 09:00:03] No rain | Intensity (AO): 4088 [2026-04-29 09:00:04] Rain DETECTED | Intensity (AO): 1243 [2026-04-29 09:00:05] Rain DETECTED | Intensity (AO): 876 [2026-04-29 09:00:06] Rain DETECTED | Intensity (AO): 512 [2026-04-29 09:00:07] No rain | Intensity (AO): 3950

Bridge: Linux + MCU

This section shows how to program both processors of the Arduino UNO Q so the Linux side can read rain state and receive rain start events via Bridge:

  • The rain sensor is connected to the MCU — the MCU reads DO and AO every second and caches the values
  • The MPU cannot read the sensor pins directly — it calls Bridge functions to get state, analog value, or events
  • The MPU has Wi-Fi — running full Debian Linux, it can send Telegram alerts the moment rain is detected
  • Arduino_RouterBridge enables RPC communication between the two processors
  • ⚠️ /dev/ttyHS1 (Linux) and Serial1 (MCU) are RESERVED by the router — never open them in user code

In short: MCU detects rain via DO pin → sets event flag → MPU polls Bridge → MPU sends Telegram alert.

MCU Code (Bridge)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rain-sensor */ // COPYRIGHT newbiely.com // AUTHOR: newbiely // This code is made available for public use without restriction. // For complete instructions, tutorials, and further information, visit: // https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rain-sensor #include "Arduino_RouterBridge.h" #define POWER_PIN 3 // The Arduino UNO Q MCU pin providing power to the rain sensor #define DO_PIN 4 // The Arduino UNO Q MCU pin connected to DO of the rain sensor #define AO_PIN A0 // The Arduino UNO Q MCU pin connected to AO of the rain sensor // Cache int cached_ao = 4095; // start at max (dry) bool cached_rain = false; // from DO pin bool rain_event = false; bool prev_rain = false; unsigned long last_read_ms = 0; const unsigned long READ_INTERVAL = 1000; String get_state(String arg) { return cached_rain ? "rain" : "no_rain"; } String get_value(String arg) { return String(cached_ao); } String get_event(String arg) { if (rain_event) { rain_event = false; return "rain_detected"; } return "none"; } void setup() { Bridge.begin(); Monitor.begin(); pinMode(POWER_PIN, OUTPUT); pinMode(DO_PIN, INPUT); digitalWrite(POWER_PIN, LOW); Bridge.provide("get_state", get_state); Bridge.provide("get_value", get_value); Bridge.provide("get_event", get_event); Monitor.println("Arduino UNO Q Rain Sensor Bridge ready"); } void loop() { unsigned long now = millis(); if (now - last_read_ms >= READ_INTERVAL) { last_read_ms = now; digitalWrite(POWER_PIN, HIGH); delay(10); int do_state = digitalRead(DO_PIN); cached_ao = analogRead(AO_PIN); digitalWrite(POWER_PIN, LOW); cached_rain = (do_state == LOW); // LOW = rain detected if (cached_rain && !prev_rain) { rain_event = true; Monitor.print("Rain detected! AO value: "); Monitor.println(cached_ao); } else if (!cached_rain && prev_rain) { Monitor.println("Rain stopped."); } prev_rain = cached_rain; } }

Python Code (Bridge)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rain-sensor */ # COPYRIGHT newbiely.com # AUTHOR: newbiely # This code is made available for public use without restriction. # For complete instructions, tutorials, and further information, visit: # https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rain-sensor from arduino.app_utils import * import time def loop(): state = Bridge.call("get_state") value = Bridge.call("get_value") print(f"Rain state: {state} AO value: {value}") time.sleep(1) App.run(user_loop=loop)

Detailed Instructions

  • Connect: Wire the rain sensor to the Arduino UNO Q as shown in the wiring diagram.
  • Open Arduino App Lab: Launch Arduino App Lab and wait for the board to be detected.
  • Create a new App: Click Create New App, name it RainSensorBridge, then click Create.
  • Paste the MCU sketch: Copy the MCU Bridge code above and paste it into sketch/sketch.ino.
  • Paste the Python code: Copy the Python Bridge code above and paste it into the Python file in the App.
  • Install the library: Click the Add sketch library button (the open book icon with a + sign) in the left sidebar.
Add sketch library in Arduino App Lab on Arduino UNO Q
  • Search for Arduino_RouterBridge created by Arduino and click the Install button.
My Apps / DIYables Apps
Run
Bricks
No bricks added...
Sketch Libraries
No sketch libra...
Files
python
sketch
.gitignore
README.md
app.yaml
sketch.ino
Add sketch library
Arduino_RouterBridge Arduino

This library provides a simple RPC bridge for Arduino UNO Q boards, allowing communication between the board and other devices using MsgPack serialization.

0.4.1
Install
More Info
  • Upload: Click the Run button in Arduino App Lab.
Click Run button in Arduino App Lab on Arduino UNO Q
  • Add water to the sensor pad — observe rain state change in both consoles.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
Message (Enter to send a message to "Newbiely" on usb(2820070321))
New Line
9600 baud
[2026-04-29 09:00:01] Arduino UNO Q Rain Sensor Bridge ready [2026-04-29 09:00:05] Rain detected! AO value: 987 [2026-04-29 09:00:08] Rain stopped.
DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-04-29 09:00:02] Rain state: no_rain AO value: 4090 [2026-04-29 09:00:05] Rain state: rain AO value: 987 [2026-04-29 09:00:08] Rain state: no_rain AO value: 4080

Telegram

Receive instant Telegram alerts when rain is detected on the Arduino UNO Q rain sensor.

MCU sketch: Keep the same MCU sketch from the previous Bridge section.

Python Code (Telegram)

/* * This Arduino UNO Q code was developed by newbiely.com * * This Arduino UNO Q code is made available for public use without any restriction * * For comprehensive instructions and wiring diagrams, please visit: * https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rain-sensor */ # COPYRIGHT newbiely.com # AUTHOR: newbiely # This code is made available for public use without restriction. # For complete instructions, tutorials, and further information, visit: # https://newbiely.com/tutorials/arduino-uno-q/arduino-uno-q-rain-sensor from arduino.app_utils import * import requests import time TELEGRAM_BOT_TOKEN = "YOUR_TELEGRAM_BOT_TOKEN" CHAT_ID = "YOUR_CHAT_ID" last_update_id = 0 def get_updates(): global last_update_id url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/getUpdates" params = {"offset": last_update_id + 1, "timeout": 5} try: response = requests.get(url, params=params, timeout=10) data = response.json() if data["ok"]: return data["result"] except Exception as e: print(f"Error getting updates: {e}") return [] def send_message(chat_id, text): url = f"https://api.telegram.org/bot{TELEGRAM_BOT_TOKEN}/sendMessage" payload = {"chat_id": chat_id, "text": text} try: requests.post(url, data=payload, timeout=10) except Exception as e: print(f"Error sending message: {e}") def loop(): # Auto-alert when rain starts event = Bridge.call("get_event") if event == "rain_detected": value = Bridge.call("get_value") print(f"Rain detected! AO value: {value}") send_message(CHAT_ID, f"🌧️ Rain detected! Intensity (AO): {value}") # Telegram commands updates = get_updates() for update in updates: last_update_id = update["update_id"] if "message" not in update: continue message = update["message"] chat_id = message["chat"]["id"] text = message.get("text", "").strip() print(f"Received: {text}") if text == "/start": send_message(chat_id, "Arduino UNO Q Rain Sensor Bot\n" "/state - Rain detected or not (digital)\n" "/value - Read analog intensity (0-4095)\n" "Automatic alert when rain starts") elif text == "/state": result = Bridge.call("get_state") send_message(chat_id, f"Rain state: {result}") elif text == "/value": result = Bridge.call("get_value") send_message(chat_id, f"AO intensity value: {result}") else: send_message(chat_id, "Unknown command. Send /start for help.") time.sleep(0.5) App.run(user_loop=loop)

Detailed Instructions

  • Replace YOUR_TELEGRAM_BOT_TOKEN with your actual bot token from BotFather.
  • Replace YOUR_CHAT_ID with your Telegram chat ID.
  • Paste this Python code into your App's Python file (keep the same MCU sketch).
  • Click the Run button. Add drops of water to the sensor — receive the Telegram alert instantly.

App Lab Console Output

DIYables_Apps
Stop
sketch.ino
1#include "Arduino_RouterBridge.h"
Serial Monitor
Python
[2026-04-29 09:10:00] Waiting for Telegram messages... [2026-04-29 09:10:05] Rain detected! AO value: 875 [2026-04-29 09:10:12] Received: /state
Telegram
Telegram 12:45
Welcome to Telegram!
ArduinoBot 10:19
Chatting with Arduino...
telegram-botfather
BotFather Yesterday
Your bot has been created.

ArduinoBot

bot
Today
/state
10:15 AM ✓✓
Rain state: no_rain
10:16 AM
🌧️ Rain detected! Intensity (AO): 875
10:17 AM
/value
10:18 AM ✓✓
AO intensity value: 875
10:19 AM
/state
10:20 AM ✓✓
Rain state: rain
10:21 AM

OpenClaw

...OPENCLAW

OpenClaw support for Arduino UNO Q Rain Sensor is coming soon.

...OPENCLAW

Project Ideas

You can build many useful projects with the rain sensor and Arduino UNO Q:

  • Rain Alert System: Mount the sensing pad on a rooftop — when rain starts, the MPU sends a Telegram alert with the AO intensity value, so you can take action (close windows, bring in laundry) from anywhere
  • Automatic Awning Controller: Use the rain sensor with a motor/relay — when rain is detected, the MCU automatically closes an awning or blind via Bridge, and sends a Telegram notification
  • Rainfall Logger: Log every rain detection event with timestamp and AO intensity to a CSV file on Linux — generate a daily rainfall summary and send it to Telegram at midnight
  • Smart Irrigation Inhibitor: Combine with the pump tutorial — if rain is detected, Python skips the scheduled irrigation cycle to conserve water, and sends a Telegram message explaining why
  • Rooftop Garden Monitor: Track rain intensity over time using AO values — Python calculates average rainfall every 15 minutes and sends a periodic Telegram summary

Challenge Yourself

Ready to go further with the rain sensor on Arduino UNO Q? Try these challenges:

  • Easy: Classify AO intensity in Python: if int(value) > 3000"dry", > 1500"light rain", > 500"moderate rain", else "heavy rain" — include this label in every Telegram alert.
  • Medium: Implement a rain duration tracker: record the start time when rain is detected and the end time when it stops — send a Telegram message when rain stops reporting how long it lasted.
  • Advanced: Build a 24-hour rainfall chart: log AO values every minute to a list in Python — implement a /chart Telegram command that sends a text-based bar chart of rainfall intensity per hour over the last 24 hours.

※ OUR MESSAGES

  • As freelancers, We are AVAILABLE for HIRE. See how to outsource your project to us
  • Please feel free to share the link of this tutorial. However, Please do not use our content on any other websites. We invested a lot of effort and time to create the content, please respect our work!