Mundarija:

Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi: 6 qadam
Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi: 6 qadam

Video: Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi: 6 qadam

Video: Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi: 6 qadam
Video: Telefonning 15 ta siz bilmagan maxfiy kodlari/Телефоннинг сиз билмаган 15 та махфий кодлари 2024, Noyabr
Anonim
Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi
Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi
Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi
Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi
Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi
Umumiy nuqtai: Uydagi o'yin -kulgi va xavfsizlik tizimi

Ilova haqida

Bu IOT tizimi uy o'yin -kulgi va xavfsizlik tizimi.

  1. Xavfsizlik

    1. RFID kartasini bosing va kirishlar Firebase -ga saqlanadi.
    2. Agar ruxsat berilgan bo'lsa, siz tinchgina kirishingiz mumkin va rasm S3 -ga yuklanadi
    3. Agar ruxsatsiz bo'lsa, mudofaa bo'limi keladi va LCD displey sizga ruxsat yo'qligini aytadi.
  2. Mudofaa
    1. Boshqaruv panelidagi tugmani bosing.
    2. Lazer minoralari tasodifiy portlash va tezlikda hujum qiladi.
  3. O'yin -kulgi

    1. Agar harakat aniqlansa, o'yin boshlanadi.
    2. Foydalanuvchi o'yinni o'ynaganidan so'ng, hisob Firebase -ga saqlanadi.
    3. LDR qiymatlari olinadi va asboblar panelida chiqariladi.

Bu dasturni IBM Node-Red veb-serveri orqali boshqarish va ko'rish mumkin. Biz AWS va IBM Cloud Services -dan foydalanamiz va Firebase -dan ma'lumotlar bazamiz sifatida foydalanganmiz.

Ta'riflanadigan qadamlar haqida qisqacha ma'lumot

  • Uskuna talablari
  • Xavfsizlik - RFID kiritish va tasvirni aniqlash dasturidan foydalanadigan xavfsizlik tizimini qanday yaratish kerak
  • Mudofaa - Lazerli minorani qanday yaratish kerak
  • O'yin -kulgi - Simon aytadigan o'yinni qanday yaratish kerak
  • IBM Bluemix -dagi IOT App Watson - Qanday qilib barcha tizimlarni bitta boshqaruv paneliga birlashtirish mumkin

Davom eting va ushbu loyihani qanday yaratish haqida batafsil tushuntirish uchun pdf faylga kiring.

1 -qadam: Uskuna talablari

Bu sizga kerak bo'ladi

  1. Xavfsizlik

    • 1 Raspberry Pi
    • 1 LCD
    • 1 RFID o'quvchi
    • 1 PiCam
    • 2 ta RFID karta/tugma
    • X Ayol -> Erkak o'tish kabellari
  2. Mudofaa
    • 1 Raspberry Pi
    • 2 10 ㏀ rezistor (tugmalar uchun)
    • 2 mikro -servo
    • 1 650nm lazer uzatuvchi moduli
    • 2 bosish tugmasi
    • 1 Buzzer
    • 3 ta kichik kauchuk bantlar/kabel bog'lamlari (mahkamlash uchun)
    • X Ayol -> Erkak o'tish kabellari
    • X Oddiy o'tish kabellari
    • 1 tranzistor
    • 1 kondansatör
  3. O'yin -kulgilar

    • 1 Raspberry Pi
    • 3 1, qarshilik (LEDlar uchun)
    • 1 10㏀ qarshilik (LDR uchun)
    • 3 ta LED (turli xil ranglar)
    • 3 tugma
    • 1 LDR
    • 1 LCD
    • 1 Pir harakat sensori
    • X Ayol -> Erkak o'tish kabellari
    • X Oddiy o'tish kabellari

2 -qadam: Xavfsizlik

Xavfsizlik
Xavfsizlik
Xavfsizlik
Xavfsizlik
Xavfsizlik
Xavfsizlik

Xavfsizlik tizimi uskunalarini yaratish

Devorlarni chizish diagrammasida ko'rsatilgandek ulang

Xavfsizlik tizimi uchun dasturiy ta'minot yaratish

  1. Biror narsa yaratish orqali AWS -ni sozlang
  2. AWS Python kutubxonasini o'rnating
  3. LCD kutubxonasini o'rnating
  4. RFID kutubxonasini o'rnating
  5. Firebase -ni o'rnatish
  6. S3 saqlash joyini sozlash
  7. Raspberry Pi -ga Boto -ni o'rnating
  8. AWS ClI -ni Raspberry Pi -ga o'rnating
  9. AWS hisob ma'lumotlarini yarating
  10. AWS -ni sozlash
  11. Security.py faylini RPi -ga yuklang
  12. Imagerecognition.py faylini RPi -ga yuklang

