Introduction: Arduino Air Conditioning Model
As part of a demonstration of our team's ability to create a model of a smart train device for marketing purposes, the objective was to create a system in which a temperature sensor reads data from the circuit and converts the information into a temperature value that is both displayed on a lighted screen and focused on as to whether a fan turns on or off. The purpose is to help accommodate the riding conditions of passengers using an automated system that also acts to display the temperature in the immediate vicinity.
By using an Arduino microcontroller kit and MATLAB versions 2016b and 2017b, we were able to demonstrate these results with relative success.
Step 1: Equipment
Microcontroller Kit with the following:
-Sparkfun Red Board
-Jumper Wires (25, minimum)
Laptop (Windows 10) with USB input
3D Printed Object (optional)
Step 2: Microcontroller Setup
Consider this: the entire system is composed single units that each apply a significant factor towards the final result. For this reason, it is highly recommended to set up an image of the circuit before attaching wires in a convoluted mess.
Images of each individual model can be found in the Microcontroller tool kit's manual or at its website at https://learn.sparkfun.com/tutorials/tags/arduino?page=all.
Start with attaching the temperature sensor, potentiometer, servo connectors and LCD onto the board. It is recommended that due to the LCD's size and requirement for the number of wires for it, it should be placed on its own half of the breadboard with the other pieces on the other half and for the potentiometer to be in an area for someone to easily turn its knob.
Servo: i1-3 (GND + -)
Temp Sensor: i13-15 (- GND +)
Potentiometer: g24-26 (- GND +)
Next, begin connecting jumper wires to each pin of the microcontroller units; though arbitrary in the overall grand scheme, the design was created with these important connections:
Connecting Potentiometer to LCD: f25 -- e3
Servo GND wire: j1 -- Digital Input 9
Temp Sensor GND: j14 -- Analog Input 0
LCD inputs: e11-e15 -- Digital Input 2-5
e4 -- Digital Input 7
e6 -- Digital Input 6
(Note: If successful, both lights on the LCD's edge should flash on and the potentiometer can help adjust its brightness once given power from the adapter.)
Optional: A 3D printed object was used as part of a requirement. To avoid potential damage to the more fragile parts, an extended case was placed as a sleeve around the LCD. Measurements of the LCD's screen proved to be approximately 2-13/16" x 1-1/16" x 1/4", and thus only the height was significantly changed. If a 3D printer is readily available, consider adding a personal object, though unnecessary. Also, be aware that measurements may differ.
Step 3: MATLAB Setup
Install a more updated version of MATLAB (2016a and onward), available at the MathWorks website https://www.mathworks.com/products/matlab.html?s_tid=srchtitle. Once opened, go to Add-Ons on the Home tab and download "MATLAB Support Package for Arduino Hardware" for the microcontroller commands to be accessible.
Once completed, a test can be made to find the connectivity of the microcontroller to one's computer/laptop. After connecting them with the USB adapter from the tool kit, insert the command "fopen(serial('nada'))."
An error message will pop-up stating the connector as "COM#", which will be needed to create an arduino object as long as it is the same input at all times.
Because of the LCD not having a direct connection to the Arduino library, a new library must be created in order to display messages. A recommendation is to create a LCDAddon.m file from the LCD example found in the MATLAB help window after searching "Arduino LCD" and placing it in the +arduinoioaddons folder, or use the compressed folder attached and copy all of its content into the aforementioned folder.
If successful, then the code to create an Arduino object in MATLAB is as shown below.
Step 4: Functions
Create a MATLAB function. For the inputs, we use variables "eff" and "T_min"; for outputs, though unnecessary in the overall design, we used variable "B" as a way to contain data from the results. The "eff" input allows for managing the maximum speed of the servo, and the "T_min" input controls the minimum temperature desired. The value "B" should thus produce a matrix that contains three columns for the time, the temperature and the efficiency of the fan. Also, as a bonus to detail, the code listed below also has an if-statement such that the fan speed will be reduced by fifty percent when it gets close to the desired minimum temperature.
If all inputs and jumper wires are placed exactly and assuming the port of the arduino connection is COM4 and the function name is "fanread", the following code should be sufficient:
function [B] = fanread(Tmin,eff)
clear a; clear lcd;
t=0; t_max=15; % time in seconds
initializeLCD(lcd, 'Rows', 2, 'Columns', 2);
if eff>=1 || e<0
error('Fan will not activate unless eff is set between 0 and 1.')
for t=1:10 % number of loops/intervals
clear c; % prevent repeating error
TempC=(v-0.5)*100; % estimation for voltage ranges 2.7-5.5 V
c=['Temp ', num2str(TempC,3),'C On'];
writePWMDutyCycle(a, 'D9',eff/2); % turn on servo at half speed
c=['Temp ', num2str(TempC,3),'C On'];
writePWMDutyCycle(a, 'D9',eff); % turn on servo at speed given
c=['Temp ', num2str(TempC,3),'C Off'];
writePWMDutyCycle(a, 'D9',0); % shut down if already on
pause(3); % three seconds elapse per loop
plot(time,tempplot,'b-o') % line graph
axis([0 33 0 40])
plot([0 33],[Tmin Tmin],'r-')
plot([0 33],[Tmin+2 Tmin+2],'g-')
bar(time,act) % bar graph
Now that the function is complete, it is time to test.
Step 5: Testing
Now test the function in the command window by inserting "function_name(input_value_1,input_value_2)" and watch. Be sure that no Arduino object is already existent; if so, use command "clear a" to remove it. If errors occur, check and see if any connectors are in the wrong place or if the wrong digital or analog inputs are used. Results are expected to vary, although this may be caused by placement of certain jumper wires and the temperature sensor.
The expectations of the results should produce changes in the performance of the servo and the data on the LCD. With each three second interval, a line of text should display the temperature in Celsius and whether or not the fan is active while the fan runs at full speed, half speed or no speed. Data should most likely not be consistent, though if desiring more various results, the place the "Tmin" value close to the average temperature produced by the circuit.
Step 6: Conclusion
Though an arduous task to accomplish by trial and error, the final results proved to be rather interesting and satisfying. A system as such helps to illustrate how many complicated machines, or even some of their parts, can be seen as a collection of independent parts placed together to accomplish a specific goal.
Due to the rather simplistic design of the final project, those who have an interest in improving its performance can make tweaks and alterations in the final product that can make the project better and more elaborate. However, it does reveal weaknesses in the circuit such as the servo's activation resulting in sporadic fluctuations in the circuit's voltage reading, which can cause the system to never produce identical results. Also, there have been issues with seeing a change in servo speed when "eff" is set 0.4 and higher. Had a temperature and humidity sensor been used, the final model would be more complicated yet present more consistent values. Nevertheless, this is an experience that shows a complex machine can function as a combination of its simple parts.
We have a be nice policy.
Please be positive and constructive.