Basic computer programming knowledge is crucial for modern mechanical engineer. Having knowledge of basic computer programming allows gives a mechanical engineer several advantages
- It allows them to complete data collection that would take hours to do manually in a matter of minutes.
- It give them the ability custom modify a program to take data easily.
- It gives them the ability to solve some systems electronically vs. mechanically could save time, materials, and money durring production.
To develop a great program with minimal effort it is easiest to start with some example code. The example code can then be modified to fit the situation. The easiest way to find the commands for modifying the example code with is by using a schema.
Sample Data
The following data chart is water being reduced to room temperature from 160 degrees farhenheit.
Code
/*
*Temperature Data Logger
*/
int time = 0;
int temperaturePin = 0; //determines the input pin for the temperature sensor
float gtemperature; //global variable to transfer an int version of the value
//coming from the sensor
void setup()
{
Serial.begin(9600); //Start the serial connection with the copmuter to view the result open the serial monitor
}
void loop() //loops the program
{
gtemperature = tempreading(); //converts the temperature reading to an int
Serial.println("Temperature"); //Prints "Temperature" to debug screen
Serial.println(gtemperature); //Shows the temperature variable value for debugging
Serial.println("Time"); //Prints "Time" to debug screen
Serial.println(time); //Shows the temperature variable value for debugging
delay(900); //waiting 9ms
time = time+1; //Shows the temperature variable value for debugging
}
float tempreading() //Function for reading the temperature sensor and
//returning a float variable
{
float temperature = getVoltage(temperaturePin); //getting the voltage reading from the temperature sensor
temperature = (((temperature - .5) * 100)*1.8)+32; //converting from mv to degrees fahrenheit
delay(100); //waiting a tenth second
return temperature;
}
float getVoltage(int pin) //getVoltage() - returns the voltage on the analog input defined by pin
{
return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}
{
return (analogRead(pin) * .004882814); //converting from a 0 to 1023 digital range to 0 to 5 volts (each 1 reading equals ~ 5 millivolts
}
Code Features
My code has several useful features. It reads temperature in farhenheit to make it easy to verify that the data is relevant. It also seperates the time and temperature onto seperate lines to make it easier to chart later.
Reflective Thinking
It would have been much easier to chart the data if it had already been in columns. This could have been done by modifying the lines of code that tell the program to output to the screen to evenly space the data on the same line.
Data logging and code development was done in collaboration with Jason Hurst.
Data logging and code development was done in collaboration with Jason Hurst.
No comments:
Post a Comment