security.py - bu rfid kirishini o'qiy oladigan va foydalanuvchi buzg'unchilik qiladimi yoki yo'qligini aniqlaydigan kod. Agar foydalanuvchi aniqlansa, rasm olinadi va s3 ga yuklanadi. Kod, shuningdek, aws MQTT -da mavzuni e'lon qiladi

3 -qadam: himoya

Mudofaa
Mudofaa
Mudofaa
Mudofaa
Mudofaa
Mudofaa

Lazer minorasi uskunalarini yaratish

  1. Biz 2 ta servo va 1 ta lazer moduli yordamida lazerli minorani yaratamiz
  2. Devorlarni chizish sxemasida ko'rsatilgandek ulang

Lazerli minorali dasturiy ta'minot yaratish

Quyidagi kod lazerli minorani tasodifiy yo'nalishlarda, tasodifiy portlashlar va tezlikda otishga imkon beradi

laserturret.py

gpiozero importidan LED, Buzzer, Tugma, Servoimport signalining import pauzasidan import vaqti tasodifiy

#LED = LED (12)

#pir = MotionSensor (19, sample_rate = 5, queue_len = 1) buzzer_pin = Buzzer (17) hujum = Button (5, pull_up = False) #reset = Button (6, pull_up = False) servo1 = Servo (18) servo2 = Servo (24)

def ledON ():

led.on () print ("LED yoniq") def ledOFF (): led.off () chop etish ("LED o'chirilgan")

def Fire ():

chop etish ("qurollar issiq") buzzer_pin.on () time.sleep (0.1) buzzer_pin.off ()

def laserturret ():

timeBetweenBurst = random.uniform (0.2, 1) timeBetweenShots = random.uniform (0.05, 0.2) servo1start = random.randrange (-1, 1) servo1end = random.randrange (-1, 1) servo2start = random.randrange (-1, 1) servo2end = random.randrange (-1, 1) numShots = random.randrange (5, 20) servo1change = (servo1end - servo1start)/numShots servo2change = (servo2end - servo2start)/numShots servo1.value = servo1start servo2.value = servo2start time.sleep (0.1) tortishish = 0 detal = [timeBetweenBurst, timeBetweenShots, servo1.value, servo2.value, numShots] otish paytida bosib chiqarish (tafsilot) <numshots: shot+= "1" servo1.value = "servo1start" servo2.value = "servo2start" servo1start = "servo1change" servo2start = "servo2change" fire () = "" time.sleep (timebetweenshots) = "" time.sleep (timebetweenburburst)

eslatmalar = {

'B0': 31, 'C1': 33, 'CS1': 35, 'D1': 37, 'DS1': 39, 'EB1': 39, 'E1': 41, 'F1': 44, 'FS1 ': 46,' G1 ': 49,' GS1 ': 52,' A1 ': 55,' AS1 ': 58,' BB1 ': 58,' B1 ': 62,' C2 ': 65,' CS2 ': 69, 'D2': 73, 'DS2': 78, 'EB2': 78, 'E2': 82, 'F2': 87, 'FS2': 93, 'G2': 98, 'GS2': 104, 'A2': 110, 'AS2': 117, 'BB2': 123, 'B2': 123, 'C3': 131, 'CS3': 139, 'D3': 147, 'DS3': 156, 'EB3 ': 156,' E3 ': 165,' F3 ': 175,' FS3 ': 185,' G3 ': 196,' GS3 ': 208,' A3 ': 220,' AS3 ': 233,' BB3 ': 233, 'B3': 247, 'C4': 262, 'CS4': 277, 'D4': 294, 'DS4': 311, 'EB4': 311, 'E4': 330, 'F4': 349, 'FS4': 370, 'G4': 392, 'GS4': 415, 'A4': 440, 'AS4': 466, 'BB4': 466, 'B4': 494, 'C5': 523, 'CS5 ': 554,' D5 ': 587,' DS5 ': 622,' EB5 ': 622,' E5 ': 659,' F5 ': 698,' FS5 ': 740,' G5 ': 784,' GS5 ': 831, 'A5': 880, 'AS5': 932, 'BB5': 932, 'B5': 988, 'C6': 1047, 'CS6': 1109, 'D6': 1175, 'DS6': 1245, 'EB6': 1245, 'E6': 1319, 'F6': 1397, 'FS6': 1480, 'G6': 1568, 'GS6': 1661, 'A 6 ': 1760,' AS6 ': 1865,' BB6 ': 1865,' B6 ': 1976,' C7 ': 2093,' CS7 ': 2217,' D7 ': 2349,' DS7 ': 2489,' EB7 ': 2489, 'E7': 2637, 'F7': 2794, 'FS7': 2960, 'G7': 3136, 'GS7': 3322, 'A7': 3520, 'AS7': 3729, 'BB7': 3729, 'B7': 3951, 'C8': 4186, 'CS8': 4435, 'D8': 4699, 'DS8': 4978}

