Community project · Arduino Uno R3

Stacker

A circuit on the Arduino Uno R3 by @meganoorfajriyah, shared on Mokxi. Open it and press Run: it runs in your browser, free.

Runs in your browser. Free · 1 heart.

Stacker: the circuit as it is drawn in the Mokxi editor.

The code

The sketch exactly as it was saved. Open it in the editor and press Run: it compiles in your browser.

sketch.ino · uno1
// =============================================
// SUDAH PAS TOTAL:
// 700 - 1023  = KERING → POMPA HIDUP 🔥 ✅
// 0   - 400   = BASAH  → POMPA MATI 💧 ✅
// 401 - 699   = LEMBAB → DIAM ⚠️
// =============================================

#include <LiquidCrystal.h>
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); 

// PIN
const int pinSensor = A0;
const int pinRelay  = 8;

// BATAS SESUAI KEMAUAN
const int BATAS_BASAH = 400;
const int BATAS_KERING = 700;

// TEKS BERJALAN
void teksJalan(const char *pesan) {
  char buf[17];
  int pjg = strlen(pesan);
  if (pjg <= 16) {lcd.setCursor(0,1); lcd.print(pesan); return;}
  for(int i=0; i<=pjg-16; i++){
    lcd.setCursor(0,1); strncpy(buf, pesan+i,16); buf[16]=0; lcd.print(buf);
    delay(300); lcd.setCursor(0,1); lcd.print("                ");
  }
}

void setup() {
  pinMode(pinRelay, OUTPUT);
  digitalWrite(pinRelay, HIGH); // <-- AWALNYA UDAH DIBALIK
  lcd.begin(16,2); 
  lcd.clear();
  
  lcd.setCursor(0,0); lcd.print("  PENYIRAM AIR  ");
  lcd.setCursor(0,1); lcd.print("     OTOMATIS   ");
  delay(2000); 
  lcd.clear();
}

void loop() {
  // Baca rata biar stabil
  int baca = 0;
  for(int i=0; i<5; i++){baca += analogRead(pinSensor); delay(10);}
  int nilai = baca / 5;

  // TAMPIL ANGKA
  lcd.setCursor(0,0);
  lcd.print("Nilai:"); lcd.print(nilai); lcd.print("    ");

  // 🔴 BAGIAN INI UDAH DIBALIK BIAR RELAY NYALA PAS KERING:
  if (nilai >= BATAS_KERING) {
    // ✅ KERING (700-1023) → POMPA HIDUP
    digitalWrite(pinRelay, LOW);  // <-- DIBALIK DISINI
    teksJalan(">> KERING - POMPA HIDUP 🔥 <<");
  } 
  else if (nilai <= BATAS_BASAH) {
    // ✅ BASAH (0-400) → POMPA MATI
    digitalWrite(pinRelay, HIGH); // <-- DIBALIK DISINI
    teksJalan(">> BASAH - SUDAH MATI 💧 <<");
  }
  else {
    // ⚠️ LEMBAB (401-699) → TETAP MATI
    digitalWrite(pinRelay, HIGH);
    teksJalan(">> LEMBAB - TETAP DIAM ⚠️ <<");
  }

  delay(500);

Parts list

5 parts, plus the jumper wires. Every one is in the editor's parts bin.