hi everyone ,i want two things to do, to differentiating DATA from temp sensor and distance sensor.,the other name is rate of change.
I use the serial sketcher.also to store the plots....THANKS
nektarios-25ma:
I use the serial sketcher.also to store the plots....THANKS
you mean the Serial Monitor ?
so; you read the two sensors and then print the result to the Serial Monitor - should be straight-forward enough.
- read the input from the temp sensor, write to a variable.
- read the input from the distance sensor, write to another variable.
- set a metronome, using millis() and interval for when to plot data.
- Serial.println() the two variables.
what's the question ?
@nektarios-25ma, if you post your program we may have a better understanding of your problem.
...R
- Take Reading1, take TimeStamp1
- ***Take Reading2, take TimeStamp2
- DeltaReading = Reading2-Reading1
- DeltaTime = TimeStamp2 - TimeStamp1
- RateOfChange = DeltaReading / DeltaTime
- Save Reading2 as Reading1
- Save TimeStamp2 as TimeStamp1
- Repeat from ***
(or take Reading2 a known elapsedTime after Reading1, if not randomly
i will try to be clear (sorry i am not familiar with english).Trying to find cheap temp sensor i fix that "https://www.allaboutcircuits.com/projects/measuring-temperature-with-an-ntc-thermistor/".But i change litle the code ,erase the comment about temp and i have nice data from serial port (and plot -the x axis prefare to be in sec-).MY MAIN QUESTION is how to do this dT/dt automatically as a second plot in the same graph simultaneusly with temp-time graph.dT/dt called differantation in math i think.
THANK YOU ALL...
nektarios-25ma:
i will try to be clear (sorry i am not familiar with english).
The problem is not with your English - it is how you present your information.
And post your program - as already requested in Reply #2
...R
/*
File........... Thermistor_Demo_Code
Purpose........ Thermistor demonstration code
Author......... Joseph Corleto
E-mail......... corleto.joseph@gmail.com
Started........ 7/25/2016
Finished....... 7/25/2016
Updated........ --/--/----
================================================================================
Notes
================================================================================
Updates
*/
//===============================================================================
// Header Files
//===============================================================================
//===============================================================================
// Constants
//===============================================================================
//Thermistor related:
/* Here we have a few constants that make editing the code easier. I will go
through them one by one.
A reading from the ADC might give one value at one sample and then a little
different the next time around. To eliminate noisy readings, we can sample
the ADC pin a few times and then average the samples to get something more
solid. This constant is utilized in the readThermistor function.
*/
const int SAMPLE_NUMBER = 10;
/* In order to use the Beta equation, we must know our other resistor
within our resistor divider. If you are using something with large tolerance,
like at 5% or even 1%, measure it and place your result here in ohms. */
const double BALANCE_RESISTOR = 9710.0;
// This helps calculate the thermistor's resistance (check article for details).
const double MAX_ADC = 1023.0;
/* This is thermistor dependent and it should be in the datasheet, or refer to the
article for how to calculate it using the Beta equation.
I had to do this, but I would try to get a thermistor with a known
beta if you want to avoid empirical calculations. */
const double BETA = 3974.0;
/* This is also needed for the conversion equation as "typical" room temperature
is needed as an input. */
const double ROOM_TEMP = 298.15; // room temperature in Kelvin
/* Thermistors will have a typical resistance at room temperature so write this
down here. Again, needed for conversion equations. */
const double RESISTOR_ROOM_TEMP = 10000.0;
//===============================================================================
// Variables
//===============================================================================
// Here is where we will save the current temperature
double currentTemperature = 0;
//===============================================================================
// Pin Declarations
//===============================================================================
//Inputs:
int thermistorPin = 0; // Where the ADC samples the resistor divider's output
//Outputs:
//===============================================================================
// Initialization
//===============================================================================
void setup()
{
// Set the port speed for serial window messages
Serial.begin(9600);
}
//===============================================================================
// Main
//===============================================================================
void loop()
{
/* The main loop is pretty simple, it prints what the temperature is in the
serial window. The heart of the program is within the readThermistor
function. */
currentTemperature = readThermistor();
Serial.println(currentTemperature);
delay(3000);
}
//===============================================================================
// Functions
//===============================================================================
/////////////////////////////
////// readThermistor ///////
/////////////////////////////
/*
This function reads the analog pin as shown below. Converts voltage signal
to a digital representation with analog to digital conversion. However, this is
done multiple times so that we can average it to eliminate measurement errors.
This averaged number is then used to calculate the resistance of the thermistor.
After this, the resistance is used to calculate the temperature of the
thermistor. Finally, the temperature is converted to celsius. Please refer to
the allaboutcircuits.com article for the specifics and general theory of this
process.
Quick Schematic in case you are too lazy to look at the site
(Ground) ----///-------|-------///---- V_supply
R_balance | R_thermistor
|
Analog Pin
*/
double readThermistor()
{
// variables that live in this function
double rThermistor = 0; // Holds thermistor resistance value
double tKelvin = 0; // Holds calculated temperature
double tCelsius = 0; // Hold temperature in celsius
double adcAverage = 0; // Holds the average voltage measurement
int adcSamples[SAMPLE_NUMBER]; // Array to hold each voltage measurement
/* Calculate thermistor's average resistance:
As mentioned in the top of the code, we will sample the ADC pin a few times
to get a bunch of samples. A slight delay is added to properly have the
analogRead function sample properly */
for (int i = 0; i < SAMPLE_NUMBER; i++)
{
adcSamples = analogRead(thermistorPin); // read from pin and store
- delay(10); // wait 10 milliseconds*
- }*
_ /* Then, we will simply average all of those samples up for a "stiffer"_
_ measurement. */_ - for (int i = 0; i < SAMPLE_NUMBER; i++)*
- {*
_ adcAverage += adcSamples*; // add all samples up . . ._
_ }_
adcAverage /= SAMPLE_NUMBER; // . . . average it w/ divide*
_ /* Here we calculate the thermistor’s resistance using the equation_
_ discussed in the article. /
rThermistor = BALANCE_RESISTOR * ( (MAX_ADC / adcAverage) - 1);
/ Here is where the Beta equation is used, but it is different_
* from what the article describes. Don't worry! It has been rearranged*
* algebraically to give a "better" looking formula. I encourage you*
* to try to manipulate the equation from the article yourself to get*
* better at algebra. And if not, just use what is shown here and take it*
* for granted or input the formula directly from the article, exactly*
_ as it is shown. Either way will work! /
tKelvin = (BETA * ROOM_TEMP) /
(BETA + (ROOM_TEMP * log(rThermistor / RESISTOR_ROOM_TEMP)));
/ I will use the units of Celsius to indicate temperature. I did this_
* just so I can see the typical room temperature, which is 25 degrees*
* Celsius, when I first try the program out. I prefer Fahrenheit, but*
* I leave it up to you to either change this function, or create*
_ another function which converts between the two units. /_
_ tCelsius = tKelvin - 273.15; // convert kelvin to celsius*_
* return tCelsius; // Return the temperature in Celsius*
}
i post the code up
Did you type in italics I doubt it.
Edit your post with the code and
- Add
** **[code]** **
before the code - Add
** **[/code]** **
after the code
/*
================================================================================
File........... Thermistor_Demo_Code
Purpose........ Thermistor demonstration code
Author......... Joseph Corleto
E-mail......... corleto.joseph@gmail.com
Started........ 7/25/2016
Finished....... 7/25/2016
Updated........ --/--/----
================================================================================
Notes
================================================================================
================================================================================
Updates
================================================================================
*/
//===============================================================================
// Header Files
//===============================================================================
//===============================================================================
// Constants
//===============================================================================
//Thermistor related:
/* Here we have a few constants that make editing the code easier. I will go
through them one by one.
A reading from the ADC might give one value at one sample and then a little
different the next time around. To eliminate noisy readings, we can sample
the ADC pin a few times and then average the samples to get something more
solid. This constant is utilized in the readThermistor function.
*/
const int SAMPLE_NUMBER = 10;
/* In order to use the Beta equation, we must know our other resistor
within our resistor divider. If you are using something with large tolerance,
like at 5% or even 1%, measure it and place your result here in ohms. */
const double BALANCE_RESISTOR = 9710.0;
// This helps calculate the thermistor's resistance (check article for details).
const double MAX_ADC = 1023.0;
/* This is thermistor dependent and it should be in the datasheet, or refer to the
article for how to calculate it using the Beta equation.
I had to do this, but I would try to get a thermistor with a known
beta if you want to avoid empirical calculations. */
const double BETA = 3974.0;
/* This is also needed for the conversion equation as "typical" room temperature
is needed as an input. */
const double ROOM_TEMP = 298.15; // room temperature in Kelvin
/* Thermistors will have a typical resistance at room temperature so write this
down here. Again, needed for conversion equations. */
const double RESISTOR_ROOM_TEMP = 10000.0;
//===============================================================================
// Variables
//===============================================================================
// Here is where we will save the current temperature
double currentTemperature = 0;
//===============================================================================
// Pin Declarations
//===============================================================================
//Inputs:
int thermistorPin = 0; // Where the ADC samples the resistor divider's output
//Outputs:
//===============================================================================
// Initialization
//===============================================================================
void setup()
{
// Set the port speed for serial window messages
Serial.begin(9600);
}
//===============================================================================
// Main
//===============================================================================
void loop()
{
/* The main loop is pretty simple, it prints what the temperature is in the
serial window. The heart of the program is within the readThermistor
function. */
currentTemperature = readThermistor();
Serial.println(currentTemperature);
delay(3000);
}
//===============================================================================
// Functions
//===============================================================================
/////////////////////////////
////// readThermistor ///////
/////////////////////////////
/*
This function reads the analog pin as shown below. Converts voltage signal
to a digital representation with analog to digital conversion. However, this is
done multiple times so that we can average it to eliminate measurement errors.
This averaged number is then used to calculate the resistance of the thermistor.
After this, the resistance is used to calculate the temperature of the
thermistor. Finally, the temperature is converted to celsius. Please refer to
the allaboutcircuits.com article for the specifics and general theory of this
process.
Quick Schematic in case you are too lazy to look at the site :P
(Ground) ----\/\/\/-------|-------\/\/\/---- V_supply
R_balance | R_thermistor
|
Analog Pin
*/
double readThermistor()
{
// variables that live in this function
double rThermistor = 0; // Holds thermistor resistance value
double tKelvin = 0; // Holds calculated temperature
double tCelsius = 0; // Hold temperature in celsius
double adcAverage = 0; // Holds the average voltage measurement
int adcSamples[SAMPLE_NUMBER]; // Array to hold each voltage measurement
/* Calculate thermistor's average resistance:
As mentioned in the top of the code, we will sample the ADC pin a few times
to get a bunch of samples. A slight delay is added to properly have the
analogRead function sample properly */
for (int i = 0; i < SAMPLE_NUMBER; i++)
{
adcSamples[i] = analogRead(thermistorPin); // read from pin and store
delay(10); // wait 10 milliseconds
}
/* Then, we will simply average all of those samples up for a "stiffer"
measurement. */
for (int i = 0; i < SAMPLE_NUMBER; i++)
{
adcAverage += adcSamples[i]; // add all samples up . . .
}
adcAverage /= SAMPLE_NUMBER; // . . . average it w/ divide
/* Here we calculate the thermistor’s resistance using the equation
discussed in the article. */
rThermistor = BALANCE_RESISTOR * ( (MAX_ADC / adcAverage) - 1);
/* Here is where the Beta equation is used, but it is different
from what the article describes. Don't worry! It has been rearranged
algebraically to give a "better" looking formula. I encourage you
to try to manipulate the equation from the article yourself to get
better at algebra. And if not, just use what is shown here and take it
for granted or input the formula directly from the article, exactly
as it is shown. Either way will work! */
tKelvin = (BETA * ROOM_TEMP) /
(BETA + (ROOM_TEMP * log(rThermistor / RESISTOR_ROOM_TEMP)));
/* I will use the units of Celsius to indicate temperature. I did this
just so I can see the typical room temperature, which is 25 degrees
Celsius, when I first try the program out. I prefer Fahrenheit, but
I leave it up to you to either change this function, or create
another function which converts between the two units. */
tCelsius = tKelvin - 273.15; // convert kelvin to celsius
return tCelsius; // Return the temperature in Celsius
}
If you want to calculate the time derivative of the data, study reply #3 carefully and make the necessary changes in the code.
If you don't understand reply #3, explain the parts of it that are causing the problem.
If the revised code does not work properly, post the revised code, using code tags, and tell us what is wrong.
THANKS YOU ALL....