def buzz (chastota, uzunlik): #"buzz" funktsiyasini yarating va uni balandligi va davomiyligi bilan ta'minlang)

agar (chastota == 0):

time.sleep (uzunlik) qaytish davri = 1.0 / chastota #chastotali kechikishValue = period / 2 #to'lqinning yarmi uchun vaqtni hisoblang sonlar = int (uzunlik * chastota) #to'lqinlar soni = i diapazonda davomiylik x chastotasi (numCycles)): #dan pastadirni boshlang buzzer_pin.on () time.sleep (delayValue) buzzer_pin.off () time.sleep (delayValue)

def play (ohang, temp, pauza, p = 0.800):

i uchun diapazonda (0, len (ohang)): # Qo`shiq notasini ijro etishDuration = temp/temp buzz (melodiya , noteDuration) # Qo`shiq notasi davomida chastotani o`zgartirish pauzaBotweenNotes = noteDuration * pauza vaqti. uxlash (pauzaBetweenNotes)

rost bo'lsa:

laserturret () tanaffus;

4 -qadam: O'yin -kulgi

O'yin -kulgi
O'yin -kulgi
O'yin -kulgi
O'yin -kulgi
O'yin -kulgi
O'yin -kulgi

O'yin -kulgi uskunalarini yaratish

Biz Simon aytadigan tugmachali o'yinni yaratamiz, u LEDlarning yonish sxemasiga amal qilishi va tegishli tugmachalarni bosishi kerak. U boshqaruv panelida keyingi foydalanish uchun ballar va vaqt tamg'asini NoSQL firebase ma'lumotlar bazasiga yuklaydi.

Zanjirlarni Fritzing diagrammasida ko'rsatilgan tarzda ulang.

O'yin -kulgi dasturini yaratish

o'yin -kulgi

