Sensor works properly when not "put" on the device

All ESP8266 boards running MicroPython.
Official boards are the Adafruit Huzzah and Feather boards.
Target audience: MicroPython users with an ESP8266 board.
Post Reply
dhust
Posts: 40
Joined: Sun Jul 11, 2021 10:59 pm

Sensor works properly when not "put" on the device

Post by dhust » Fri Oct 22, 2021 6:19 pm

When I upload the code below to a Wemos D1 mini, using ampy put, the ultrasonic sensor gets false readings from across the room. But when I just run the code on the device, using ampy run. Any idea on why that might be?

Code: Select all

from hcsr04 import HCSR04
from machine import Pin, Signal
import utime

sensor = HCSR04(trigger_pin=4, echo_pin=14) # d2 = 4 - green, # d5 = 14 - yellow
scanner_power = Signal(12, Pin.OUT, invert=True)
scanner_power.on()
scanner = Signal(0, Pin.OUT, invert=True)

while True:
    distance = sensor.distance_cm()
    utime.sleep(0.1)
    print('Distance:', distance, 'cm')
    if 10 < distance < 30:
        print("Scanning...")
        scanner.on()
        utime.sleep(2)
        scanner.off()

Post Reply