Cov txheej txheem:

AUTOMATIC PET FOOD DISPENSER: 9 Kauj Ruam
AUTOMATIC PET FOOD DISPENSER: 9 Kauj Ruam

Video: AUTOMATIC PET FOOD DISPENSER: 9 Kauj Ruam

Video: AUTOMATIC PET FOOD DISPENSER: 9 Kauj Ruam
Video: Автоматическая кормушка для кошек и собак. Автокормушка Automatic Pet Feeder 4PLDH5001 с таймером. 2024, Hlis ntuj nqeg
Anonim
AUTOMATIC PET FOOD DISPENSER
AUTOMATIC PET FOOD DISPENSER

Puas tau xav zoo li nkim sijhawm ntau dhau rau koj tus tsiaj? Puas tau hu xov tooj rau ib tus neeg los pub koj cov tsiaj thaum koj nyob rau hnub so? Kuv tau sim kho ob qho teeb meem no nrog kuv qhov haujlwm tam sim no hauv tsev kawm ntawv: Petfeed!

Khoom siv

Raspberry Pi 3b

Bar Load Cell (10kg)

HX711 Load Cell Amplifier

Waterlevel Sensor (https://www.dfrobot.com/product-1493.html)

Ultrasonic sib thooj Sensor

LCD 16-pin

2x stepper tsav 28byj-48

2x stepper tsav tsav ULN2003

Kauj ruam 1: Kev thaiv kab

Thaiv
Thaiv
Thaiv
Thaiv

ntau cabling ntawm no. Tawm koj cov jumper cables thiab pib pinning!

Kauj Ruam 2: Ua Kom Koj Li Load Cell Siv Tau

Ua kom koj lub Load Cell Siv Tau
Ua kom koj lub Load Cell Siv Tau

txhawm rau siv lub nra thauj khoom, thawj zaug peb yuav tsum txuas nws rau ob daim phiaj: hauv qab phaj, thiab phaj uas peb yuav ntsuas peb cov zaub mov.

Cov ntsia hlau uas koj xav tau yog ib khub M4 ntsia hlau nrog cov ntsia hlau sib dhos thiab ib khub ntawm M5 ntsia hlau nrog cov ntsia hlau sib dhos. Kuv siv lub laum me me los ua qhov.

(pic:

Kauj ruam 3: Normalized Database

Normalized Database
Normalized Database

cov ntaub ntawv los ntawm peb cov sensors yuav tsum tau khaws tseg hauv lub database. Txog cov nab nab cov ntaub ntawv txuas rau lub hauv paus: saib hauv qab no.

ces koj kuj xav tau cov ntaub ntawv teeb tsa:

[connector_python] neeg siv = * yourusername * host = 127.0.0.1 #if chaw nres nkoj hauv zos = 3306 tus password = * yourpassword * database = * yourdb * [application_config] driver = 'SQL Server'

Kauj Ruam 4: Coding Load Cell

ntshuam RPi. GPIO li GPIOimporting ntshuam lub sijhawm los ntawm hx711 ntshuam HX711 los ntawm helpers.stepperFood ntshuam StepperFood los ntawm pab. LCDWrite ntshuam LCDWrite los ntawm cov chaw khaws khoom.

Tom qab ntshuam tag nrho peb cov tsev qiv ntawv (nco ntsoov, peb siv HX711 Lub Tsev Qiv Ntawv los tsav lub xov tooj ntawm tes) peb tuaj yeem pib sau peb cov lej tiag

TARRA_CONSTANT = 80600

GRAM_CONSTANT = 101

Txhawm rau nrhiav tawm peb qhov tsis sib xws, xub teeb tsa TARRA_CONSTANT = 0 thiab GRAM_CONSTANT = 1.

Tom ntej no peb yuav tsum nrhiav kom paub tus nqi peb lub xov tooj ntawm tes nyeem thaum tsis muaj dab tsi raug hnyav. Tus nqi no yuav yog TARRA_CONSTANT.

Raws li rau GRAM_CONSTANT, tsuas yog coj yam khoom koj paub qhov hnyav ntawm (kuv siv pob ntawm spaghetti's), ntsuas nws thiab faib cov load cell nyeem nrog qhov hnyav ntawm qhov khoom. Rau kuv qhov no yog 101.

chav kawm LoadCell (threading. Thread):

def _init _ (tus kheej, qhov (socket), lcd): threading. Thread._ init _ (self) self.hx711 = HX711 (dout_pin = 5, pd_sck_pin = 6, channel = 'A', nce = 64) self.socket = socket self.lcd lcd = lwd

nov peb pib qib LoadCell thiab qhia cov pins.

def khiav (tus kheej):

sim: thaum Muaj Tseeb: self.hx711.reset () # Ua ntej peb pib, rov pib dua HX711 (tsis ua raws qhov xav tau) ntsuas_avg = sum (self.hx711.get_raw_data ()) / 5 hnyav = puag ncig ((ntsuas_avg - TARRA_CONSTANT) / GRAM_CONSTANT, 0) print ("hnyav: {0}". Hom ntawv (hnyav)) DataRepository.insert_weight (hnyav) data_weight = DataRepository.get_data_sensor (3) historyId = data_weight ["SensorsHistory"] db_weight = data_weight ["tus nqi"] actionTime = data_weight ["actionTime"] self.socket.emit ('data_weight', {"id": historyId, "Weight": db_weight, "Sijhawm": DataRepository.serializeDateTime (actionTime)}) print ("zou moeten emitten") writeWeight = "qhov hnyav:" + str (db_weight) msg = "PETFEED" LCDWrite.message () yog int (db_weight [:-2]) <= 100: StepperFood.run () time.s pw (20) tshwj tsis yog kev zam raws li e: luam tawm ("Yuam kev nrog qhov hnyav" + str (e))

Kauj Ruam 5: Coding Dej Sensor

ntshuam sij hawm ntshuam xov xov los ntawm chaw cia khoom. DataRepository ntshuam DataRepository los ntawm RPi ntshuam GPIOGPIO.setmode (GPIO. BCM) GPIO.setwarnings (Cuav) GPIO_Water = 18 GPIO.setup (GPIO_Water, GPIO. IN) chav WaterSensor (threading. Thread): def _in tus kheej, qhov (socket): threading. Thread._ init _ (self) self.socket = socket self.vorige_status = 0 def run (self): sim: thaum Muaj tseeb: dej = self.is_water () print (dej) xwm txheej = dej [" xwm txheej "] ua = dej [" ua "] DataRepository.insert_water (str (xwm txheej), nqis tes ua) data_water = DataRepository.get_data_sensor (2) historyId = data_water [" SensorsHistory "] tus nqi = data_water [" tus nqi "] yog tus nqi == "0": value = "te weinig water" else: value = "genoeg water" actionTime = data_water ["actionTime"] self.socket.emit ('data_water', {"id": historyId, "value": tus nqi, "Sijhawm": DataRepository.serializeDateTime (actionTime), "action": action}) time.sleep (5) tshwj tsis yog Kev zam raws li ex: print (ex) print ('error bij watersensor') def is_water (self): status = GPIO.input (GPIO_Wate r) yog self.vorige_status == 0 thiab xwm txheej == 1: luam tawm ('dej gedetecteerd') sensorData = {"xwm txheej": xwm txheej, "nqis tes ua": "dej gedetecteerd"} self.vorige_status = xwm txheej xwm txheej = GPIO.input (GPIO_Water) yog tus kheej.vorige_status == 1 thiab xwm txheej == 1: luam tawm ('dej aanwezig') sensorData = {"xwm txheej": xwm txheej, "ua": "dej aanwezig"} xwm txheej = GPIO.input (GPIO_Water) yog self.vorige_status == 1 thiab xwm txheej == 0: print ('dej weg') sensorData = {"xwm txheej": xwm txheej, "ua": "dej weg"} self.vorige_status = xwm txheej xwm txheej = GPIO.input (GPIO_Water) yog self.vorige_status == 0 thiab xwm txheej == 0: print ('startpositie') xwm txheej = GPIO.input (GPIO_Water) sensorData = {"status": status, "action": "startpositie"} return sensorData

Kauj Ruam 6: Coding Qhov Sib Cais Sensor

ntshuam sij hawm ntshuam xov xov los ntawm chaw cia khoom. DataRepository ntshuam DataRepository los ntawm RPi ntshuam GPIO GPIO.setmode (GPIO. BCM) GPIO.setwarnings (Cuav) GPIO_Trig = 4 GPIO_Echo = 17 GPIO.setup (GPIO_Trig, GPIO. OUT) GPIO.setup (GPIO_Echo, GPIO_Echo,. IN) def tam sim no_milli_time (): rov qab int (puag ncig (sijhawm.time () * 1000)) chav kawm UltrasonicSensor (xov xov. Xov): def _init _ (tus kheej, qhov (socket)): threading. Thread._ init _ (self) self.socket = socket def run (tus kheej): sim: last_reading = 0 interval = 5000 thaum Tseeb: yog tam sim no_milli_time ()> last_reading + interval: dist = self.distance () print ("Ntsuas nrug = %.1f cm" % deb) DataRepository. insert_proximity (dist) data_prox = DataRepository.get_data_sensor (1) historyId = data_prox ["SensorsHistory"] prox = data_prox ["value"] actionTime = data_prox ["actionTime"] self.socket.emit ('data_proximity', {"id": historyId, "Proximity": prox, "Time": DataRepository.serializeDateTime (actionTime)}) last_reading = current_milli_time () tsuas yog Kev zam raws li ex: print (ex) de f nrug (tus kheej): # teeb tsa rau HIGH GPIO.output (GPIO_Trig, Tseeb) # teeb tsa tom qab 0.01ms rau LOW time.sleep (0.00001) GPIO.output (GPIO_Trig, Cuav) PibTime = time.time () StopTime = time.time () # txuag StartTime thaum GPIO.input (GPIO_Echo) == 0: StartTime = time.time () # txuag lub sijhawm tuaj txog thaum GPIO.input (GPIO_Echo) == 1: StopTime = time.time () # sijhawm sib txawv ntawm qhov pib thiab tuaj txog TimeElapsed = StopTime - StartTime # sib npaug nrog lub suab sonic (34300 cm / s) # thiab faib ua 2, vim tias muaj thiab nrug nrug = (TimeElapsed * 34300) / 2 rov qab nrug

Kauj Ruam 7: Coding Stepper Motors

ntshuam RPi. GPIO li GPIOimport lub sij hawm ntshuam threading GPIO.setmode (GPIO. BCM) GPIO.setwarnings (Cuav) control_pins = [12, 16, 20, 21] rau tus pin hauv control_pins: GPIO.setup (tus pin, GPIO. OUT) GPIO.output (pin, 0) halfstep_seq =

Txoj cai no rov siv tau rau lwm tus neeg tsav lub zog, tsuas yog teeb tus lej tus lej tswj rau lawv tus lej rov qab thiab hloov npe chav kawm rau StepperWater:

Kauj Ruam 8: Coding LCD

Ntau tus lej, tab sis peb yuav luag tiav.

Chav kawm LCD suav nrog ua cov ntaub ntawv LCD.py

los ntawm helpers. LCD ntshuam LCD

E = 26 RS = 25 D0 = 19 D1 = 13 D2 = 24 D3 = 22 D4 = 23 D5 = 8 D6 = 7 D7 = 10 lcd = LCD (E, RS, [D0, D1, D2, D3, D4, D5), D6, D7]) chav LCDWrite: def message (msg): sim: luam tawm ("sim") lcd.init_LCD () lcd.send_instruction (12) lcd.clear_display () lcd.write_message (msg, '1') tshwj tsis yog: print ("yuam kev LCDWrite")

Kauj Ruam 9: Qhov Kawg

Qhov Kawg
Qhov Kawg
Qhov Kawg
Qhov Kawg

qhov kawg: yuav ua li cas peb kos nws li vs. nws xaus li cas.

Pom zoo: