]> vault307.fbx.one Git - garage_door_sensor.git/commitdiff
measure distance and light in garage using veml7700
authorjimmy <jimipunk88@gmail.com>
Mon, 8 Jul 2024 23:58:07 +0000 (18:58 -0500)
committerjimmy <jimipunk88@gmail.com>
Mon, 8 Jul 2024 23:58:07 +0000 (18:58 -0500)
will be using pico as sensor pack. will read data from sensors,
then process over data (door{open/closed},light{on/off}),
send data to zero 2 w over usb. zero will host webpage
displaying status of DOOR and LIGHT.

distanceLux.py [new file with mode: 0644]

diff --git a/distanceLux.py b/distanceLux.py
new file mode 100644 (file)
index 0000000..1cdb2b7
--- /dev/null
@@ -0,0 +1,34 @@
+from machine import Pin, I2C, time_pulse_us
+import veml7700, time
+
+i2c = I2C(0, scl=Pin(1), sda=Pin(0), freq=10000) # connected on i2c0
+
+veml = veml7700.VEML7700(address=0x10, i2c=i2c, it=100, gain=1/8)
+
+def measure():
+    lux_val = veml.read_lux()
+    print(lux_val)
+    return(lux_val)
+
+SOUND_SPEED=340
+TRIG_PULSE_DURATION=10
+
+trig_pin=Pin(3, Pin.OUT)
+echo_pin=Pin(2,Pin.IN)
+
+def distance():
+    trig_pin.value(0)
+    time.sleep_us(5)
+    trig_pin.value(1)
+    time.sleep_us(TRIG_PULSE_DURATION)
+    trig_pin.value(0)
+    
+    ultransonic_duration=time_pulse_us(echo_pin,1,30000)
+    distance_cm=SOUND_SPEED*ultransonic_duration/20000
+    print(distance_cm)
+    return(distance_cm)
+
+while True:
+    measure()
+    distance()
+    
\ No newline at end of file