PearTech2.0
Published © GPL3+

Irrigation System using ESP32 with Tuya link SDK

Create your own Irrigation System with TUYA link SDK!

IntermediateFull instructions provided4 hours4,330
Irrigation System using ESP32 with Tuya link SDK

Things used in this project

Hardware components

Espressif esp32
×1
Soil Moisture Sensor
×1
Relay board
Use only 1 relay
×1
Jumper wires (generic)
Jumper wires (generic)
×1

Software apps and online services

Arduino IDE
Arduino IDE
Python
Tuya IOT Cloud
VS Code
Microsoft VS Code
To edit the python file and better visualization.

Story

Read more

Code

Arduino IDE Code

Arduino
const int water = 33;// 
const int sc = 14;
const int sB = 26;
int incomingByte;      // 
int a=5;
int b=10;
int c=15;
int e=20;
void setup() {  // initialize serial communication:
  Serial.begin(115200); 
  pinMode(water, OUTPUT);
  pinMode(sc, INPUT);
  pinMode(sB, INPUT);}
void loop() {
  // see if there's incoming serial data:
  if (Serial.available() > 0) {
    // read the oldest byte in the serial buffer:
    incomingByte = Serial.read();
    if  (digitalRead(sc)==LOW){
      digitalWrite(water, HIGH);
      Serial.println(a);
      digitalWrite(sc, HIGH);      }
      if (digitalRead(sB)== LOW){
        digitalWrite(water, HIGH);
      Serial.println(b);
      digitalWrite(sB, HIGH);        }  
    if (incomingByte == 'D')  {
      digitalWrite(water, HIGH);      }
    if (digitalRead(sB)== HIGH){
      digitalWrite(water, LOW);
      Serial.println(c);
      digitalWrite(sB, LOW);      }
      if (digitalRead(sc)== HIGH){
        digitalWrite(water, LOW);
      Serial.println(e);
      digitalWrite(water, LOW);        }
   if (incomingByte == 'W')  {
      digitalWrite(water, LOW);   }  }
  delay(900); }

Python File

Python
#!/usr/bin/env python
from __future__ import print_function
import time
import coloredlogs
from tuyalinksdk.client import TuyaClient
from tuyalinksdk.console_qrcode import qrcode_generate
coloredlogs.install(level='DEBUG')
import sys
import serial
import time
 # Define the serial port and baud rate.
ser = serial.Serial('COM3', 115200) #ENTER YOUR PORT

client = TuyaClient(productid='Paste Your product ID',
                    uuid='—Your UUID from the downloaded License file',
                    authkey='—Your authkey from the downloaded License file ')
#ENTER YOUR CORRESPONDING DETAILS

def on_connected():
    print('Connected.')

def on_qrcode(url):
    qrcode_generate(url)

def on_reset(data):    print('Reset:', data)

def on_dps(dps):
    print('DataPoints:', dps)     
    if(dps == {'103':True}): 
        time.sleep(0.1)
        print("Water is On.")
        ser.write(b'W')
        print('ON')
    elif(dps =={'103':False}):
        dps=={'101':'Truee'}
        print("Water is oFF.")
        time.sleep(0.1)
        ser.write(b'D')
        print('OFF')
    go=ser.readline()
    
    print(go)
    co=go.decode('utf')

    print(co)
    if (co<'11'):
        dps['101']= str('need ')
        dps['102']= str('need ')
        print('sadd')
    elif (co > '14'): 
        dps['101'] = str('NO Need')
        dps['102'] = str('NO Need')
        print('saddgg')            
    client.push_dps(dps)

client.on_connected = on_connected
client.on_qrcode = on_qrcode
client.on_reset = on_reset
client.on_dps = on_dps

client.connect()
client.loop_start()
while True:
    
    time.sleep(1)

Tuya Link SDK

Credits

PearTech2.0

PearTech2.0

2 projects • 1 follower

Comments