Cov txheej txheem:

SmartBin: 4 Kauj Ruam
SmartBin: 4 Kauj Ruam

Video: SmartBin: 4 Kauj Ruam

Video: SmartBin: 4 Kauj Ruam
Video: XIAOMI MI BAND 4 ПОЛНЫЙ ОБЗОР И НАСТРОЙКА 2024, Hlis ntuj nqeg
Anonim
Image
Image

Lub hom phiaj tseem ceeb ntawm txoj haujlwm no yog tsim cov khoom siv hluav taws xob uas siv tsawg kawg ib qho Raspberry Pi. Pab neeg no yog ua los ntawm 5 tus kws kho tshuab yav tom ntej thiab ib tus kws tshaj lij tshuab tshuab. Peb tes num suav nrog ua cov thoob khib nyiab uas qhib thiab kaw tau qhov tshwm sim los ntawm kev txav taw hauv qab lub suab ntsuas pom nyob hauv nruab nrab ntawm pem hauv ntej ntawm lub thoob khib nyiab. Wifi USB stick siv los xa cov ntaub ntawv mus rau lub vev xaib. Lub thoob no hu ua "The SmartBin". Cov vis dis aus lom zem saum toj no qhia peb qhov SmartBin tshiab.

Txhawm rau ua tiav txoj haujlwm no thiab SmartBin zoo kawg, ntau yam cuab yeej tsim nyog:

  • Ib lub 'meter'
  • Cov kua nplaum muaj zog
  • Ib daim kab xev nplaum
  • Ntoo pom
  • Tus ntsia hlau
  • Lub tshuab laum
  • Ib qho clamp
  • Riam

Kauj Ruam 1: Cov Khoom Siv SmartBin

Cov khoom siv SmartBin
Cov khoom siv SmartBin
Cov khoom siv SmartBin
Cov khoom siv SmartBin

SmartBin yog tsim los ntawm ntsuab, txiv kab ntxwv thiab liab LED teeb uas tau muab tso rau ntawm lub teeb ntawm sab laug ntawm lub thoob uas yuav qhia tias nws puv li cas. Cov teeb no yuav pom meej thiab yuav ceeb toom rau tus neeg siv thaum nws tsim nyog los hloov lub hnab ntim cov thoob khib nyiab. Cov lus programming siv yog Python. Qhov ntsuas ntsuas qib ntawm lub thoob raug xa mus rau lub vev xaib hauv qab no:

Nov yog cov ntsiab lus uas tau siv lawm tab sis koj tuaj yeem yooj yim nrhiav lwm txoj hauv kev daws teeb meem:

  • 1 Hauv ("viav vias npog" rau hauv)
  • 1 Servomotor qhib lub thoob
  • 1 Raspberry Pi 2
  • 2 Cov khoom siv hluav taws xob (5V lub xov tooj ntawm tes them nyiaj thiab 6V lub zog xa khoom) txhawm rau muab Raspberry Pi thiab servomotor
  • 1 Ultrasonic sensor txhawm rau ntsuas qib ntim ntawm lub thoob
  • Qee qhov LED los tso saib qib sau (4 ntsuab, 2 txiv kab ntxwv thiab 1 liab)
  • 1 Ultrasonic tsab ntawv tsa suab ntes kom txav tau
  • 1 16Gb SD-daim npav
  • Hluav taws xob resistors (10,000 Ohms, 2000 Ohms thiab 1000 Ohms)
  • 1 WiFi usb lo kom pab tau kev sib txuas wireless mus rau lub vev xaib.
  • 1 Breadboard thiab qee cov kab Raspberry

Tus nqi tsim khoom kwv yees yog 80 €.

Kauj Ruam 2: Kev Tsim Khoom ntawm Raspberry Box thiab LED Bar

Kev tsim khoom ntawm Raspberry Box thiab LED Bar
Kev tsim khoom ntawm Raspberry Box thiab LED Bar
Kev tsim khoom ntawm Raspberry Box thiab LED Bar
Kev tsim khoom ntawm Raspberry Box thiab LED Bar
Kev tsim khoom ntawm Raspberry Box thiab LED Bar
Kev tsim khoom ntawm Raspberry Box thiab LED Bar

Txhawm rau tsim lub thawv Raspberry, siv ntoo pom. Khaws txhua sab ntawm lub npov nrog rivets kom nws zoo nkauj. Raws li nws lub npe qhia, lub npov no nws yuav tsis tsuas yog Raspberry Pi tab sis tseem yuav suav nrog lub suab txav uas koj yuav tso rau hauv qab. Thaum lub thawv raug tsim, pleev xim rau xim tib yam li lub thoob. 3D tshuab luam ntawv tuaj yeem siv los tsim lub npov no.

Txog kev tsim khoom ntawm LED bar, siv cov kab hluav taws xob uas koj tau khawb qhov kom tso cov teeb LED teeb tsa. LED bar kuj tseem yuav tsum tau pleev xim. Thaum txhua yam npaj txhij, teeb tsa cov LEDs hauv cov ciav dej thiab ua qhov txuas hluav taws xob. Ua tib zoo saib tus lej kom raug txhua kab lus LED nrog daim kab xev nplaum. Nws yuav pab koj txheeb xyuas txhua tus LED thaum txuas kab.

Thaum kawg, muab lub npov thiab LED kab rau sab xub ntiag ntawm koj lub thoob.

Kauj Ruam 3: Tshooj Ntim

Qhov Hau Tshooj
Qhov Hau Tshooj
Qhov Hau Tshooj
Qhov Hau Tshooj

Hais txog lub hau ntawm lub thoob, thawj kauj ruam yog lo cov servomotor rau lub hau. Kev txuas ntxiv ntawm kev quab yuam yuav tsum tau ua yav dhau los. Qib yuav tsoo qhov nres uas tau xuas tes ua yav tas los. Txuas lub hau ntswj rau lub hau thiab ua lub qhov nyob rau hauv thiaj li yuav tuav lub ultrasonic sensor nyob rau hauv txoj haujlwm raug. Xyuas kom tseeb tias koj txuas cov hlua txuas ntawm lub hau kom raug.

Kauj Ruam 4: Software Tshooj thiab Tau Txais Cov Ntaub Ntawv

Software Tshooj thiab Tau Txais Cov Ntaub Ntawv
Software Tshooj thiab Tau Txais Cov Ntaub Ntawv
Software Tshooj thiab Tau Txais Cov Ntaub Ntawv
Software Tshooj thiab Tau Txais Cov Ntaub Ntawv
Software Tshooj thiab Tau Txais Cov Ntaub Ntawv
Software Tshooj thiab Tau Txais Cov Ntaub Ntawv

Hais txog qhov software ib feem, peb siv cov lus sau ua nab nab. Txoj haujlwm tau txais kev cawmdim hauv SD-daim npav uas yuav ua los ntawm Raspberry Pi thaum nws tau qhib. Cov phiaj xwm thaiv tau muaj nyob saum toj no. Daim duab Gpio pins muaj rau txhua hom raspberry ntawm qhov txuas hauv qab no:

www.raspberrypi-spy.co.uk/2012/06/simple-g…

Nws muaj peev xwm siv lub ntsuas hluav taws xob ultrasonic los hloov lub ntsuas lub zog, koj tsuas yog yuav tsum tsim "yog lub voj" hauv cov cai.

Raws li tau hais los saud, cov ntaub ntawv hais txog qib uas lub ntim ntim tau raug xa mus rau lub vev xaib tsim los ntawm wix.com. Hauv lub vev xaib no, koj tuaj yeem pom cov tab sib txawv uas sib sau ua ke cov tswv cuab, kho vajtse thiab nthuav qhia software,… tab nthuav tab yog qhov "Database" tab uas sau cov ntaub ntawv hais txog cov thoob khib nyiab ncaj qha los ntawm SmartBin thiab tsim kab ntawv nrog cov ntaub ntawv. Daim duab qhia txog kev hloov pauv ntawm qib ntawm kev txhaws. Nws tuaj yeem pom lossis rub cov ntaub ntawv los ntawm lub vev xaib. Qhov txuas hauv qab no yog lub vev xaib peb siv thiab yuav qhia koj yuav ua li cas nyeem thiab sau hauv google nplooj ntawv nrog nab nab:

www.makeuseof.com/tag/read-write-google-sh…

Hais txog "autorun ib feem" ntawm cov cai, sau rau hauv lub davhlau ya nyob twg: sudo nano/etc/xdg/lxsession/LXDE-pi/autostart

Tom qab ntawd, thaum kawg ntawm tsab ntawv uas nyuam qhuav qhib, sau ob kab kab no: nab nab /home/pi/main.py & nab nab /home/pi/csvcontrol.py &

Txhawm rau txuag lub aurorun, nias: C trl + O Tom qab ntawd, nias: Nkag Mus Tom Qab, nias: C trl + X

Sau raws li kab kab kawg: sudo reboot

Koj kuj tseem tuaj yeem rub daim ntawv txuas uas yog tag nrho cov nab npawb nab npawb siv rau txoj haujlwm. Ob tus lej tau khiav tib lub sijhawm!

Nov yog qhov main.py code:

ntshuam RPi. GPIO li GPIOimport datetime ntshuam lub sijhawm ntshuam csv

GPIO.setmode (GPIO. BCM)

GPIO.setwarnings (Cuav)

capteurP = 7

siv = 17

GPIO.setup (servo, GPIO. OUT)

GPIO.setup (capteurP, GPIO. IN)

pwm = GPIO. PWM (17, 50)

