Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 82 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
82
Dung lượng
5,1 MB
Nội dung
MINISTRY OF EDUCATION AND TRAINING HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY AND EDUCATION FACULTY FOR HIGH QUALITY TRAINING GRADUATION THESIS ELECTRONIC AND COMMUNICATION DESIGN AND CONSTRUCT A MODEL OF VEHICLE TO MONITOR THE QUALITY OF ENVIRONMENT REMOTELY LECTURER: M.Eng NGO BA VIET STUDENT: LE THANH TUNG NGUYEN LE DUY SKL 0 Ho Chi Minh City, July 2022 HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY AND EDUCATION FACULTY FOR HIGH QUALITY TRAINING - - GRADUATION THESIS DESIGN AND CONSTRUCT A MODEL OF VEHICLE TO MONITOR THE QUALITY OF ENVIRONMENT REMOTELY LE THANH TUNG Student ID: 17141036 NGUYEN LE DUY Student ID: 17141002 Major: ELECTRONIC AND COMMUNICATION ENGINEERING TECHNOLOGY Advisor: NGO BA VIET, M.Eng Ho Chi Minh City, July 2022 HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY AND EDUCATION FACULTY FOR HIGH QUALITY TRAINING - - GRADUATION THESIS DESIGN AND CONSTRUCT A MODEL OF VEHICLE TO MONITOR THE QUALITY OF ENVIRONMENT REMOTELY LE THANH TUNG Student ID: 17141036 NGUYEN LE DUY Student ID: 17141002 Major: ELECTRONIC AND COMMUNICATION ENGINEERING TECHNOLOGY Advisor: NGO BA VIET, M Eng Ho Chi Minh City, July 2022 ii THE SOCIALIST REPUBLIC OF VIETNAM Independence – Freedom– Happiness -Ho Chi Minh City, July 30th, 2022 ADVISOR’S EVALUATION SHEET Student name: Le Thanh Tung Student ID: 17141036 Student name: Nguyen Le Duy Student ID: 17141002 Major: Electronics and Communication Engineering Technology Project title: Design and construct a model of vehicle to monitor the quality of environment remotely Advisor: M.Eng Ngo Ba Viet EVALUATION Content of the project: - Project completed on schedule The model works according to its intended purpose Strengths: - Students actively self-study to program hardware and applications In addition, students have good ability to design and construct electrical circuits Weaknesses: Approval for oral defense? (Approved or denied): Approved Overall evaluation: (Excellent, Good, Fair, Poor): Good Mark: 8.5 Ho Chi Minh City, July 30th , 2022 ADVISOR (Sign with full name) iii THE SOCIALIST REPUBLIC OF VIETNAM Independence – Freedom– Happiness -Ho Chi Minh City, July 30th, 2022 PRE-DEFENSE EVALUATION SHEET Student name: Le Thanh Tung Student ID: 17141036 Student name: Nguyen Le Duy Student ID: 17141002 Major: Electronics and Communication Engineering Technology Project title: design and construct a model of vehicle to monitor the quality of environment remotely Name of Reviewer: EVALUATION Content and workload of the project Strengths: Weaknesses: Approval for oral defense? (Approved or denied) Overall evaluation: (Excellent, Good, Fair, Poor) Mark: ……………… (in words: .) Ho Chi Minh City, day… month……year…… REVIEWER (Sign with full name) iii THE SOCIALIST REPUBLIC OF VIETNAM Independence – Freedom– Happiness -Ho Chi Minh City, July 30th, 2022 EVALUATION SHEET OF DEFENSE COMMITTEE MEMBER Student name: Le Thanh Tung Student ID: 17141036 Student name: Nguyen Le Duy Student ID: 17141002 Major: Electronics and Communication Engineering Technology Project title: Design and construct a model of vehicle to monitor the quality of environment remotely Advisor: M.Eng Ngo Ba Viet Name of Defense Committee Member: EVALUATION Content and workload of the project Strengths: Weaknesses: Overall evaluation: (Excellent, Good, Fair, Poor) Mark: ……………… ) (in Ho Chi Minh City, day… month… year COMMITTEE MEMBER (Sign with full name) iv words: HCMC University of Technology and Education Socialist Republic of Vietnam Faculty for High Quality training Independence - Liberty – Happiness Ho Chi Minh City, July 30th, 2022 PROJECT ASSIGNMENT Name of Members: Le Thanh Tung Student ID: 17141036 Nguyen Le Duy Student ID: 17141002 Training system: Regular university Major: Electronics and communication engineering technology Class: 17141CLA I NAME OF PROJECT: DESIGN AND CONSTRUCT A MODEL OF A VEHICLE TO MONITOR THE QUALITY OF THE ENVIRONMENT REMOTELY II ASSIGNMENT The original figures - Recognize the urgency and importance of the monitor and control system Conducting research, studying materials, current models related to the topic for comparison and improvement Content of implementation Task 1: Brainstorm and research related topics Task 2: Research and select components Task 3: Draw algorithm flowchart Write a program to communicate between the main microcontroller and peripheral devices Task 4: Design and build complete system model Run tests and calibrate the system Task 5: Write a report III DATE OF RECEIVING TASK: IV DATE OF TASK COMPLETION: V ADVISOR: M.Eng Ngo Ba Viet CHAIR OF THE PROGRAM ADVISOR (Sign with full name) (Sign with full name) v HCMC University of Technology and Education Socialist Republic of Vietnam Faculty for High Quality training Independence - Liberty – Happiness Ho Chi Minh City, July 30th, 2022 PROJECT IMPLEMENT SCHEDULE Name of Members: Le Thanh Tung Student ID: 17141036 Nguyen Le Duy Student ID: 17141002 Class: 17141CLA Name of project: Design and construct a model of a vehicle to monitor the quality of the environment remotely Week/Date 1st (11/3-18/3) Content Meet Instructor to disseminate regulations: choose topic, working time - Instructor conducts review of the topic 2st (19/3-25/3) - Write a summary of the requirements of the selected topic: Reasons and objectives of the topic, design content, limited parameters of the topic 3nd Write the plan and detail outlines for the topic (26/3-2/4) - Design block diagram rd - Design the principal diagram and explain the (3/4-9/3) function of each block vi Lecture Confirm - Search for knowledge, information about the 5th (29/3-4/4) temperature, humidity and CO2 concentration in the air - Find out the sensors used in the subject - Learn about how to write program to control car 6th (5/4-18/4) 7th (19/4-2/5) Connect and write code to push data to the web server Connect and write code to send data from Arduino to Raspberry 8th Research and learn about MJPEG to run Camera (3/5-9/5) 9th (10/5-16/5) 10th - Programming to connect operating modules in the system - Design background and control interface in web server (17/5-23/5) 11th (24/5-30/5) 12th (31/5-7/6) 13th (8/6-14/6) - Research, learn and use Hamachi for this project - Model Building 14th (15/6-21/6) vii 15th (22/6-30/6) - Implement, test and fix the Project - Write the report Complete the report and send it to Instructor to 16 th review and comment for the last time before (1/7-14/7) printing the report 17th Submit the report and slide PowerPoint (15/7-28/7) ADVISOR (Sign with full name) STUDENTS (Sign with full name) viii elif code == "left": HStep = print("left") elif code == "right": HStep = -5 print("right") return "OK" def timerfunc(): global HPulse,VPulse,HStep,VStep,pwm if(HStep != 0): HPulse += HStep if(HPulse >= 2500): HPulse = 2500 if(HPulse = 2500): VPulse = 2500 if(VPulse = 0) and (right = -100)): 52 GPIO.output(self.IN1,GPIO.LOW) GPIO.output(self.IN2,GPIO.HIGH) self.PWMA.ChangeDutyCycle(0 - right) if((left >= 0) and (left = -100)): GPIO.output(self.IN3,GPIO.LOW) GPIO.output(self.IN4,GPIO.HIGH) self.PWMB.ChangeDutyCycle(0 - left) if name ==' main ': Ab = AlphaBot() Ab.forward() try: while True: time.sleep(1) except KeyboardInterrupt: GPIO.cleanup() Code of Arduino #include //DHT config #define DHTPIN // what digital pin we're connected to #define DHTTYPE DHT11 // DHT 11 //#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321 //#define DHTTYPE DHT21 // DHT 21 (AM2301) DHT dht(DHTPIN, DHTTYPE); void setup() { Serial.begin(9600); dht.begin(); } 53 void loop() { float h = dht.readHumidity(); float t = dht.readTemperature(); float ppm = analogRead(A0); Serial.print(t); Serial.print(" "); Serial.print(h); Serial.print(" "); Serial.println(ppm); delay(1000); } Code of Python import serial #Serial imported for Serial communication import time #Required to use delay functions import sys import urllib.request as urllib3 myAPI = "SGZCEXUZZMB12VG2" ser = serial.Serial( port = '/dev/ttyUSB0', baudrate = 9600, parity = serial.PARITY_NONE, stopbits = serial.STOPBITS_ONE, bytesize = serial.EIGHTBITS, timeout = 1000 ) def main(): print ('starting ') baseURL = 'https://api.thingspeak.com/update?api_key=%s' % myAPI try: while True: # using ser.readline() assumes each line contains a single reading reading = ser.readline().decode('utf-8') # reading is a string whatever you want from here 54 #print(reading) cut_string = reading.split(' ') #print(cut_string) t = cut_string[0] h = cut_string[1] k = cut_string[2] print("Temperature:",t) print("Humidity:",h) print("PPM:",k) f = urllib3.urlopen('https://api.thingspeak.com/update?api_key=SGZCEXUZZMB12VG2' + "&field1=%s&field2=%s&field3=%s" % (t,h,k)) print (f.read()) f.close() except KeyboardInterrupt: ser.close() if name == ' main ': main() Code of servo #!/usr/bin/python import time import math import smbus # ============================================================================ # Raspi PCA9685 16-Channel PWM Servo Driver # ============================================================================ class PCA9685: # Registers/etc SUBADR1 = 0x02 SUBADR2 = 0x03 SUBADR3 = 0x04 55 MODE1 = 0x00 PRESCALE = 0xFE LED0_ON_L = 0x06 LED0_ON_H = 0x07 LED0_OFF_L = 0x08 LED0_OFF_H = 0x09 ALLLED_ON_L = 0xFA ALLLED_ON_H = 0xFB ALLLED_OFF_L = 0xFC ALLLED_OFF_H = 0xFD def init (self, address=0x40, debug=False): self.bus = smbus.SMBus(1) self.address = address self.debug = debug if (self.debug): print("Reseting PCA9685") self.write(self. MODE1, 0x00) def write(self, reg, value): "Writes an 8-bit value to the specified register/address" self.bus.write_byte_data(self.address, reg, value) if (self.debug): print("I2C: Write 0x%02X to register 0x%02X" % (value, reg)) def read(self, reg): "Read an unsigned byte from the I2C device" result = self.bus.read_byte_data(self.address, reg) if (self.debug): print("I2C: Device 0x%02X returned 0x%02X from reg 0x%02X" % (self.address, result & 0xFF, reg)) return result def setPWMFreq(self, freq): "Sets the PWM frequency" prescaleval = 25000000.0 # 25MHz 56 prescaleval /= 4096.0 # 12-bit prescaleval /= float(freq) prescaleval -= 1.0 if (self.debug): print("Setting PWM frequency to %d Hz" % freq) print("Estimated pre-scale: %d" % prescaleval) prescale = math.floor(prescaleval + 0.5) if (self.debug): print("Final pre-scale: %d" % prescale) oldmode = self.read(self. MODE1); newmode = (oldmode & 0x7F) | 0x10 # sleep self.write(self. MODE1, newmode) # go to sleep self.write(self. PRESCALE, int(math.floor(prescale))) self.write(self. MODE1, oldmode) time.sleep(0.005) self.write(self. MODE1, oldmode | 0x80) def setPWM(self, channel, on, off): "Sets a single PWM channel" self.write(self. LED0_ON_L+4*channel, on & 0xFF) self.write(self. LED0_ON_H+4*channel, on >> 8) self.write(self. LED0_OFF_L+4*channel, off & 0xFF) self.write(self. LED0_OFF_H+4*channel, off >> 8) if (self.debug): print("channel: %d LED_ON: %d LED_OFF: %d" % (channel,on,off)) def setServoPulse(self, channel, pulse): "Sets the Servo Pulse,The PWM frequency must be 50HZ" pulse = pulse*4096/20000 #PWM frequency is 50HZ,the period is 20000us self.setPWM(channel, 0, pulse) if name ==' main ': pwm = PCA9685(0x40, debug=True) 57 pwm.setPWMFreq(50) while True: # setServoPulse(2,2500) for i in range(500,2500,10): pwm.setServoPulse(0,i) time.sleep(0.02) for i in range(2500,500,-10): pwm.setServoPulse(0,i) time.sleep(0.02) Code of Web server AlphaBot > $(function(){ var isTouchDevice = "ontouchstart" in document.documentElement ? true : false; var BUTTON_DOWN = isTouchDevice ? "touchstart" : "mousedown"; var BUTTON_UP = isTouchDevice ? "touchend" : "mouseup"; $("button").bind(BUTTON_DOWN,function(){ $.post("/cmd",this.id,function(data,status){ }); }); $("button").bind(BUTTON_UP,function(){ $.post("/cmd","stop",function(data,status){ }); 58 }); $('input').change(function() { var speed = this.value; $.post('/cmd', {speed: speed});; }); }); button { margin: 10px 15px 10px 15px; width: 50px; height: 50px; } input { margin: 10px 15px 10px 15px; width: 50px; height: 50px; } AlphaBot Robot Web Control var ip_addr = document.location.hostname; document.write(""); 59 > Motor ControlServo Control > > 60 Appendices 2: Step 1: Turn on the system switch or plug in the power Step 2: After booting is complete, Raspberry will change the status in Hamachi to green (online), use that IP address to conduct remote via VNC Viewer Step 3: Run the program to start the camera, web server and sensor Step 4: After running the Web server program to control the vehicle, the code will generate a link :8000 Step 5: Follow the link and the user will go to the user interface, from which they can control the vehicle's operation and view environmental quality data through that website 61 62 S K L 0