import RPi. GPIO = 'h5Sis7TXdoUVncrpjSzGAvhBH' CONSUMER_SECRET = 'ZfDVxc4aTd9doGmBQO3HiSKKzxSTKT4C3g0B3AGx8eETCJm2rY' ACCESS_KEY = 'Firebase import Firebase CONSUMER_KEY dan sana import DATETIME dan vaqt import uyqudan subprocess import qo'ng'iroq dan rpi_lcd import displeyda dan GPIOimport zarrachalar import vaqt import tasodifiy import OS import tweepy sifatida 988333099669901312- YDLEQN1weW2n1JP4lxJcFPppCsbvzQh 'ACCESS_SECRET =' K2IlUPur6jx7DO5S0HhhZW29H5AQFOvkMMevSsk9ZzwLk 'auth = tweepy. OAuthHandler (CONSUMER_KEY, CONSUMER_SECRET) auth.secure = True auth.set_access_token (ACCESS_KEY, ACCESS_SECRET) API = tweepy. API (auth) Firebase = firebase. FirebaseApplication («https:// iotca2 -12f48.firebaseio.com ', Yo'q) lcd = LCD () lcd.text (' Xursand bo'ling! ', 1) lcd.text (' Omad! ', 2) uxlash (1) # Qizil, Sariq, Yashil LIGHTS = [40, 38, 36] TUGMALAR = [37, 33, 35] QAYDLAR = ["E3", "A4", "E4"] # o'zgarishi mumkin, bu o'yin tezligiga ta'sir qiladi = 0,5 # bayroqlar o'yin signallari uchun ishlatiladi. status is_displaying_pattern = Noto'g'ri is_won_curr ent_level = False is_game_over = False # o'yin holati current_level = 1 current_step_of_level = 0 model = def initialize_gpio (): GPIO.setmode (GPIO. BOARD) GPIO.setup (LIGHTS, GPIO. OUT, initial = GPIO. LOW) GPIO. (3) oralig'idagi i uchun sozlash (BUTTONS, GPIO. IN, pull_up_down = GPIO. PUD_DOWN): GPIO.add_event_detect (BUTTONS , GPIO. FALLING, verify_player_selection) def verify_player_selection (channel): global current_step_le_level_level_level_level is_game_over if is_displaying_pattern and is_won_current_level and not_game_over: flash_led_for_button (channel) if channel == BUTTONS [pattern [current_step_of_level]: current_step_of_level += 1 if current_step_vel_level_level_level_leve flash_led_for_button (button_channel): led = LIGHTS [BUTTONS.index (button_channel)] GPIO.output (led, GPIO. HIGH) time.sleep (0.4) GPIO.output (led, GPIO. LOW) def add_new_color_to_pattern (): global is_won jingalak rent_step_of_level is_won_current_level = False current_step_of_level = 0 next_color = random.randint (0, 2) pattern.append (next_color) def display_pattern_to_player (): global is_displaying_pattern is_displaying GPU: GPIO.output (LIGHTS [pattern , GPIO. HIGH) time.sleep (speed) GPIO.output (LIGHTS [pattern , GPIO. LOW) time.sleep (speed) is_displaying_pattern = Noto'g'ri def wait_for_player_to_repeat_pattern (): is_won_current_level va is_game_over emas esa: daf reset_board_for_new_game time.sleep (0,1) (): global is_displaying_pattern, is_won_current_level, is_game_over global current_level, current_step_of_level, namuna is_displaying_pattern = FALSE is_won_current_level = FALSE is_game_over = FALSE current_level = 1 current_step_of_level = 0 namuna = GPIO.output (LIGHTS, GPIO. LOW) def send_data (ball): lcd.text ('O'yin oxiri', 1) lcd.text ('Tez orada ko'rishguncha!', 2) datestr = str (datetime. now ()) while True: chop etish (datestr) print (score) data = {'Date': datestr, 'Score': score} result = firebase.post ('/scores/', data) print (result) if score> 2: status = 'Kimdir gol urdi' +(str (skor))+'ustiga'+datestr+'!' api.update_status (status = status) break start_game (): while True: add_new_color_to_pattern () display_pattern_to_player () wait_for_player_to_repeat_pattern () if is_game_over: send_data (current_level -!) bosma ("O'yin ustidan!" n).format (joriy daraja - 1)) uyqu (2) chop etish ("O'ynaganingiz uchun tashakkur! / n") lcd.text ('', 1) lcd.text ('', 2) tanaffus vaqti.sleep (2) def start_game_monitor (): t = threading. Thread (target = start_game) t.daemon = True t.start () t.join () def main (): try: os.system ('cls' if os.name == 'nt) 'else' clear ') print ("Yangi turni boshlang! / n") initialize_gpio () start_game_monitor () nihoyat: GPIO.cleanup () agar _name_ ==' _main_ ': main ()

5 -qadam: IOT App Watson IBM Bluemix -da [Birinchi qism]

Blumix IoT xizmatini o'rnating

  1. Shlyuz qurilmasi turini o'rnating
  2. Qurilmani sozlash

1 va 2 -qadamlarni 3 marta bajaring. Bitta RPi bitta bo'lim uchun (Xavfsizlik/Mudofaa/O'yin -kulgi)

Qizil tugunni o'rnating

Qizil tugunni ishlating

qizil tugunli boshlanish

  1. Gamburger menyusidagi palitrani boshqarish uchun o'ting (yuqori o'ngda)
  2. Quyidagi paletlarni yuklab oling

    1. qizil tugunli boshqaruv paneli
    2. tugun-qizil-hissa-olov bazasi
    3. tugun-qizil-hissa-ibm-vatson-iot

6 -qadam: Qizil oqim tugunlari

Qizil oqim tugunlari
Qizil oqim tugunlari
Qizil oqim tugunlari
Qizil oqim tugunlari
Qizil oqim tugunlari
Qizil oqim tugunlari
Qizil oqim tugunlari
Qizil oqim tugunlari

Fayllarni yuklab oling va qizil tugunga eksport qiling.

Xavfsizlik tuguni-qizil

hech kim

Himoya Rpi tugun-qizil

laserturret.txt

O'yin-kulgi Rpi tugun-qizil

  • o'yin -kulgi rpi flow.txt
  • ldr rpi oqim.txt

IBM Bluemix tugun-qizil

Tavsiya: