Closed N2E5c8 closed 1 year ago
Good morning,
Got climate-control working (3 relay array, 3.3V, 5V) but it only works when the mcu is USB hocked to the computer.
Further, when I implement commands import microdot, mm_wlan, pico_w_server relays falter (stop functioning).
Do you have any ideas of where the problem could be?
I would appreciate some help.
Germany, Hannover
axel
Here is some new code, that I made, copied.
from machine import Pin from pmon import PlantMonitor import time#, microdot
time.sleep(2) # PlantMonitor startup time
pm = PlantMonitor()
water_valve_pin = Pin(15, Pin.OUT)
nebulizer_pin = Pin(16, Pin.OUT)
fan_pin = Pin(17, Pin.OUT)
moisture = 25
humidity = 85
temp = 10
while True:
wetness = pm.get_wetness()
temp = pm.get_temp()
humidity = pm.get_humidity()
# Print sensor values
print("Wetness: {0} Temp: {1} Humidity: {2}".format(wetness, temp, humidity))
# Control water valve based on wetness value
if wetness <= moisture:
water_valve_pin.on() # Turn on the water valve
print("Watering plants ...")
else:
water_valve_pin.off() # Turn off the water valve
# Control fog nebulizer based on humidity
if humidity <= humidity:
nebulizer_pin.on() # Turn on fog
print("Nebulizer ...")
else:
nebulizer_pin.off() # Turn off fog
# Control fan based on temperature
if temp <= temp:
fan_pin.on() # Turn on the fan
print("Temp-control ...")
else:
fan_pin.off() # Turn off the fan
# Delay before the next reading
time.sleep(3)
Am 13.05.23 um 10:39 schrieb MonkMakes Support:
Hi, I'm glad you got it working and for sending over the code. At some point I'll make an example for switching on a pump. It's a very common use of the Plant Monitor.
Kind Regards, Simon.
On Sat, 13 May 2023, 08:53 Wolfgang Freiherr, [wf-detraphon@t-online.de](mailto:wf-detraphon@t-online.de) wrote:
Hello support team, Had a long chat with chtgtp-code, told it my plight and it gave me some code. The code worked so far for me but there are probably other issues that need to be solved. If interested here is the code. from machine import Pin from pmon import PlantMonitor import time # Create an instance of the PlantMonitor class pm = PlantMonitor() # Water valve pin water_valve_pin = Pin(15, Pin.OUT) # Define the threshold for soil moisture threshold_moisture = 24 while True: # Read sensor values wetness = pm.get_wetness() temp = pm.get_temp() humidity = pm.get_humidity() # Print sensor values print("Wetness: {0} Temp: {1} Humidity: {2}".format(wetness, temp, humidity)) # Control water valve based on wetness value if wetness <= threshold_moisture: water_valve_pin.on() # Turn on the water valve print("Watering plants...") else: water_valve_pin.off() # Turn off the water valve # Delay before the next reading time.sleep(1)
Hello Team members, First of all, I am not a professional in this area. I use Lubuntu 22.04 LTS 64bit, Thonny 3.3.14, Pyhton 3.10.6, Tk 8.6.12, Micropython v1.19.1-88-g74e33e714 on 2022-06-30 Raspberry Pi Pico W with RP2040.
This is my query, The Soil-monitor works well, all indicators running. I bought an array relay (3x) with 3.3V trigger, 5V VCC.
I ran the following command for each relay, pin 15,16,17.
from machine import Pin import time relay1 = Pin(15, Pin.OUT) while True: relay1.value(1) time.sleep(2) relay1.value(0) time.sleep(2
All relays switch, so connections are OK.
When I add the following commands to the test.py I get syntax errors.
test.py as follows:
time.sleep(2) # PlantMonitor startup time pm = PlantMonitor()
while True: w = pm.get_wetness() t = pm.get_temp() h = pm.get_humidity() print("Wetness: {0} Temp: {1} Humidity: {2}".format(w, t, h)) time.sleep(1)
relay1 = Pin(15, Pin.OUT) #relay is wired up to GP15 and GND
if w = 24 # watch for a wetness value of 24/100
relay1.value(1) # turn on the relay relay1(0) # turn off the relay
Thonny shell: SyntaxError: invalid syntax File "", line 19
After a few hours of fouling around with the code, I went to Chatgpt, Tipped in my query (relay code).
Chatgpt answered: The code snippet you provided has a few syntax errors. Here's the corrected version:
from machine import Pin
relay1 = Pin(15, Pin.OUT) w = 24
if w == 24: relay1.value(1) else: relay1.value(0)
Copy &, no syntax errors anymore. Pump relay not switching. I am at the end of my Latin, do you have any idea of how to get things working?
Thank you axel