Grove base hat for raspberry

why this dont work for me?
i got an error always like this:
File “testt.py”, line 6
sensor = seeed_dht.DHT(“11”, 5)
^
IndentationError: expected an indented block
or
just do nothing if i modify something
i want to make an iot smart garden (https://www.instructables.com/Raspberry-Pi-Powered-IOT-Garden/) i know grovepi+ is different
i would like to make this project with my raspberry zero and grove base hat for raspberry zero
but nothing wants to work

import time
import seeed_dht
from grove.grove_moisture_sensor import GroveMoistureSensor
def main():
 
    
    sensor = seeed_dht.DHT("11", 5)
    PIN = 0
    sensor = GroveMoistureSensor(PIN)
 
    while True:
        humi, temp = sensor.read()
        if not humi is None:
            print('DHT{0}, humidity {1:.1f}%, temperature {2:.1f}*'.format(sensor.dht_type, humi, temp))
        else:
            print('DHT{0}, humidity & temperature: {1}'.format(sensor.dht_type, temp))
            m = sensor.moisture
            if 0 <= m and m < 300:
                result = 'Dry'
            elif 300 <= m and m < 600:
                result = 'Moist'
            else:
                result = 'Wet'
            print('Moisture value: {0}, {1}'.format(m, result))
        time.sleep(1)
 
 
if __name__ == '__main__':
    main()

@salman I think you can help this user solve this problem.

1 Like

Hi @Coconutguy, Most of the programming languages like C, C++, and Java use braces { } to define a block of code. Python, however, uses indentation. Indentation refers to the spaces at the beginning of a code line, you might use the wrong Indentation,

what you can do is, copy and past the code into a text editor, and do the formatting! it’s done.

Now I did the indentation for you, you can check the by running and let me know your feedback.

import time
import seeed_dht from grove.grove_moisture_sensor 
import GroveMoistureSensor

def main():

    sensor = seeed_dht.DHT("11", 5)

    PIN = 0

    sensor = GroveMoistureSensor(PIN)

    while True:

        humi, temp = sensor.read()

        if not humi is None:

            print(

                'DHT{0}, humidity {1:.1f}%, temperature {2:.1f}*'.format(sensor.dht_type, humi, temp))

        else:

            print('DHT{0}, humidity & temperature: {1}'.format(

                sensor.dht_type, temp))

            m = sensor.moisture

            if 0 <= m and m < 300:

                result = 'Dry'

            elif 300 <= m and m < 600:

                result = 'Moist'

            else:

                result = 'Wet'

            print('Moisture value: {0}, {1}'.format(m, result))

        time.sleep(1)

if __name__ == '__main__':

    main()

You can find more about the Seeed DHT library here at https://github.com/Seeed-Studio/Seeed_Python_DHT , The repo also contain the example code too.