from machine import Pin, ADC
import utime
import onewire, ds18x20
import math
DIR_PIN = 16
STEP_PIN = 17
rows = [Pin(i, Pin.OUT) for i in range(4)]
cols = [Pin(i, Pin.IN, Pin.PULL_DOWN) for i in range(4, 8)]
dir_pin = Pin(DIR_PIN, Pin.OUT)
step_pin = Pin(STEP_PIN, Pin.OUT)
step_pin.value(0)
led_R = Pin(28, Pin.OUT)
led_G = Pin(27, Pin.OUT)
led_B = Pin(22, Pin.OUT)
adc = ADC(Pin(26))
passwordE = "ABCD"
BETA = 3950
dat = Pin(8)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(dat))
# Keypad layout
keys = [['1', '2', '3', 'A'],
['4', '5', '6', 'B'],
['7', '8', '9', 'C'],
['*', '0', '#', 'D']]
def scan_keypad():
for row in range(4):
rows[row].high()
for col in range(4):
if cols[col].value() == 1:
utime.sleep_ms(20)
if cols[col].value() == 1:
while cols[col].value() == 1:
utime.sleep_ms(10)
rows[row].low()
return keys[row][col]
rows[row].low()
return None
def read_temperature():
analog_value = adc.read_u16()
voltage_ratio = analog_value / 65535.0
# Bağlantıya göre uygun formül seçilmeli!
try:
resistance_ratio = 1 / voltage_ratio - 1 # Termistör GND tarafında ise
celsius = 1 / (math.log(resistance_ratio) / BETA + 1.0 / 298.15) - 273.15
return round(celsius, 2)
except (ZeroDivisionError, ValueError):
print("Hata: Sıcaklık hesaplanamadı! ADC:", analog_value)
return None
def read_password():
password = ""
while len(password) < 4:
key = None
while key is None:
key = scan_keypad()
print("Key Pressed:", key)
password += key
return password
def open_door(password, passwordE):
raw = adc.read_u16() # 0-65535 arasında analog değer
voltage = raw * 3.3 / 65535
if password == passwordE and voltage>0.65:
print("Şifre doğru, kapı açılıyor!")
led_B.value(1)
led_R.value(1)
utime.sleep(1)
led_B.value(0)
led_R.value(0)
dir_pin.value(1)
for _ in range(50):
step_pin.value(1)
step_pin.value(0)
utime.sleep_ms(5)
utime.sleep(5)
dir_pin.value(0)
for _ in range(50):
step_pin.value(1)
step_pin.value(0)
utime.sleep_ms(5)
while True:
raw = adc.read_u16() # 0-65535 arasında analog değer
voltage = raw * 3.3 / 65535 # Gerilime çevir (3.3V referans)
print("Ham Değer:", raw, "Gerilim:", voltage)
utime.sleep(1)
else:
print("Şifre yanlış!")
led_G.value(1)
led_B.value(1)
utime.sleep(1)
led_G.value(0)
led_B.value(0)
while True:
raw = adc.read_u16() # 0-65535 arasında analog değer
voltage = raw * 3.3 / 65535 # Gerilime çevir (3.3V referans)
print("Ham Değer:", raw, "Gerilim:", voltage)
utime.sleep(1)
print("4 karakterli şifreyi girin:")
password = read_password()
print("Girilen Şifre:", password)
open_door(password, passwordE)