GPIO.setup (5, GPIO. OUT)

GPIO.setup (6, GPIO. OUT) GPIO.setup (13, GPIO. OUT) GPIO.setup (19, GPIO. OUT) GPIO.setup (20, GPIO. OUT) GPIO.setup (21, GPIO. OUT) GPIO.setup (26, GPIO. OUT)

Luas = 23

Ncha = 24

GPIO.setup (Trig, GPIO. OUT)

GPIO.setup (Echo, GPIO. IN)

GPIO.setwarnings (Cuav)

GPIO.output (5, Tsis tseeb)

GPIO.output (6, Cuav) GPIO.output (13, Cuav) GPIO.output (19, Cuav) GPIO.output (20, Cuav) GPIO.output (21, Cuav) GPIO.output (26, Cuav)

GPIO.output (Trig, False)

timeset = sijhawm.time ()

distance = 100 memory = 0 time.sleep (2) pwm.start (12.5)

thaum Muaj Tseeb:

timetac = time.time () yog GPIO.input (capteurP) thiab timetac-timeset0.9: pwm. ChangeDutyCycle (2.5) time.sleep (0.2) nco = -0.5 pwm. ChangeDutyCycle (0) timetac = time.time () time.sleep (0.5) yog timetac-timeset> 15 lossis nco> 0.4: yog nco> 0.4: pwm. ChangeDutyCycle (2.5) time.sleep (1) rau x hauv ntau (0, 1): # GPIO.output (Trig, Tseeb) time.sleep (0.01) GPIO.output (Trig, False)

thaum GPIO.input (Echo) == 0 thiab timetac-timeset <17: timetac = time.time () debutImpulsion = time.time ()

thaum GPIO.input (Echo) == 1:

finImpulsion = time.time () yog timetac-timeset <17: distance1 = round ((finImpulsion-debutImpulsion) * 340 * 100/2, 1) nrug2 = nrug yog (nrug 1-nrug 2) <1 thiab (nrug 2-nrug 1) 0.4: dis = puag ncig ((60-nrug)*5/6, 1) nrog qhib ('capteur.csv', 'w') raws li csvfile: capteurwriter = csv.writer (csvfile) time_str = datetime.datetime.strftime (datetime.datetime.now (), '%Y-%m-%d%H:%M:%S') print ('Sijhawm: {0} Quantitee: {1}'. format (time_str, dis)) capteurwriter. writerow ([time_str, dis]) nco = -0.1 yog qhov deb <52.5: GPIO.output (5, Tseeb) lwm qhov: GPIO.output (5, Cuav) yog nrug <45: GPIO.output (6, Muaj tseeb) lwm qhov: GPIO.output (6, Cuav) yog nrug <37.5: GPIO.output (13, Muaj tseeb) lwm qhov: GPIO.output (13, Cuav) yog nrug <30: GPIO.output (19, Muaj tseeb) lwm qhov: GPIO.output (19, Cuav) yog nrug <22.5: GPIO.output (20, Muaj tseeb) lwm qhov: GPIO.output (20, Cuav) yog nrug <15: GPIO.output (21, Muaj tseeb) lwm qhov: GPIO.output (21, Tsis tseeb) yog nrug deb <7.5: GPIO.output (26, Muaj tseeb) lwm qhov: GPIO.output (26, Tsis tseeb)

Nov yog tus lej csvcontrol.py. Tsis txhob hnov qab muab cov ntawv ".json" tsim rau hauv tib phau ntawv ntawm main.py. Cov ntaub ntawv ".json" tau tsim nrog google API. Lub screenshot muaj nyob hauv cov duab.

ntshuam datetimeimport lub sijhawm ntshuam csv ntshuam gspread

los ntawm oauth2client.service_account ntshuam ServiceAccountCredentials

los ntawm lub sijhawm ntshuam ntshuam ntshuam traceback

timec2 = 'lolx'

thaum muaj tseeb: sijhawm.sleep (5) loc = ('capteur.csv') nrog qhib (loc) li csvfile: readCSV = csv.reader (csvfile, delimiter = ',') rau kab hauv readCSV: luam tawm (kab [0]) timec = row [0] print (row [1]) distance = row [1] distance = float (str (distance)) if timec2! = timec: timec2 = timec print ('Sijhawm: {0} Quantitee: { 1} '. Hom ntawv (timec, nrug))

SCOPES = ['https://www.googleapis.com/auth/spreadsheets', "https://www.googleapis.com/auth/drive.file", "https://www.googleapis.com/auth/ tsav "]

daim ntawv pov thawj = ServiceAccountCredentials.from_json_keyfile_name ('client_secret.json', SCOPES) gc = gspread.authorize (credentials) wks = gc.open ("graph"). sheet1 wks = wks.append_row ((timec, nrug))

Pom zoo: