Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

MAE 188 FWM Team B Final Binder

232 views

Published on

  • Be the first to comment

  • Be the first to like this

MAE 188 FWM Team B Final Binder

  1. 1. WHEELCHAIR INSTRUMENTATION University of California Irvine – MAE 188 JUNE 9, 2016 BONNIE GONZALEZ TUO HAN ERIN HO VICTOR MOROCHO BRIAN PHAM NICK VO
  2. 2. Table of Contents 1 Management.........................................................................................................................................1 Project Goal...................................................................................................................................1 Objective.......................................................................................................................................1 Company Contacts and Faculty Advisors......................................................................................2 Group Members............................................................................................................................3 Gantt Chart....................................................................................................................................4 2 Project Definition..................................................................................................................................4 Principal Goal ................................................................................................................................4 Requirements Document..............................................................................................................5 3 Preliminary Sensor and Module Research............................................................................................5 Wireless Communication Modules...............................................................................................5 3.1.1 RF Modules ...........................................................................................................................5 3.1.2 Bluetooth Module.................................................................................................................6 Strain Gauge..................................................................................................................................7 3.2.1 Definition of Strain & Strain Gauge:......................................................................................7 3.2.2 1.2 Physical operation:..........................................................................................................7 3.2.3 Theory ...................................................................................................................................8 Accelerometer...............................................................................................................................9 Hall Effect Sensor..........................................................................................................................9 4 Sensor Downselection.........................................................................................................................10 Strain Gauge Downselection.......................................................................................................10 Thermocouple Downselection....................................................................................................11 Accelerometer Downselection....................................................................................................12 Arduino Downselection...............................................................................................................13 RF Module Downselection..........................................................................................................13 BOM for the nRF24L01+ Assembly .............................................................................................14 Wiring Diagram ...........................................................................................................................15 Understanding the RF24 Settings ...............................................................................................19 Uploading and Troubleshooting the Code..................................................................................19 Opening Additional Transmitting Nodes within the Network ....................................................21 5 Strain Gauges ......................................................................................................................................25 Wiring schematics.......................................................................................................................27 Mounting instructions.................................................................................................................29 Wiring Notification..............................................................................................................................31 Test Results.................................................................................................................................32 6 K-Type Thermocouple.........................................................................................................................33 Thermocouples Description........................................................................................................33 Wiring 4 Thermocouples.............................................................................................................34 Thermocouple Mounting Instructions....................................................................................................35 Component .................................................................................................................................35 Materials Needed................................................................................................................................36 6.2.1 Instructions .........................................................................................................................36 7 MPU-6050 Accelerometer + Gyroscope .............................................................................................36 MPU-6050 Description................................................................................................................36 Wiring 4 MPU-6050 Sensors .......................................................................................................36 Accelerometer Mounting Instructions........................................................................................38
  3. 3. Materials Needed................................................................................................................................40 7.3.1 Instructions: ........................................................................................................................41 Calibrating MPU-6050 Sensor.....................................................................................................43 Accelerometer Results................................................................................................................44 8 Hall Effect Sensor................................................................................................................................45 10 Graphical User Interface .....................................................................................................................48 Introduction ................................................................................................................................48 Preliminary Research ..................................................................................................................49 10.2.1 Processing ...........................................................................................................................49 10.2.2 PLX-DAQ..............................................................................................................................49 10.2.3 MATLAB...............................................................................................................................50 11 Graphical User Interface Instructions: App Designer .........................................................................52 Steps to run the App ...................................................................................................................53 Debugging User Interface ...........................................................................................................57 Whenever a COM Port is being used and the user tries to utilize it again, the error message shown above, will appear. Pasting the following line of code will properly close all COM Ports: fclose(instrfind)...................................................................................................................................58 12 Cost Report .........................................................................................................................................58 13 Results.................................................................................................................................................59 Final Pin Assignment...................................................................................................................59 14 Appendices..........................................................................................................................................60 Distribution of Work ...................................................................................................................60 15 References ..........................................................................................................................................61 Datasheets ..................................................................................................................................61 Code Libraries .............................................................................................................................61 GUI Instructional videos..............................................................................................................61 16 Miscellaneous .....................................................................................................................................62 Accelerometer Components and References.............................................................................62 Thermocouple components and References..............................................................................62 Uxcell® 9mm x 5mm Probe Ring K Type Thermocouple Temperature Sensor ...........................................62 URBEST® K Type Wire Lead Measuring Thermocouple Sensor ...................................................................62 Strain Gauge Components and References ................................................................................63 nRF24L01+ Components and References ...................................................................................63 17 Arduino Codes.....................................................................................................................................63 Strain Gauge Calibrate Code.......................................................................................................63 Strain Gauge Function Code .......................................................................................................64 Accelerometer Function Code ....................................................................................................65 Final Code (Receiver) ..................................................................................................................71 Hall Effect Sensor........................................................................................................................76 Final Code (Transmitter) .............................................................................................................77
  4. 4. Table of Figures Figure 1. Snapshot of Bonnie's research on Bluetooth.................................................................................6 Figure 2: nRF24L01+ Diagram 1 (Breadboard)............................................................................................15 Figure 3: nRF24L01+ Diagram 1 (Schematic) ..............................................................................................16 Figure 4: nRF24L01+ Diagram 2 (Breadboard)............................................................................................17 Figure 5: nRF24L01+ Diagram 2 (Schematic) ..............................................................................................18 Figure 6. Breadboard View .........................................................................................................................27 Figure 7. Schematic View............................................................................................................................28 Figure 8. Front Left castor...........................................................................................................................29 Figure 9. Rear left axle ................................................................................................................................29 Figure 10. Breadboard Position ..................................................................................................................30 Figure 11. Magnetic Field Created by DC current.......................................................................................31 Figure 12. Bad example...............................................................................................................................31 Figure 13. Left Front Castor ........................................................................................................................32 Figure 14. Left Rear Wheel..........................................................................................................................32 Figure 15. Right Front Castor......................................................................................................................33 Figure 16. Right Rear Wheel .......................................................................................................................33 Figure 17. Rear Wheel's Axles.....................................................................................................................35 Figure 18. Castor Pivot Bearing...................................................................................................................35 Figure 19. MPU 6050 accelerometer and gyroscope..................................................................................36 Figure 20. 16 Channel Multiplexer..............................................................................................................36 Figure 21. Accelerometer placement diagram as viewed from the top of the wheelchair........................38 Figure 22. Close-up view of accelerometer placement on front wheel .....................................................39 Figure 23. Close-up view of accelerometer placement on back wheel......................................................39 Figure 24. Top view close-up of location A with arrows indicating the thin line of glue............................41 Figure 25. Top view of location A with proper orientation of accelerometer. Green arrows represent the direction that wires should be fed..............................................................................................................41 Figure 26. Front left castor..........................................................................................................................42 Figure 27. Red arrows Represent the direction the wires from the accelerometer should be fed. The yellow star is where the Arduino microcontroller will be mounted...........................................................43 Figure 28. Buttons referenced for steps 3 and 4. .......................................................................................44 Figure 29. Screenshot of the portion of the code that needs to be changed in step 5..............................44 Figure 30. Acceleration vs. Time Graph......................................................................................................45 Figure 31. Mounting cap and magnet.........................................................................................................46 Figure 32. Mounted magnet on the wheel .................................................................................................47 Figure 33. Magnet level with sensor...........................................................................................................47 Figure 34. Light indicator to check magnet activity....................................................................................48
  5. 5. Table of Tables Table 1. Requirements Document ................................................................................................................5 Table 2. BOM for nRF24L01+ Assembly......................................................................................................14 Table 3. BOM for Strain Gauge Assembly...................................................................................................25 Table 4. BOM for Thermocouple Assembly ................................................................................................36 Table 5. BOM for Accelerometer Assembly................................................................................................40 Table 6. BOM for Hall Effect Sensor............................................................................................................45 Table 7. Cost Analysis..................................................................................................................................58
  6. 6. 1 | P a g e 1 Management Project Goal The project goal is to improve the design and reliability of Free Wheelchair Mission’s GEN 2 wheelchair model through failure analysis. The failure analysis described in this report consist of the use of various sensors. These sensors are carefully placed in key areas of high stress and areas where failure more commonly occurs. The sensor data is carefully monitored on a daily basis for any drastic changes. The areas that experience high stress include the metal frame near the rear wheel axles as well as the area near the front castors. Another major failure occurs in the bearings in the front castor wheels, most likely due to high temperatures. Objective Design a system that measures key information from 4 wheelchairs simultaneously; including speed, tire pressure, temperature at bearings, vibration and strain on metal frame. The system must be battery powered and able to transmit the measured values to a computer wirelessly and in real time.
  7. 7. 2 | P a g e Company Contacts and Faculty Advisors Free Wheelchair Mission Don Schoendorfer dschoendorfer@freewheelchairmission.org FWM President and Founder Farzad Ahmadkhanlou Faculty Advisor farzad.a@uci.edu Josiah Auer jauer@freewheelchairmission.org FWM Mechanical Engineer Vince McDonell Faculty Advisors mcdonell@apep.uci.edu
  8. 8. 3 | P a g e Group Members Bonnie Gonzalez bonnniesg@uci.edu (323) 841-6452 Tuo Han Tuoh1@uci.edu (949)345-9456 Victor Morocho morocho@uci.edu (310)343-3793 Erin Ho erinch@uci.edu (949)285-8688 Nick Vo vopm@uci.edu (714)272-1993 Brian Pham Brianp1@uci.edu (714)905-4965
  9. 9. 4 | P a g e Gantt Chart 2 Project Definition Principal Goal The goal is to design a sensor system that measures and records key information about a wheelchair. The system will measure speed in RPM using a hall effect sensor, tire pressure of the rear wheels using pressure valve caps, acceleration near all four wheel axels using an accelerometer, and temperature near the bearing in the front castor wheels using thermocouples, and strain near all four wheel axels using unidirectional strain gauges. The data for all sensors should be transmitted wirelessly to a computer in real time and presented in an organized fashion on a monitor using a GUI.
  10. 10. 5 | P a g e Requirements Document Table 1. Requirements Document Property Measured Units Marginal Optimal Importance Pressure psi 30 50 5 Speed Accuracy mph 3 5 3 Frequency Hz 10 50 5 Bearing Temperature Accuracy ℃ (+/-) 3 (+/-) 1 5 Acceleration Accuracy 𝑚/𝑠2 (+/- )0.3 (+/-) 0.1 5 Strain Accuracy N/A (+/-) 5E-6 (+/-) 5E-7 5 Battery Life hr 8 120 5 Cost $ 200 150 5 3 Preliminary Sensor and Module Research The following is a brief description of each sensors and module that was considered and implemented into our system. Wireless Communication Modules 3.1.1 RF Modules Radio frequency spans between the 3 kHz to 300 GHz. Various modules are capable of communication ranges greater than 500 ft. In addition, communication range is dependent on the amount of supplied voltage, where modules capable of receiving higher voltage will be able to transmit further distances. These modules vary in complexity where more complex RF modules will require more pins and a supporting library in order to be utilized. Likewise, higher complexity translates to increases in costs.
  11. 11. 6 | P a g e 3.1.2 Bluetooth Module A computer or PC should be able to receive the data from all four wheelchairs simultaneously as long as they are connected to a different Serial port on the computer. Up to 7 Bluetooth devices can be connected to a computer at a time. *BLE is Bluetooth Low Energy Figure 1. Snapshot of Bonnie's research on Bluetooth.
  12. 12. 7 | P a g e Strain Gauge 3.2.1 Definition of Strain & Strain Gauge: Strain: it is the amount of deformation of a body due to an applied force. Strain gauge: it is a device which used to measure strain on a certain object. 3.2.2 1.2 Physical operation: A strain gauge takes advantage of the physical property of electrical conductance and its dependence on the conductor's geometry. When an electrical conductor is stretched within the limits of its elasticity such that it does not break or permanently deform, it will become narrower and longer, changes that increase its electrical resistance end-to-end. Conversely, when a conductor is compressed such that it does not buckle, it will broaden and shorten, changes that decrease its electrical resistance end-to-end. From the measured electrical resistance of the strain gauge, the amount of induced stress may be inferred. A typical strain gauge arranges a long, thin conductive strip in a zig-zag pattern of parallel lines such that a small amount of stress in the direction of the orientation of the parallel lines results in a multiplicatively larger strain measurement over the effective length of the conductor surfaces in the array of conductive lines—and hence a multiplicatively larger change in resistance—than would be observed with a single straight-line conductive wire. Figure 1.2.1 Strain Gauge
  13. 13. 8 | P a g e Figure 1.2.2 strain gauge attached on a certain object 3.2.3 Theory In order to use the strain gauge to measure the strain, the Wheatstone bridge and Op amps are required. It allows to measure unknown resistance by balancing two legs of bridge circuit. Figure 1.3.1. Wheatstone Bridge & Op Amps Circuit Diagram The digital value that Arduino analog pin reads is not the actual voltage but it can be calculated by this function where ε is the strain, GF is the gage factor, DV is digital value that reads by analog pins. and R1 and R2 are the gain setting resistors 𝜀 = 𝐷𝑉 𝐺𝐹 256 𝑅2 𝑅1 ⁄
  14. 14. 9 | P a g e Accelerometer An accelerometer is an electromechanical device that measures the forces of gravity in units of acceleration. These forces may be static or continuous. They are most commonly used to detect or monitor vibration in a system or machinery. Many times, vibration can cause a piece of machinery to malfunction when vibrating at the resonant frequency, so it is important to monitor and control vibration. Accelerometers can measure acceleration in 3 axis known as X, Y, and Z. When the accelerometer is placed in the horizontal position so that the z direction is straight up, the accelerometer readings should be zero in the x and y direction and 1G in the z direction. 1G is equal to 9.81m/s^2 which is the acceleration of gravity that we all feel when static. If the accelerometer was dropped from a certain height, it would experience a G force greater than 1 at impact. G force varies when the device being monitored is no longer static. Many times, Accelerometers are used in conjunction with gyroscopes to determine the orientation of a system in units of degrees. Gyroscopes measure orientation as yaw, pitch, and roll (reference the figure below). Hall Effect Sensor - The “Hall Effect” is a change in voltage across an electrical conductor that is caused by a magnetic field. Hall Effect sensors output a voltage response to a magnetic field interference and mostly used for proximity switching, positioning, and speed detection.
  15. 15. 10 | P a g e 4 Sensor Downselection Strain Gauge Downselection Strain Gauge Types Brand name uxcell Uwish - DIY Picture Size 0.28’’ * 0.18” 0.6” * 0.2” - 0.25’’* 0.13’’ Weight 1g 56 g - - Cost $2.87 $6.99 $0.76 $1.38 Resistance 349.8 +/- 0.1 ohm 120 ohm 1000 ohm 120 ohm Sensitive Factor 2.0-2.20 2.08 - 2.0 If contains wire No yes yes yes Shipping Time 1-week shipping with 29.99 shipping fee 1 month 1 month 1-2 weeks Strain Gauge Down Selection Brand name uxcell Uwish - DIY Picture Size 0 0 0 0 Weight 0 0 0 0 Cost 0 - + +
  16. 16. 11 | P a g e Resistance 0 0 0 0 Sensitive Factor 0 0 0 0 If contains wire - + + + Shipping Time - - - + Sum +’s 0 1 2 3 Sum 0’s 5 4 4 4 Sum -‘s 2 2 1 0 Net score -2 -1 1 3 Continue? No No No yes Thermocouple Downselection
  17. 17. 12 | P a g e Accelerometer Downselection *Since cost was ranked of the most importance, we decided to go with sensor MPU-6050 since it is less than half the price of the other two accelerometers.
  18. 18. 13 | P a g e Arduino Downselection RF Module Downselection Datum A B C D Selection Criteria Arduino Uno R3 Arduino 101 w/ Bluetooth & Accel. Arduino Pro 328 Arduino Micro Arduino Mega 2560 R3 Price $24.95 $30.00 $14.95 $24.95 $45.95 Operating Voltage 5 V 3.3 V 5 V 5 V 5 V Digital I/O Pins 14 14 14 20 54 Analog Input Pins 6 6 6 12 16 I/O Pin Current Draw 20 mA 20 mA 40 mA 20 mA 20 mA Flash 32 kB 196 kB 32 kB 32 KB 256 KB SRAM 2 kB 24 kB 2 kB 2.5 KB 8 KB EEPROM 1 kB 0 1 kB 1 KB 4 KB Clock Speed 16 MHz 32 MHz 16 MHz 16 MHz 16 MHz Price 0 - + 0 - Operating Voltage 0 + 0 0 0 Digital I/O Pins 0 0 0 + + Analog Input Pins 0 0 0 + + I/O Pin Current Draw 0 0 - 0 0 Flash 0 + 0 0 + SRAM 0 + 0 + + EEPROM 0 - 0 0 + Clock Speed 0 + 0 0 0 Sum of (-) 0 2 1 3 5 Sum of (0) 9 3 7 6 3 Sum of (+) 0 4 1 0 1 Total 0 2 0 3 4 Datum A B C C Selection Criteria RF Link 315MHz RF Link 434 MHz RFM12B-S2 RFM22B-S2 SMD nRF24L01+ Range 500 ft 500 ft 200 m (656.2 ft) 600 m (1968.5 ft) 262 ft Power Cons. (@3V) 8 mA 8 mA 24 mA 30 mA 13.5 mA Frequency 315 MHz 434 MHz 915 MHz 433 MHz 2.4 GHz Tx Power 25 mW 25 mW 3.2 mW 100 mW 1 mW Data Rate 4.8 kb/s 4.8 kb/s 115.2 kb/s 256 kb/s 2 Mb/s Cost (Total) $8.90 $8.90 $13.90 $23.90 $6.45 Range 0 0 + + - Power Cons. (<15 mA) 0 0 - - + Frequency 0 + + + + Tx Power 0 0 - + - Data Rate 0 0 + + + Cost (Total) 0 0 - - + SUM+'s 0 1 3 4 4 SUM0's 6 5 0 1 0 SUM-'s 0 0 3 1 2 Total 0 1 0 3 2
  19. 19. 14 | P a g e BOM for the nRF24L01+ Assembly Item Price Links nRF24L01+ 2.4 GHz Wireless Transceiver Modules x 2 $6.95 https://www.amazon.com/nRF24L 01-Wireless-Transceiver- Antistatic- Compatible/dp/B00E594ZX0/ref=s r_1_1?ie=UTF8&qid=1465562777 &sr=8-1&keywords=nrf24l01 Arduino Mega 2560 $12.50 x 2 https://www.amazon.com/ATmeg a2560-16AU-ATMEGA16U2- Arduino-MEGA2560- Duemilanove/dp/B00OH21CRM/r ef=sr_1_3?ie=UTF8&qid=1465563 070&sr=8- 3&keywords=arduino+mega+2560 Voltage Regulator x 5 $7.45 https://www.amazon.com/Addico re-LD1117V33-Voltage-Regulator- Antistatic/dp/B01B034F7O/ref=sr _1_2?ie=UTF8&qid=1465563244& sr=8- 2&keywords=voltage+regulator+3. 3v Total Cost: $39.40 Table 2. BOM for nRF24L01+ Assembly
  20. 20. 15 | P a g e Wiring Diagram Figure 2: nRF24L01+ Diagram 1 (Breadboard)
  21. 21. 16 | P a g e Figure 3: nRF24L01+ Diagram 1 (Schematic)
  22. 22. 17 | P a g e The diagrams shown in Figures 2 and 3 demonstrates the current connection between nRF24L01+ module, a voltage regulator, and the Arduino. In addition, this pin set up will require the line of code, “SPI.begin();” to be uncommented (in section “2FWM” of the final receiver code and section “7FWM“ of the final transmitter code.) Uncommenting this line of code allows the pins 50, 51, and 52 to become Serial Peripheral Interface (SPI) pins. Alternatively, the diagrams shown below in Figures 4 and 5 demonstrates the use of ICSP header pins (blue, purple, and brown). This pin configuration should be used if additional digital pin space is required. Make sure to comment out “SPI.begin();” if using the below set up. Figure 4: nRF24L01+ Diagram 2 (Breadboard)
  23. 23. 18 | P a g e Figure 5: nRF24L01+ Diagram 2 (Schematic)
  24. 24. 19 | P a g e Understanding the RF24 Settings The nRF24L01+ module utilizes the base RF24 Library for facilitating the data transfer and maintaining the module settings. Unfortunately, the base RF24 library is unable to send packets greater than 32-bits of data. As a result, the RF24Network library was required to supplement the RF24 base library in order to send larger bits of data. The following is a brief overview of the RF24 settings: 1. In section “1FWM” of both the receiver and transmitter code (see below), this line of designates the CE and the CSN pin (48-CE, 49-CSN) to a specific digital pin on the board. 2. In section “1FWM” of both the receiver and transmitter code (see below), the receiver side will always have a value of “0” while the transmitter side can have values of “1, 2, 3, or 4” (see section 5.4). 3. In section “1FWM” of both only transmitter code (see below), this line of code will always have a value of “0”. 4. In section “2FWM” of the receiver and section “8FWM” of the transmitter(see below), the functions below designate the loudness/range, data rate, and the amount of retries (1-15) per interval(1-15, every increase in value will result in adding 250 microsecond to the base 250 microsecond). The current setting is already set at the highest level. **For a comprehensive list and descriptions of functions/class references of the RF24 and RF24 Library, please see section “16.4: nRF24L01+ Components and References” Uploading and Troubleshooting the Code The following instructions are used to begin the operation of the sensors on the transmitter side:
  25. 25. 20 | P a g e 1. Begin by opening the file labeled “Receiver_Rev_Final.ino” and make sure that the settings in section 5.2 are implemented. 2. Next, make sure the proper ports and board are selected (the board/processor is a mega 2560). 3. Upload the code using the right arrow key at the top left of the Arduino IDE. Once uploaded, click on the serial monitor at the top right of the window or press “Ctrl+Shift+M” to begin the serial monitor. **Please note that the main loop will reset every time the serial monitor is restarted** 4. Once the code has been uploaded onto the receiver board and the serial monitor is ready to be read. The transmitter board may be uploaded with file labeled “Transmitter_Rev_Final. ino” in the same manner as the receiver board. 5. In order to ensure that transmission is successful, in section “15FWM” of the main loop on the transmitter side, uncomment and comment out the lines of code shown below.
  26. 26. 21 | P a g e Comment out this line: Uncomment these lines of code: 6. Upload the transmitter code and open serial monitor on the transmitter board in order to read out all the values as well as demonstrate whether or not the transmission was successful. In addition, the receiver side should also read out any successful transmission. 7. Once transmission has proven to be stable, undo step 5 by uncommenting and commenting out the respective lines of codes. This is done to prevent the transmitter code from reducing the data rate due to the amount of serial prints currently active. 8. Re-upload the undone transmitter code to the board. 9. Unplug all transmitter boards from the power source and reinitialize the serial monitor on the receiver board (repeat step 3). 10. Once the receiver board’s serial monitor is up and ready for read out, just plug the transmitter board into the supplied battery and transmission should begin in a few seconds. Opening Additional Transmitting Nodes within the Network Currently the program is set up to transmit from one node to the main node. However, the following steps will allow for multiple nodes to transmit at the same time: 1. In the final transmitter code, section “1FWM”, change the node value into 1, 2, 3, or 4 respective to the chair the transmitter will be sending from. This is the transmitter’s node address that the receiver will be reading from.
  27. 27. 22 | P a g e 2. In the final receiver code, section “1FWM”, uncomment “payload c2; payload c3; payload c4;” according to the chair nodes currently transmitting through the network. These “payloads” are global class structs that hold the transmitted value of each chair that will be printed into the serial monitor.
  28. 28. 23 | P a g e 3. In the final receiver code, section “3FWM”, uncomment each “if (rec.node == #)” in order to make sure that the data transmitted from each chair node will be placed into the respective “payload” structs. This ensures that the serial monitor will be able to organize the data in a way that will be readable to the GUI. 4. In the final receiver code, section “3FWM”, uncomment each “Serial.print(“~~~”)” according to the chair node connected to the system. These blocks of “serial.print” will format the data onto the serial monitor in a way that will be readable in the GUI. In addition, make sure to change the last line of “Serial.println(~~)” into “Serial.print(~~)” to prevent the serial monitor from printing onto a new line. **see blue square
  29. 29. 24 | P a g e **PLEASE NOTE: The transmission of multiple nodes will take time to stabilize the signal. In addition, some data packets will be lost according to the rate that each transmitter sends to the receiver as the packets will collide and prevent the pipes from reading the respective packets.
  30. 30. 25 | P a g e 5 Strain Gauges Table 3. BOM for Strain Gauge Assembly Item Picture Quantity Cost Per Item Strain Gauge 4 $1.38 16 Pins OP AMP 2 $1.69 120 Ohm Resistor 4 $0.12 1K Ohm Resistor 4 $0.05 100K Ohm Resistor 8 $0.05 Wires Many $0.03
  31. 31. 26 | P a g e Solder Gun 1 $15.49 Solder 1 $8.59 Breadboard 2 $2.97 Arduino Mega 2560 1 $11.99 Electrical Tape 1 $3.99
  32. 32. 27 | P a g e Wiring schematics Figure 6. Breadboard View
  33. 33. 28 | P a g e Figure 7. Schematic View
  34. 34. 29 | P a g e Mounting instructions Placement Diagram Figure 8. Front Left castor Figure 9. Rear left axle
  35. 35. 30 | P a g e Figure 10. Breadboard Position Instruction 1. Use P200 – P400 sand paper to polish the surface till the paint is removed. 2. Use alcohol to clean the surface. 3. Add one drop super glue on the back of strain gauge 4. Put the strain gauge on the surface and press the strain gauge to remove extra super glue underneath.
  36. 36. 31 | P a g e Wiring Notification Do not arrange wires too close while connecting breadboard with Arduino because the DC current flows in the wire can create a magnetic field. If another wire moves in this magnetic field, the magnetic field will produce extra current in that wire, which will result incorrect data. Figure 11. Magnetic Field Created by DC current Figure 12. Bad example
  37. 37. 32 | P a g e Test Results The wheelchair went over Team A’s Test Track and yielded the following results: *The values on the serial monitor are strains Figure 13. Left Front Castor Figure 14. Left Rear Wheel -0.0001 -0.00005 0 0.00005 0.0001 0.00015 0.0002 0.00025 0.0003 0 100 200 300 400 500 600 700 Strain Point Numbners LF -0.00025 -0.0002 -0.00015 -0.0001 -0.00005 0 0.00005 0.0001 0 100 200 300 400 500 600 700 strain Point Numbers LR
  38. 38. 33 | P a g e Figure 15. Right Front Castor Figure 16. Right Rear Wheel 6 K-Type Thermocouple Thermocouples Description A device for measuring temperature. Two different conducting material form electrical junctions. For K type thermocouple, it is made out of Nickel-Chromium and Nickel-Alumel wires. A thermocouple produces voltage proportion to the temperature difference, and this voltage can be interpreted to compute the temperature. -0.0002 -0.0001 0 0.0001 0.0002 0.0003 0.0004 0 100 200 300 400 500 600 700 Strain Point Numbers RF -0.0006 -0.0005 -0.0004 -0.0003 -0.0002 -0.0001 0 0 100 200 300 400 500 600 700 Strain Point Numbers RR
  39. 39. 34 | P a g e K type thermocouple data sheet: http://www.omega.com/temperature/Z/pdf/z204-206.pdf Wiring 4 Thermocouples
  40. 40. 35 | P a g e Figure 17. Rear Wheel's Axles Thermocouple Mounting Instructions Sensor Location Component Figure 18. Castor Pivot Bearing
  41. 41. 36 | P a g e Materials Needed Table 4. BOM for Thermocouple Assembly QTY Item 1 MG Chemicals 8329TCM-6ML Thermal Conductive Adhesive, Medium Cure* 1 Super Glue 1 Mixing cup 1 Mixing Sticks 1 Alcohol 5 Cotton swabs *It is essential to wear gloves and safety glasses before working with epoxy. 6.2.1 Instructions 1. Clean surface with alcohol and cotton swab (File or sand the surface if needed) 2. Eject the amount of thermal conductive adhesive that is needed (Mix the appropriate ratio according to the manufacturer’s instructions)
  42. 42. 37 | P a g e 3. Mix the solution well (May use a cup to mix) 4. Secure the wire with super glue 5. Apply thin layer of adhesive on the sensor and the surface
  43. 43. 36 | P a g e 7 MPU-6050 Accelerometer + Gyroscope MPU-6050 Description The MPU- 6050 is a 3 axis accelerometer and 3 axis gyroscope. The accelerometer can measure acceleration in the x, y, and z axis and orientation in yaw, pitch, and roll. MPU-6050 Datasheet: https://www.cdiweb.com/datasheets/invensense/MPU- 6050_DataSheet_V3%204.pdf Figure 19. MPU 6050 accelerometer and gyroscope Wiring 4 MPU-6050 Sensors The 16 channel multiplexer is used to read multiple I2C accelerometers on single I2C bus. It will allow up to 16 sensors to operate on only 5 pins of a microcontroller. Figure 20. 16 Channel Multiplexer
  44. 44. 37 | P a g e MPU-6050 (QTY 4) + 16 CH MUX (QTY 1) + Mega 2560 (QTY 1)
  45. 45. 38 | P a g e Accelerometer Mounting Instructions The following are instructions on how to mount the accelerometers to the front and back wheel axles of the GEN 2 Wheelchair. One Accelerometer will be placed near each wheel axle as shown in Figure 2 below. The red squares represent the accelerometers. The locations of each accelerometer are labeled A-D. Figure 21. Accelerometer placement diagram as viewed from the top of the wheelchair A D B C Top View
  46. 46. 39 | P a g e Figure 23. Close-up view of accelerometer placement on back wheel Figure 22. Close-up view of accelerometer placement on front wheel Isometric View
  47. 47. 40 | P a g e Materials Needed Table 5. BOM for Accelerometer Assembly QTY Item Cost/unit Total Cost Notes 4 Accelerometer Sensor 5.99 23.96 1 16 CH Analog/Digital MUX 7.95 7.95 16 Male to female pin headers 5.38 5.38 Attach wires to accelerometer pin headers 25+ Jumper wires 0.00 0.00 Lab stash 1 Cyanoacrylate Adhesive (.07oz) (Krazy Glue or Super Glue) 1.00 1.00 Cyanoacrylate cures almost instantly at room temperature and has a broad frequency response and thermal stability. 1 Cleaning Solvent (rubbing alcohol) 1.00 1.00 Used to clean the metal surface 1 Soldering Iron 0.00 0.00 Lab use 1 Solder 0.00 0.00 Lab use Total $39.29
  48. 48. 41 | P a g e 7.3.1 Instructions: 1. Before installing the accelerometer clean the area where you will be mounting the accelerometer thoroughly with a solvent, (Rubbing Alcohol) to remove any surface contaminants. 2. Starting with point A (left back wheel), Squeeze a thin line of super glue along the edge of the clean metal surface as shown with the red arrows in Figure 24. Figure 24. Top view close-up of location A with arrows indicating the thin line of glue. 3. Quickly align the accelerometer on metal edges and press gently so that the accelerometer adheres to the surface. The proper orientation of the accelerometer is shown in Figure 10. The X arrow displayed on the accelerometer points to the right and the Y arrow points to the front of the wheelchair. 4. Feed the wires in the direction of the green arrow shown in Figure 25. 5. At location B, generously apply super glue to the area near the castor fork. See Figure 26. Figure 25. Top view of location A with proper orientation of accelerometer. Green arrows represent the direction that wires should be fed A A
  49. 49. 42 | P a g e Figure 26. Front left castor 6. Quickly align the accelerometer on metal edges and press gently so that the accelerometer adheres to the surface. The proper orientation of the accelerometer is shown in Figure 26. 7. Feed the wires in the direction of the green arrow shown in Figure 26. 8. Repeat this process on the other front wheel at location D and back wheel at location B. B
  50. 50. 43 | P a g e Figure 27. Red arrows Represent the direction the wires from the accelerometer should be fed. The yellow star is where the Arduino microcontroller will be mounted Calibrating MPU-6050 Sensor After mounting the MPU-6050 sensors the sensors must be calibrated so that they yield accurate measurements. It is important to calibrate the sensors after they have been mounted on the wheelchair so that the offset between the local zero G position of the wheelchair and the global true zero position G position can be accounted for. The sensors will have to be calibrated one by one. 1. Hook up the first MPU-6050 to the MEGA 2560 microcontroller 2. Upload the calibration code found on this website: http://42bots.com/tutorials/arduino- script-for-mpu-6050-auto-calibration/ to the MEGA 2560 microcontroller. 3. Click on the checkmark on the top left corner of the page to compile the code. If no error messages are displayed, click the arrow button to upload the code onto the microcontroller. D C B A Arduino
  51. 51. 44 | P a g e 4. Open the serial monitor by clicking on the button with the magnifying glass on the top right corner of the page. Figure 28. Buttons referenced for steps 3 and 4. 5. Check the values on the serial monitor. These are offsets for acceleration in the x, y, and z direction. Copy these offsets and overwrite the defaults in the ____Name of file and line number) code provided. Figure 29. Screenshot of the portion of the code that needs to be changed in step 5. The accelerometer is now calibrated. Repeat steps 1-5 for all four MPU-6050 sensors. Accelerometer Results The following results were produced after running the wheelchair over Team A’s test track. (3) (4)
  52. 52. 45 | P a g e Figure 30. Acceleration vs. Time Graph 8 Hall Effect Sensor Table 6. BOM for Hall Effect Sensor
  53. 53. 46 | P a g e Sample wiring schematics 9 Mounting Instructions: - 2 parts: magnet and sensor 1. Magnet: Figure 31. Mounting cap and magnet o Line up wheel spoke with cap trench.
  54. 54. 47 | P a g e Figure 32. Mounted magnet on the wheel o Screw in tightly until magnet is secure. 2. Hall Effect Sensor: i. Mount Velcro behind the sensor, front and back of mount stand and on wheelchair’s frame  Make sure the top of the sensor (the black head) line up with magnet Figure 33. Magnet level with sensor Note: a red light on the sensor with light up whenever a magnet pass through
  55. 55. 48 | P a g e Figure 34. Light indicator to check magnet activity 10 Graphical User Interface Introduction As explained by the project goal, the team is required to wirelessly transmit data from multiple sensors in real time, and present it in an organized fashion using a graphical user interface (GUI). The image above portrays the template for the user interface that was established between Team B and FWM representatives. It was determined that the GUI should display sensor data for 4 wheelchairs. Each quadrant will display the following information:  Temperature Figure 31. User Interface Template
  56. 56. 49 | P a g e  Strain  Track Speed  Time of Day  Total Run Time  Room Temperature  Test #  Accelerometer A significant amount of research was carried out to determine the ideal software to develop a GUI that is responsive, comprehensive and aesthetically pleasing. Preliminary Research Three different software options will be examined before choosing the best option for the final design. 10.2.1 Processing Processing is a flexible software sketchbook and a language that teaches people how to code. The beauty of using this software is that it is free, open source, and accompanied by a large community of users ready to share information. Further, the program builds on the Java language comes with its own integrated development environment (IDE) similar to Arduino. Lastly, the program comes with a cross-language called OpenGL, which is used for rendering 2D and 3D vector graphics. In other words, it is really fast. 10.2.2 PLX-DAQ Parallax Data Acquisition tool (PLX-DAQ) is a software add-on tool for Microsoft Excel. It allows for any microcontroller to be connected via the serial port of a PC and send data directly Figure 31. Processing Components
  57. 57. 50 | P a g e to excel. In fact, the tool can acquire up to 26 channels of data and plot or graph it as it arrives in real-time. 10.2.3 MATLAB Matlab (matrix laboratory) is a numerical computing environment developed by MathWorks. Matlab allows for matrix manipulations, plotting functions of data, implementation of algorithms, and most importantly the creation of user interfaces. 10.2.3.1 GUI Development Environment Matlab apps are programs with GUI front ends that automate a task or calculation. GUIDE (graphical user interface design environment) provides the tools necessary for designing interfaces for custom apps. Using the built-in editor, a person cangraphically design the interface dragging and dropping visual components. The user can then modify the code that is automatically generated to control the behavior of the app. Figure 31. PLX-DAQ for Excel
  58. 58. 51 | P a g e 10.2.3.2 MATLAB APP Designer App Designer is a design environment utilized for building Matlab apps. It actually makes it very easy in terms of the process of laying out the visual component of a user interface. The environment is equipped with a large set of standard user interface components, along with gauges, knobs and switches. App designer integrates the two main tasks of creating an app – laying out the visual components and programming the app behavior. It is simple moving between visual design on the canvas and code environment. The code is neatly written and structured so that it’s easy to comprehend and maintain. The apps are stored in a single file which contains the design layout and code. Figure 31. MATLAB GUIDE
  59. 59. 52 | P a g e The company liaisons in the end preferred a design environment that would allow anyone to easily create an app that is comprehensive, aesthetic, organized, and flexible. For that reason, we agreed to proceed the Matlab App Designer. 11 Graphical User Interface Instructions: App Designer As mentioned before, the code for a visual component is generated once its put onto the field. In order to control the behavior of them, the user simply needs to insert a callback function as shown in the instructional video located in the references. In order for a component to display a value, simply insert for example: app.T_FL.Value = a(19) The line of code represents the value for a Front Left Temperature gauge. Its property name can be found in the properties class, which is automatically generated. Figure 31. App Designer Properties Figure 31. App Designer Properties 2
  60. 60. 53 | P a g e Steps to run the App 1. Hit the start button Figure 31. Hit Start Figure 31. Final Design Iteration of GUI
  61. 61. 54 | P a g e 2. Insert a test number. This file name will be saved as that test number and a time stamp will be included in the file itself 3. Hit start Figure 31. Insert Test Number
  62. 62. 55 | P a g e 4. Wait for data to collect 5. Hit stop Figure 31. Start Button on GUI Figure 31. GUI Data Collection
  63. 63. 56 | P a g e 6. Close window 7. Go to Matlab editor 8. Open file 9. Copy all 10. Paste onto excel Figure 31. Stop Button on the GUI Figure 31. Copying data from text file
  64. 64. 57 | P a g e Debugging User Interface Figure 31. Pasting Data onto Excel Figure 31. COM Port Error
  65. 65. 58 | P a g e Whenever a COM Port is being used and the user tries to utilize it again, the error message shown above, will appear. Pasting the following line of code will properly close all COM Ports: fclose(instrfind) *For Further Information on how set up a basic GUI and how to run the APP, please see the References. 12 Cost Report This is the list of all the main parts and cost for the selected sensors and modules. The cost of all the smaller components are added up and categorized into their respective sensor. Table 7. Cost Analysis Component Cost ($) Strain Gauge & sub-components 6.92 Thermocouple & sub-components 54.30 Accelerometer & sub-components 39.29 Figure 31. Fixing COM Port Issue
  66. 66. 59 | P a g e Hall Effect Sensor & sub-components 53.91 Pressure caps 6.50 RF Module & sub-components 14.40 Microcontroller Mega 2560 12.50 Protoshield 14.95 Total $202.77 13 Results Final Pin Assignment Pin Assignment Analog Digital Pin Sensor Pin Sensor A0 Strain Gauge A1 Strain Gauge 22 A2 Strain Gauge 23 A3 Strain Gauge 24 A4 Strain Gauge 25 Thermo Couple A5 Strain Gauge 26 Thermo Couple A6 Strain Gauge 27 Thermo Couple A7 Strain Gauge 28 Thermo Couple A8 29 Thermo Couple A9 30 Thermo Couple A10 31 Thermo Couple A11 32 Thermo Couple A12 33 Thermo Couple A13 34 Thermo Couple A14 Hall Effect Sensor 35 Thermo Couple Analog Digital Pin Sensor Pin Sensor A15 Hall Effect Sensor 36 Thermo Couple Interrupt Pin 37 Pin Sensor 38 1 39 2 40 3 Hall Effect Sensor 41 4 42 5 43 6 44 7 45 8 46 9 Accelerometer 47 10 Accelerometer 48 RF24 11 Accelerometer 49 RF24 12 Accelerometer 50 RF24 13 Accelerometer 51 RF24 52 RF24 53 Hall Effect Sensor
  67. 67. 60 | P a g e 14 Appendices Distribution of Work Bonnie Gonzalez As team lead Bonnie Gonzalez was in charge of assigning weekly tasks to all the team members. She was also the main source of communication between the faculty advisors and the company liaisons and the team. She was in charge of keeping her team on track and formatting all documentation into the team binder. She also created a webpage with all the project information to be accessed by the company liaisons in the future. Bonnie also did research on various accelerometer sensors in the market and down selected from 5 sensors based on mainly cost and performance. She successfully read values from all 4 accelerometers simultaneously and wrote detailed instructions on how to mount the sensors on the wheelchair and calibrate them. The accelerometer documentation is complete with links to the code and libraries used, sensor datasheets, and circuit schematics. Tuo Han I am responsible for designing a system to measure strain on certain parts of the wheelchair GEN 2 in real time. After gathering information online, I learn how to use strain gauge and Arduino to measure strain and how to mount strain gauge on objects. Finally, I successfully run the system and collect raw data when the wheelchair is pushed on the test track. Victor Morocho Victor was responsible for developing a graphical user interface via Matlab, which conveyed the complex information in an effective manner. In order to do so, he met with the company liaisons to establish the interface template. Erin Ho Responsible for research on thermocouple, select the suitable and cost- effective sensors. Research and select thermocouple’s amplifier. Purchase sensors and materials. Write code and create functions to read the temperatures. Mount the sensors and solder the proto-shield Nick Vo My role was to research about monitoring RPM of the wheels, check tire pressure and finding power source for our system that would let it last for at least a day. This includes using sensors for data acquisition, participate in system level design trades and develop requirement, and also in charge of quality, time, and budget of the process.
  68. 68. 61 | P a g e Brian Pham Brian’s main responsibilities on the team was the research, downselection, and implementation of a wireless module and SBC/microcontroller. Brian successfully set up a network capable of transferring bulk sensor data from multiple transmitters to a single receiver. He wrote instructions detailing the connections of the modules and the implementation of the code. The nRF24L01+ documentation includes links to example codes, data sheets, and libraries used. He was also responsible for integrating and debugging multiple sensor codes into the final receiver and transmitter codes. 15 References Datasheets  MPU-6050 https://www.cdiweb.com/datasheets/invensense/MPU- 6050_DataSheet_V3%204.pdf  16- Channel Analog Multiplexer/Demultiplexer https://www.sparkfun.com/datasheets/IC/cd74hc4067.pdf  MAX6675 datasheet: https://datasheets.maximintegrated.com/en/ds/MAX6675.pdf  nRF24L01+ Single Chip 2.4 GHz Wireless Transceiver https://www.sparkfun.com/datasheets/Components/SMD/nRF24L01Pluss_Preliminary_Product_ Specification_v1_0.pdf  Code Libraries  MAX6675 Library: https://github.com/adafruit/MAX6675-library  MPU-6050 Library https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050  RF24 and RF24Network Libraries https://github.com/maniacbug/RF24 https://github.com/maniacbug/RF24Network GUI Instructional videos  Setting up a GUI  https://youtu.be/niJ8pFRAyZs  Running the GUI https://youtu.be/FMjExTEjs6k
  69. 69. 62 | P a g e 16 Miscellaneous Accelerometer Components and References  Setting up 16 CH Multiplexer and MPU-6050 http://www.egr.msu.edu/classes/ece480/capstone/spring13/group08/documents/dan.pdf  MPU-6050 tutorials http://diyhacking.com/arduino-mpu-6050-imu-sensor-tutorial/ http://playground.arduino.cc/Main/MPU-6050 Thermocouple components and References MAX6675 Module The MAX6675 provide a cold-junction compensation for thermocouples. It amplifies and digitizes the signal from a type-K thermocouple. Output in a 12-bit resolution and resolves temperatures to 0.25°C. Amazon: http://www.amazon.com/CHENBO-MAX6675-Module- Thermocouple- Arduino/dp/B014P0D7J6?ie=UTF8&keywords=max6675&qid=1465428676&ref_=sr_1_3&sr=8-3 Uxcell® 9mm x 5mm Probe Ring K Type Thermocouple Temperature Sensor  Product Name : Thermocouple; Transfer Type : K; Number of Terminals : 2  Temperature :0-800C; Fork Terminal Spacing : 4.4mm/ 0.2"  Probe Ring Size : 9 x 5mm/0.35" x 0.2"(Outside Dia.*Inner Dia.);External Shielding : Nylon Braided Cable Shield  Total Length : 2M/ 6.6Ft;Color : White  Weight : 19g;Package Content : 1 x Thermocouple Amazon: http://www.amazon.com/uxcell%C2%AE-Probe-Thermocouple- Temperature- Sensor/dp/B00EL0QX7O?ie=UTF8&keywords=Thermocouple%20ring&qid=1465429498&ref_=sr_1_1&sr =8-1 URBEST® K Type Wire Lead Measuring Thermocouple Sensor  Product Name : Thermocouple; Transfer Type : K  Temperature : 0-800 C, External Shield : Nylon Braided Cable Shield  Fork Terminal Spacing : 5.5mm / 0.2";Connector Size (Approx.) : 37 x 17 x 8mm/1.5" x 0.7" x 0.3"(L*W*T)  Cable Length : 1m / 3.3Ft;Color : White, Yellow  Weight : 26g;Package Content : 2 x Thermocouple Amazon: http://www.amazon.com/URBEST%C2%AE2-Measuring- Thermocouple-Sensor-3-
  70. 70. 63 | P a g e 3Ft/dp/B00N2QTHLM?ie=UTF8&keywords=Thermocouple&qid=1465429236&ref_=sr_1_8&refinements= p_85%3A2470955011&sr=8-8 Strain Gauge Components and References  http://www.amazon.com/uxcell%C2%AE-Pressure-Resistive-Strain- Sensor/dp/B01CSLMN0I?ie=UTF8&keywords=strain%20gauge&qid=1460677040&ref_=sr_1_4&sr=8 -4  http://www.amazon.com/Uwish-BX120-1AA-Electrical-Strain- Gage/dp/B00YSJBWF6?ie=UTF8&keywords=strain%20gauge&qid=1460677040&ref_=sr_1_5&sr=8- 5#feature-bullets-btf  http://www.ebay.com/itm/5pcs-x-1000-BF-1K-Precision-Pressure-Resistance-Strain-Gauge-1000- ohm-/221966674531?hash=item33ae3eaa63:g:BMgAAOSwnipWa~We  https://detail.tmall.com/item.htm?id=44115733114&spm=a1z09.2.0.0.UhFc17&_u=134oe5513e0 nRF24L01+ Components and References  Link for purchase: https://www.amazon.com/nRF24L01-Wireless-Transceiver-Antistatic- Compatible/dp/B00E594ZX0/ref=sr_1_1?ie=UTF8&qid=1465536179&sr=8-1&keywords=nrf24l01  Base Example of RF24network: https://maniacbug.wordpress.com/2012/03/30/rf24network/  RF24 Library Class Reference: http://maniacbug.github.io/RF24/classRF24.html  RF24network Library Class Reference: https://maniacbug.github.io/RF24Network/classRF24Network.html 17 Arduino Codes Strain Gauge Calibrate Code void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() { // read the input on analog pin 0: int sensorValue1 = analogRead(A0); int sensorValue2 = analogRead(A1); int sensorValue3 = analogRead(A2); int sensorValue4 = analogRead(A3); int sensorValue5 = analogRead(A4); int sensorValue6 = analogRead(A5); int sensorValue7 = analogRead(A6); int sensorValue8 = analogRead(A7); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float DV1 = sensorValue1; float DV2 = sensorValue2;
  71. 71. 64 | P a g e float DV3 = sensorValue3; float DV4 = sensorValue4; float DV5 = sensorValue5; float DV6 = sensorValue6; float DV7 = sensorValue7; float DV8 = sensorValue8; // print out the value you read: Serial.print(DV1 - DV2); Serial.print("t"); //Serial.println(""); Serial.print(DV3 - DV4); Serial.print("t"); // Serial.println(""); Serial.print(DV5 - DV6); Serial.print("t"); Serial.print(DV7 - DV8); Serial.print("t"); Serial.println(""); } Strain Gauge Function Code void setup() { // initialize serial communication at 9600 bits per second: Serial.begin(9600); } // the loop routine runs over and over again forever: void loop() {StrainRead(); } void StrainRead(){ // read the input on analog pin 0: int sensorValue1 = analogRead(A0); int sensorValue2 = analogRead(A1); int sensorValue3 = analogRead(A2); int sensorValue4 = analogRead(A3); int sensorValue5 = analogRead(A4); int sensorValue6 = analogRead(A5); int sensorValue7 = analogRead(A6); int sensorValue8 = analogRead(A7); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float DV1 = sensorValue1;
  72. 72. 65 | P a g e float DV2 = sensorValue2; float DV3 = sensorValue3; float DV4 = sensorValue4; float DV5 = sensorValue5; float DV6 = sensorValue6; float DV7 = sensorValue7; float DV8 = sensorValue8; // print out the value you read: Serial.print((DV1 - DV2 -(111))/(2.1* 256 * 100),8); Serial.print("t"); Serial.print((DV3 - DV4 -(150))/(2.1* 256 * 100),8); Serial.print("t"); Serial.print((DV5 - DV6 - (254))/(2.1 * 256 * 100),8); Serial.print("t"); Serial.print((DV7 - DV8 - (119))/(2.1 * 256 * 100),8); Serial.print("t"); Serial.println(""); } Accelerometer Function Code // This Program reads accelerometer and Gyroscope values from 4 MPU-6050 Sensors. // The 4 sensors are connected to a 16 channel Multiplexer. // The pins are defined for a Mega 2560 microcontroller. #include <SoftwareSerial.h> #include <SPI.h> //Arduino Wire Library #include "Wire.h" // 12Cdev and MPU6050 libraries must be installed #include "I2Cdev.h" #include "MPU6050.h" MPU6050 accelgyro; //declare accelerometer //Mux control int EN = 13; int s0 = 9; int s1 = 10; int s2 = 11; int s3 = 12;
  73. 73. 66 | P a g e // Acceleration Variables int16_t ax1, ay1, az1, gx1, gy1, gz1; int16_t ax2, ay2, az2, gx2, gy2, gz2; int16_t ax3, ay3, az3, gx3, gy3, gz3; int16_t ax4, ay4, az4, gx4, gy4, gz4; // uncomment "OUTPUT_READABLE_ACCELGYRO" if you want to see a tab-separated // list of the accel X/Y/Z and then gyro X/Y/Z values in decimal. Easy to read, // not so easy to parse, and slow(er) over UART. //#define OUTPUT_READABLE_ACCELGYRO // ================================================================ // === Functions for each of the IMU channels === // ================================================================ //Channel 1 void out1() { digitalWrite (EN, LOW); digitalWrite (s0,HIGH); digitalWrite (s1, LOW); digitalWrite (s2, LOW); digitalWrite (s3, LOW); } //Channel 0 void out2() { digitalWrite (EN, LOW); digitalWrite (s0, LOW); digitalWrite (s1, LOW); digitalWrite (s2, LOW); digitalWrite (s3, LOW); } //Channel 3 void out3() { digitalWrite (EN, LOW); digitalWrite (s0, HIGH); digitalWrite (s1, HIGH); digitalWrite (s2, LOW); digitalWrite (s3, LOW);
  74. 74. 67 | P a g e } //Channel 4 void out4() { digitalWrite (EN, LOW); digitalWrite (s0, LOW); digitalWrite (s1, LOW); digitalWrite (s2, HIGH); digitalWrite (s3, LOW); } // ================================================================ // === INITIAL SETUP === // ================================================================ void setup(){ out1(); out2(); out3(); out4(); //out1(); pinMode(EN, OUTPUT); pinMode(s0, OUTPUT); pinMode(s1, OUTPUT); pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); // // Join 12C bus Wire.begin(); // // join I2C bus (I2Cdev library doesn't do this automatically) // #if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE // Wire.begin(); // #elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE // Fastwire::setup(400, true); // #endif // initialize serial communication // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but // it's really up to you depending on your project) //Initialize serial communication Serial.begin(9600); }
  75. 75. 68 | P a g e // ================================================================ // === MAIN PROGRAM LOOP === // ================================================================ void loop(){ //conversion of reading to m/s^2 16384/9.81=1670.13 // divide by 1670.13 // Read from MPU 1 on ch 1 out1(); unsigned long x = micros(); // read raw accel/gyro measurments from device accelgyro.initialize(); // Serial.println("Testing device connections..."); // Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); // accelgyro.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1); accelgyro.getAcceleration(&ax1, &ay1, &az1); //Accelerometer Calibration //Supply your own offsets here: float Ax1=(ax1-820)/1670.13; float Ay1=(ay1-2200)/1670.13; float Az1=(az1-84)/1670.13; // gx1=gx1-10; // gy1=gy1-51; // gz1=gz1-60; // display tab-seperated acceleration x/y/z values Serial.print("ax/ay/az):t"); //Serial.print(x); Serial.print("t"); Serial.print("MPU 1:t"); Serial.print(Ax1); Serial.print("t"); // Add accel offset, scaled to senitivity Serial.print(Ay1); Serial.print("t"); Serial.println(Az1); // Uncomment to print GYRO readings // Serial.print(gx1); Serial.print("t"); // Serial.print(gy1); Serial.print("t"); // Serial.println(gz1);
  76. 76. 69 | P a g e // Read from MPU 2 on ch 2 out2(); // read raw accel/gyro measurments from device accelgyro.initialize(); // Serial.println("Testing device connections..."); // Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); // accelgyro.getMotion6(&ax2, &ay2, &az2, &gx2, &gy2, &gz2); accelgyro.getAcceleration(&ax2, &ay2, &az2); //Accelerometer Calibration //Supply your own offsets here: float Ax2=(ax2-800)/1670.13; float Ay2=(ay2-2150)/1670.13; float Az2=(az2-50)/1670.13; // gx2=gx2+23; // gy2=gy2+2; // gz2=gz2-13; // // display tab-seperated acceleration x/y/z values Serial.print("ax/ay/az):t"); //Serial.print(x); Serial.print("t"); Serial.print("MPU 2:t"); Serial.print(Ax2); Serial.print("t"); Serial.print(Ay2); Serial.print("t"); Serial.println(Az2); // Uncomment to print GYRO readings // Serial.print(gx2); Serial.print("t"); // Serial.print(gy2); Serial.print("t"); // Serial.println(gz2); // Read from MPU 3 on ch 3 out3(); // read raw accel/gyro measurments from device accelgyro.initialize(); // Serial.println("Testing device connections..."); // Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); // accelgyro.getMotion6(&ax3, &ay3, &az3, &gx3, &gy3, &gz3); accelgyro.getAcceleration(&ax3, &ay3, &az3);
  77. 77. 70 | P a g e //Accelerometer Calibration //Supply your own offsets here: float Ax3=(ax3-740)/1670.13; float Ay3=(ay3-550)/1670.13; float Az3=(az3+1104)/1670.13; // gx3=gx3+61; // gy3=gy3+19; // gz3=gz3+32; // // display tab-seperated acceleration x/y/z values Serial.print("ax/ay/az):t"); //Serial.print(x); Serial.print("t"); Serial.print("MPU 3:t"); Serial.print(Ax3); Serial.print("t"); Serial.print(Ay3); Serial.print("t"); Serial.println(Az3); // Uncomment to print GYRO readings // Serial.print(gx3); Serial.print("t"); // Serial.print(gy3); Serial.print("t"); // Serial.println(gz3); // Read from MPU 4 on ch 4 out4(); // read raw accel/gyro measurments from device accelgyro.initialize(); // Serial.println("Testing device connections..."); // Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed"); // accelgyro.getMotion6(&ax4, &ay4, &az4, &gx4, &gy4, &gz4); accelgyro.getAcceleration(&ax4, &ay4, &az4); //Accelerometer Calibration //Supply your own offsets here: float Ax4=(ax4+100)/1670.13; float Ay4=(ay4-300)/1670.13; float Az4=(az4-100)/1670.13; // gx4=gx4+69; // gy4=gy4+27; // gz4=gz4+26; // // display tab-seperated acceleration x/y/z values Serial.print("ax/ay/az):t");
  78. 78. 71 | P a g e //Serial.print(x); Serial.print("t"); Serial.print("MPU 4:t"); Serial.print(Ax4); Serial.print("t"); Serial.print(Ay4); Serial.print("t"); Serial.println(Az4); // Uncomment to print GYRO readings // Serial.print(gx4); Serial.print("t"); // Serial.print(gy4); Serial.print("t"); // Serial.println(gz4); } Final Code (Receiver) // Section Reference // 1FWM - nRF24L01+ Initial // 2FWM - nRF24L01+ Main Setup // 3FWM - nRF24L01+ Main Loop //=========================================================================== // 1FWM - nRF24L01+ INITIAL //=========================================================================== #include <nRF24L01.h> #include <RF24.h> #include <RF24_config.h> #include <RF24Network.h> #include <RF24Network_config.h> #include <Sync.h> #include <SPI.h> RF24 radio(48,49); // Defines Pins to Use RF24Network network(radio); // Network uses that radio const uint16_t this_node = 0; // Address of our node // Structure of our payload struct payload { uint16_t node; unsigned long timer; int rpm; float ax1, ay1, az1, ax2, ay2, az2, ax3, ay3, az3, ax4, ay4, az4; float s1, s2, s3, s4;
  79. 79. 72 | P a g e float T1, T2, T3, T4; }; /* Uncomment each payload according to chair connected to system */ payload c1; //struct for chair 1 //payload c2; //struct for chair 2 //payload c3; //struct for chair 2 //payload c4; //struct for chair 2 payload rec; //struct for placeholder //=========================================================================== // 2FWM - nRF24L01+ Main Setup //=========================================================================== void setup() { Serial.begin(115200); // Start serial to communication at 115200 Baud Rate //SPI.begin(); // Only uncomment if you are not using the ICSP header pins (see Figure within document) radio.begin(); // Start the RF24 module network.begin(/*channel*/ 108, /*node address*/ this_node); radio.setPALevel(RF24_PA_HIGH); // Increase if you want more range AND have a good power supply (LOW, MEDIUM, HIGH) radio.setDataRate(RF24_2MBPS); // Sets Data Rate (250KBPS, 1MBPS, 2MBPS) radio.setRetries(1,1); // First value is the delay for retries(1-15 represents multiples of 250 us), Second value is # of retries ////Uncomment to print chair 1 header // /*Serial.print("Node"); Serial.print("t"); */Serial.print("t(ms)"); // Serial.print("t"); Serial.print("RPM"); Serial.print("t"); // Serial.print("Ax_1"); Serial.print("t"); Serial.print("Ay1"); // Serial.print("t"); Serial.print("Az_1"); Serial.print("t"); // Serial.print("Ax_2"); Serial.print("t"); Serial.print("Ay_2"); // Serial.print("t"); Serial.print("Az_2"); Serial.print("t"); // Serial.print("Ax_3"); Serial.print("t"); Serial.print("Ay_3"); // Serial.print("t"); Serial.print("Az_3"); Serial.print("t"); // Serial.print("Ax_4"); Serial.print("t"); Serial.print("Ay_4"); // Serial.print("t"); Serial.print("Az_4"); Serial.print("t"); // Serial.print("Str_1"); Serial.print("t"); Serial.print("Str_2"); // Serial.print("t"); Serial.print("Str_3"); Serial.print("t"); // Serial.print("Str_4"); Serial.print("t"); Serial.print("T_1"); // Serial.print("t"); Serial.print("T_2"); Serial.print("t"); // Serial.print("T_3"); Serial.print("t"); Serial.println("T_4"); // ////Uncomment to print chair 2 header // Serial.print("t"); Serial.print("Node"); Serial.print("t"); Serial.print("time(ms)"); // Serial.print("t"); Serial.print("RPM"); Serial.print("t");
  80. 80. 73 | P a g e // Serial.print("Ax_1"); Serial.print("t"); Serial.print("Ay1"); // Serial.print("t"); Serial.print("Az_1"); Serial.print("t"); // Serial.print("Ax_2"); Serial.print("t"); Serial.print("Ay_2"); // Serial.print("t"); Serial.print("Az_2"); Serial.print("t"); // Serial.print("Ax_3"); Serial.print("t"); Serial.print("Ay_3"); // Serial.print("t"); Serial.print("Az_3"); Serial.print("t"); // Serial.print("Ax_4"); Serial.print("t"); Serial.print("Ay_4"); // Serial.print("t"); Serial.print("Az_4"); Serial.print("t"); // Serial.print("Str_1"); Serial.print("t"); Serial.print("Str_2"); // Serial.print("t"); Serial.print("Str_3"); Serial.print("t"); // Serial.print("Str_4"); Serial.print("t"); Serial.print("T_1"); // Serial.print("t"); Serial.print("T_2"); Serial.print("t"); // Serial.print("T_3"); Serial.print("t"); Serial.println("T_4"); // ////Uncomment to print chair 3 header // Serial.print("t"); Serial.print("Node"); Serial.print("t"); Serial.print("time(ms)"); // Serial.print("t"); Serial.print("RPM"); Serial.print("t"); // Serial.print("Ax_1"); Serial.print("t"); Serial.print("Ay1"); // Serial.print("t"); Serial.print("Az_1"); Serial.print("t"); // Serial.print("Ax_2"); Serial.print("t"); Serial.print("Ay_2"); // Serial.print("t"); Serial.print("Az_2"); Serial.print("t"); // Serial.print("Ax_3"); Serial.print("t"); Serial.print("Ay_3"); // Serial.print("t"); Serial.print("Az_3"); Serial.print("t"); // Serial.print("Ax_4"); Serial.print("t"); Serial.print("Ay_4"); // Serial.print("t"); Serial.print("Az_4"); Serial.print("t"); // Serial.print("Str_1"); Serial.print("t"); Serial.print("Str_2"); // Serial.print("t"); Serial.print("Str_3"); Serial.print("t"); // Serial.print("Str_4"); Serial.print("t"); Serial.print("T_1"); // Serial.print("t"); Serial.print("T_2"); Serial.print("t"); // Serial.print("T_3"); Serial.print("t"); Serial.println("T_4"); // ////Uncomment to print chair 4 header // Serial.print("t"); Serial.print("Node"); Serial.print("t"); Serial.print("time(ms)"); // Serial.print("t"); Serial.print("RPM"); Serial.print("t"); // Serial.print("Ax_1"); Serial.print("t"); Serial.print("Ay1"); // Serial.print("t"); Serial.print("Az_1"); Serial.print("t"); // Serial.print("Ax_2"); Serial.print("t"); Serial.print("Ay_2"); // Serial.print("t"); Serial.print("Az_2"); Serial.print("t"); // Serial.print("Ax_3"); Serial.print("t"); Serial.print("Ay_3"); // Serial.print("t"); Serial.print("Az_3"); Serial.print("t"); // Serial.print("Ax_4"); Serial.print("t"); Serial.print("Ay_4"); // Serial.print("t"); Serial.print("Az_4"); Serial.print("t"); // Serial.print("Str_1"); Serial.print("t"); Serial.print("Str_2"); // Serial.print("t"); Serial.print("Str_3"); Serial.print("t"); // Serial.print("Str_4"); Serial.print("t"); Serial.print("T_1"); // Serial.print("t"); Serial.print("T_2"); Serial.print("t"); // Serial.print("T_3"); Serial.print("t"); Serial.println("T_4");
  81. 81. 74 | P a g e } //=========================================================================== // 3FWM - nRF24L01+ Main Loop //=========================================================================== void loop() { network.update(); // Pump the network regularly // Is there anything ready for us? while (network.available()) { RF24NetworkHeader header; network.read(header,&rec,sizeof(rec)); if(rec.node == 1) { //Uncomment if chair 1 is connected c1 = rec; } // if(rec.node == 2) { //Uncomment if chair 2 is connected // c2 = rec; // } // if(rec.node == 3) { //Uncomment if chair 3 is connected // c3 = rec; // } // if(rec.node == 4) { //Uncomment if chair 4 is connected // c4 = rec; // } //Uncomment to print chair 1 data Serial.print(c1.node); Serial.print("t"); Serial.print(c1.timer); Serial.print("t"); Serial.print(c1.rpm); Serial.print("t"); Serial.print(c1.ax1); Serial.print("t"); Serial.print(c1.ay1); Serial.print("t"); Serial.print(c1.az1); Serial.print("t"); Serial.print(c1.ax2); Serial.print("t"); Serial.print(c1.ay2); Serial.print("t"); Serial.print(c1.az2); Serial.print("t"); Serial.print(c1.ax3); Serial.print("t"); Serial.print(c1.ay3); Serial.print("t"); Serial.print(c1.az3); Serial.print("t"); Serial.print(c1.ax4); Serial.print("t"); Serial.print(c1.ay4); Serial.print("t"); Serial.print(c1.az4); Serial.print("t"); Serial.print(c1.s1); Serial.print("t"); Serial.print(c1.s2); Serial.print("t"); Serial.print(c1.s3); Serial.print("t"); Serial.print(c1.s4); Serial.print("t"); Serial.print(c1.T1); Serial.print("t"); Serial.print(c1.T2); Serial.print("t"); Serial.print(c1.T3); Serial.print("t"); Serial.println(c1.T4); // //Uncomment to print chair 2 data // Serial.print("t"); Serial.print(c2.node); Serial.print("t"); Serial.print(c2.timer); // Serial.print("t"); Serial.print(c2.rpm); Serial.print("t"); // Serial.print(c2.ax1); Serial.print("t"); Serial.print(c2.ay1); // Serial.print("t"); Serial.print(c2.az1); Serial.print("t");
  82. 82. 75 | P a g e // Serial.print(c2.ax2); Serial.print("t"); Serial.print(c2.ay2); // Serial.print("t"); Serial.print(c2.az2); Serial.print("t"); // Serial.print(c2.ax3); Serial.print("t"); Serial.print(c2.ay3); // Serial.print("t"); Serial.print(c2.az3); Serial.print("t"); // Serial.print(c2.ax4); Serial.print("t"); Serial.print(c2.ay4); // Serial.print("t"); Serial.print(c2.az4); Serial.print("t"); // Serial.print(c2.s1); Serial.print("t"); Serial.print(c2.s2); // Serial.print("t"); Serial.print(c2.s3); Serial.print("t"); // Serial.print(c2.s4); Serial.print("t"); Serial.print(c2.T1); // Serial.print("t"); Serial.print(c2.T2); Serial.print("t"); // Serial.print(c2.T3); Serial.print("t"); Serial.println(c2.T4); // // //Uncomment to print chair 3 data // Serial.print("t"); Serial.print(c3.node); Serial.print("t"); Serial.print(c3.timer); // Serial.print("t"); Serial.print(c3.rpm); Serial.print("t"); // Serial.print(c3.ax1); Serial.print("t"); Serial.print(c3.ay1); // Serial.print("t"); Serial.print(c3.az1); Serial.print("t"); // Serial.print(c3.ax2); Serial.print("t"); Serial.print(c3.ay2); // Serial.print("t"); Serial.print(c3.az2); Serial.print("t"); // Serial.print(c3.ax3); Serial.print("t"); Serial.print(c3.ay3); // Serial.print("t"); Serial.print(c3.az3); Serial.print("t"); // Serial.print(c3.ax4); Serial.print("t"); Serial.print(c3.ay4); // Serial.print("t"); Serial.print(c3.az4); Serial.print("t"); // Serial.print(c3.s1); Serial.print("t"); Serial.print(c3.s2); // Serial.print("t"); Serial.print(c3.s3); Serial.print("t"); // Serial.print(c3.s4); Serial.print("t"); Serial.print(c3.T1); // Serial.print("t"); Serial.print(c3.T2); Serial.print("t"); // Serial.print(c3.T3); Serial.print("t"); Serial.println(c3.T4); // // //Uncomment to print chair 4 data // Serial.print("t"); Serial.print(c4.node); Serial.print("t"); Serial.print(c4.timer); // Serial.print("t"); Serial.print(c4.rpm); Serial.print("t"); // Serial.print(c4.ax1); Serial.print("t"); Serial.print(c4.ay1); // Serial.print("t"); Serial.print(c4.az1); Serial.print("t"); // Serial.print(c4.ax2); Serial.print("t"); Serial.print(c4.ay2); // Serial.print("t"); Serial.print(c4.az2); Serial.print("t"); // Serial.print(c4.ax3); Serial.print("t"); Serial.print(c4.ay3); // Serial.print("t"); Serial.print(c4.az3); Serial.print("t"); // Serial.print(c4.ax4); Serial.print("t"); Serial.print(c4.ay4); // Serial.print("t"); Serial.print(c4.az4); Serial.print("t"); // Serial.print(c4.s1); Serial.print("t"); Serial.print(c4.s2); // Serial.print("t"); Serial.print(c4.s3); Serial.print("t"); // Serial.print(c4.s4); Serial.print("t"); Serial.print(c4.T1); // Serial.print("t"); Serial.print(c4.T2); Serial.print("t"); // Serial.print(c4.T3); Serial.print("t"); Serial.println(c4.T4); } }
  83. 83. 76 | P a g e Hall Effect Sensor //=========================================================================== // HALL EFFECT SETUP //=========================================================================== attachInterrupt(0, rpm_fan, FALLING); //=========================================================================== // HALL EFFECT FUNCTIONS //=========================================================================== // This code is for reference only, please use the master code. * Pin 2 (interrupt 0) is connected across the IR detector. volatile byte rpmcount; unsigned int rpm; unsigned long timeold; void rpm_fan() { //Each rotation, this interrupt function is run twice, so take that into consideration for //calculating RPM //Update count rpmcount++; } void setup() { //Interrupt 0 is digital pin 2, so that is where the IR detector is connected //Triggers on FALLING (change from HIGH to LOW) attachInterrupt(0, rpm_fan, FALLING); rpmcount = 0; rpm = 0; timeold = 0; } void loop() { //Don't process interrupts during calculations detachInterrupt(0); //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt //happened once per revolution instead of twice. Other multiples could be used //for multi-bladed propellers or fans
  84. 84. 77 | P a g e rpm = 20*1000/(millis() - timeold)*rpmcount; timeold = millis(); rpmcount = 0; //Restart the interrupt processing attachInterrupt(0, rpm_fan, FALLING); } Final Code (Transmitter) // Section Reference // 1FWM - nRF24L01+ Initial // 2FWM - Strain Gauge Initial // 3FWM - Hall Effect Initial // 4FWM - Thermocouple Initial // 5FWM - Accelerometer Initial // 6FWM - IMU Channel Functions // 7FWM - Main Setup // 8FWM - nRF24L01+ Setup // 9FWM - Hall Effect Setup // 10FWM - Accelerometer Setup // 11FWM - Hall Effect Function // 12FWM - Strain Gauge Function // 13FWM - Thermocouple Function // 14FWM - Accelerometer Function // 15FWM - Main Loop //=========================================================================== // 1FWM - nRF24L01+ INITIAL //=========================================================================== #include <nRF24L01.h> #include <RF24.h> #include <RF24_config.h> #include <RF24Network.h> #include <RF24Network_config.h> #include <Sync.h> #include <SPI.h> RF24 radio(48,49); // pinCE, pinCSN RF24Network network(radio); // Network uses that radio const uint16_t this_node = 1; // Address of our node(change to 1, 2, 3, or 4 according to chair number) const uint16_t other_node = 0; // Address of the other node const unsigned long interval = 1000; // How often to send to run the temp program (ms) unsigned long last_sent = 0; // When did we last send? const unsigned long interval2 = 20; // How often to send to the other unit (ms) // Class Structure of Payload
  85. 85. 78 | P a g e struct payload { uint16_t node; unsigned long timer; int RPM; float aX1, aY1, aZ1, aX2, aY2, aZ2, aX3, aY3, aZ3, aX4, aY4, aZ4; float st1, st2, st3, st4; float Temp1, Temp2, Temp3, Temp4; }; //=========================================================================== // 2FWM - STRAIN GAUGE INITIAL //=========================================================================== float S1, S2, S3, S4; // Define global variables to store strain values //=========================================================================== // 3FWM - HALL EFFECT INITIAL //=========================================================================== volatile byte rpmcount; unsigned int rpm; unsigned long timeold; //=========================================================================== // 4FWM - THERMOCOUPLE INITIAL //=========================================================================== #include "max6675.h" //Define global variables to store temperature calibration values float T1_ini, T2_ini=0, T3_ini=0, T4_ini=0; // int tempcounter=0; float T1, T2, T3, T4; // Define global variable to store temperature // T1 = Rear Left, T2 = Front Left, T3 = Rear Right, T4 = Front Right //// Assign actual digital pins (all must be different) #define ktcSO1 22 // Rear Left #define ktcCS1 24 #define ktcCLK1 26 #define ktcSO2 28 // Front Left #define ktcCS2 30 #define ktcCLK2 32 #define ktcSO3 34 // Rear Right #define ktcCS3 36 #define ktcCLK3 38 #define ktcSO4 40 // Front Right #define ktcCS4 42
  86. 86. 79 | P a g e #define ktcCLK4 44 MAX6675 Thermo1(ktcCLK1, ktcCS1, ktcSO1); MAX6675 Thermo2(ktcCLK2, ktcCS2, ktcSO2); MAX6675 Thermo3(ktcCLK3, ktcCS3, ktcSO3); MAX6675 Thermo4(ktcCLK4, ktcCS4, ktcSO4); MAX6675 Thermocouples[4] = {Thermo1, Thermo2, Thermo3, Thermo4}; MAX6675 *pt=Thermocouples; //=========================================================================== // 5FWM - ACCELEROMETER INITIAL //=========================================================================== #include <SoftwareSerial.h> #include <SPI.h> //Arduino Wire Library #include "Wire.h" // 12Cdev and MPU6050 libraries must be installed #include "I2Cdev.h" #include "MPU6050.h" MPU6050 accelgyro; //declare accelerometer //Mux control int EN = 13; int s0 = 9; int s1 = 10; int s2 = 11; int s3 = 12; // Define global variables for final calibrated acceleration values float Ax1, Ay1, Az1, Ax2, Ay2, Az2, Ax3, Ay3, Az3, Ax4, Ay4, Az4; // Define global variables for preliminary acceleration/gyro values int16_t ax1, ay1, az1, gx1, gy1, gz1, ax2, ay2, az2, gx2, gy2, gz2, ax3, ay3, az3, gx3, gy3, gz3, ax4, ay4, az4, gx4, gy4, gz4; // ========================================================================== // 6FWM - Functions for each of the IMU channels // ==========================================================================
  87. 87. 80 | P a g e //Channel 1 void out1() { digitalWrite (EN, LOW); digitalWrite (s0,HIGH); digitalWrite (s1, LOW); digitalWrite (s2, LOW); digitalWrite (s3, LOW); } //Channel 0 void out2() { digitalWrite (EN, LOW); digitalWrite (s0, LOW); digitalWrite (s1, LOW); digitalWrite (s2, LOW); digitalWrite (s3, LOW); } //Channel 3 void out3() { digitalWrite (EN, LOW); digitalWrite (s0, HIGH); digitalWrite (s1, HIGH); digitalWrite (s2, LOW); digitalWrite (s3, LOW); } //Channel 4 void out4() { digitalWrite (EN, LOW); digitalWrite (s0, LOW); digitalWrite (s1, LOW); digitalWrite (s2, HIGH); digitalWrite (s3, LOW); } //=========================================================================== // 7FWM - MAIN SETUP //=========================================================================== void setup(void) { //Serial.begin(115200); // Start serial to communication //SPI.begin(); //Serial.println("Begin..."); // Code start signature
  88. 88. 81 | P a g e //=========================================================================== // 8FWM - nRF24L01+ SETUP //=========================================================================== radio.begin(); // Start the RF24 module // SPI.begin(); // Only uncomment if you are not using the ICSP header pins (see Figure within document) network.begin(/*channel*/ 108, /*node address*/ this_node); radio.setPALevel(RF24_PA_HIGH); // Increase if you want more range AND have a good power supply (LOW, MEDIUM, HIGH) radio.setDataRate(RF24_2MBPS); // Sets Data Rate (250KBPS, 1MBPS, 2MBPS) radio.setRetries(1,1); // First value is the delay for retries(1-15 represents multiples of 250 us), Second value is # of retries //=========================================================================== // 9FWM - HALL EFFECT SETUP //=========================================================================== rpmcount = 0; rpm = 0; timeold = 0; attachInterrupt(0, rpm_fan, FALLING); //=========================================================================== // 10FWM - ACCELEROMETER SETUP //=========================================================================== out1(); out2(); out3(); out4(); // Setting digital pins as outputs. pinMode(EN, OUTPUT); pinMode(s0, OUTPUT); pinMode(s1, OUTPUT); pinMode(s2, OUTPUT); pinMode(s3, OUTPUT); // Join 12C bus Wire.begin(); } //=========================================================================== // 11FWM - HALL EFFECT FUNCTIONS //=========================================================================== // ReadRPM() uses hall effect sensor to measure RPM of wheels void ReadRPM() { //Reset RPM if not moving if (rpmcount < 1){
  89. 89. 82 | P a g e if (((millis()-timeold))>=1500){ rpm = 0; } } //Calculate RPM if (rpmcount >= 1) { //Update RPM every 20 counts, increase this for better RPM resolution, //decrease for faster update rpm = 20*1000/(millis() - timeold)*rpmcount; timeold = millis(); rpmcount = 0; attachInterrupt(0, rpm_fan, FALLING); } } // Interrupt Function void rpm_fan() { rpmcount++; } //=========================================================================== // 12FWM - STRAIN GAUGE FUNCTION //=========================================================================== void ReadStrain() { //Serial.println("Strain is being read..."); // Uncomment to check if Strain Gage function is running // read the input on analog pin 0: int sensorValue1 = analogRead(A0); int sensorValue2 = analogRead(A1); int sensorValue3 = analogRead(A2); int sensorValue4 = analogRead(A3); int sensorValue5 = analogRead(A4); int sensorValue6 = analogRead(A5); int sensorValue7 = analogRead(A6); int sensorValue8 = analogRead(A7); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V): float DV1 = sensorValue1; float DV2 = sensorValue2; float DV3 = sensorValue3; float DV4 = sensorValue4; float DV5 = sensorValue5; float DV6 = sensorValue6; float DV7 = sensorValue7; float DV8 = sensorValue8; // print out the value you read: S1 = (DV1-DV2-(135)) / (2.1*256*100) * 10000;
  90. 90. 83 | P a g e S2 = (DV3-DV4-(162)) / (2.1*256*100) * 10000; S3 = (DV5-DV6-(277)) / (2.1*256*100) * 10000; S4 = (DV7-DV8-(112)) / (2.1*256*100) * 10000; } //=========================================================================== // 13FWM - THERMOCOUPLE FUNCTION //=========================================================================== void ReadTemp() { //Serial.println("Temp is being read..."); // Uncomment to check if Thermocouple function is running T1 = Thermo1.readCelsius() - 1; // - T1_ini; T2 = Thermo2.readCelsius() + 3; // - T2_ini; T3 = Thermo3.readCelsius() - 1; // - T3_ini; T4 = Thermo4.readCelsius() - 3; // - T4_ini; } //=========================================================================== // 14FWM - ACCELEROMETER FUNCTIONS //=========================================================================== void ReadAccel() { // Serial.println("Accel is being read..."); // Uncomment to check if Thermocouple function is running // Conversion of reading to m/s^2: 16384/9.81 = 1670.13 // divide by 1670.13 // Read from MPU 1 on ch 1 out1(); unsigned long x = micros(); // Read raw accel/gyro measurments from device accelgyro.initialize(); //accelgyro.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1); accelgyro.getAcceleration(&ax1, &ay1, &az1); // Accelerometer Calibration // Supply your own offsets here: Ax1=(ax1-820)/1670.13; Ay1=(ay1-2200)/1670.13; Az1=(az1-84)/1670.13; // gx1=gx1-10; // gy1=gy1-51; // gz1=gz1-60; // Read from MPU 2 on ch 2
  91. 91. 84 | P a g e out2(); // Eead raw accel/gyro measurments from device accelgyro.initialize(); //accelgyro.getMotion6(&ax2, &ay2, &az2, &gx2, &gy2, &gz2); accelgyro.getAcceleration(&ax2, &ay2, &az2); //Accelerometer Calibration //Supply your own offsets here: Ax2=(ax2-800)/1670.13; Ay2=(ay2-2150)/1670.13; Az2=(az2-50)/1670.13; // gx2=gx2+23; // gy2=gy2+2; // gz2=gz2-13; // Read from MPU 3 on ch 3 out3(); // read raw accel/gyro measurments from device accelgyro.initialize(); //accelgyro.getMotion6(&ax3, &ay3, &az3, &gx3, &gy3, &gz3); accelgyro.getAcceleration(&ax3, &ay3, &az3); //Accelerometer Calibration //Supply your own offsets here: Ax3=(ax3-740)/1670.13; Ay3=(ay3-550)/1670.13; Az3=(az3+1104)/1670.13; // gx3=gx3+61; // gy3=gy3+19; // gz3=gz3+32; // Read from MPU 4 on ch 4 out4(); // read raw accel/gyro measurments from device accelgyro.initialize(); //accelgyro.getMotion6(&ax4, &ay4, &az4, &gx4, &gy4, &gz4); accelgyro.getAcceleration(&ax4, &ay4, &az4); //Accelerometer Calibration //Supply your own offsets here: Ax4=(ax4+100)/1670.13; Ay4=(ay4-300)/1670.13; Az4=(az4-100)/1670.13; // gx4=gx4+69; // gy4=gy4+27;
  92. 92. 85 | P a g e // gz4=gz4+26; } //=========================================================================== // 15FWM - MAIN LOOP //=========================================================================== void loop() { network.update(); // Pump the network regularly // Runs Sensor Function ReadRPM(); ReadStrain(); ReadAccel(); // Sets the interval at which to run the ReadTemp function in order to prevent program data rate lag (1000 ms currently) unsigned long now = millis(); if (now - last_sent >= interval) { last_sent = now; ReadTemp(); } // Places all sensor values into the struct "packet" in order to be sent payload packet = {this_node, now, rpm, Ax1, Ay1, Az1, Ax2, Ay2, Az2, Ax3, Ay3, Az3, Ax4, Ay4, Az4, S1, S2, S3, S4, T1, T2, T3, T4}; RF24NetworkHeader header(/*to node*/ other_node); network.write(header,&packet,sizeof(packet)); // Uncomment during main operation of the code // // Uncomment in order to check if sensor data is being read // Serial.print(packet.timer); Serial.print("t"); Serial.print(packet.RPM); Serial.print("t"); // Serial.print(packet.aX1); Serial.print("t"); Serial.print(packet.aY1); Serial.print("t"); Serial.print(packet.aZ1); Serial.print("t"); // Serial.print(packet.aX2); Serial.print("t"); Serial.print(packet.aY2); Serial.print("t"); Serial.print(packet.aZ2); Serial.print("t"); // Serial.print(packet.aX3); Serial.print("t"); Serial.print(packet.aY3); Serial.print("t"); Serial.print(packet.aZ3); Serial.print("t"); // Serial.print(packet.aX4); Serial.print("t"); Serial.print(packet.aY4); Serial.print("t"); Serial.print(packet.aZ4); Serial.print("t"); // Serial.print(packet.st1); Serial.print("t"); Serial.print(packet.st2); Serial.print("t"); Serial.print(packet.st3); Serial.print("t"); Serial.print(packet.st4); Serial.print("t");
  93. 93. 86 | P a g e // Serial.print(packet.Temp1); Serial.print("t"); Serial.print(packet.Temp2); Serial.print("t"); Serial.print(packet.Temp3); Serial.print("t"); Serial.println(packet.Temp4); // // bool ok = network.write(header,&packet,sizeof(packet)); // Serial.print("Sending..."); // if (ok) // Serial.println("ok."); // else // Serial.println("failed."); }

×