You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
42 lines
933 B
Plaintext
42 lines
933 B
Plaintext
#include <Arduino.h>
|
|
|
|
const int lm35_pin = 34; /* LM35 O/P pin */
|
|
|
|
#define ADC_VREF_mV 3300.0 // in millivolt
|
|
#define ADC_RESOLUTION 4096.0
|
|
|
|
#define FILTER_LEN 15
|
|
|
|
uint32_t AN_Pot1_Buffer[FILTER_LEN] = {0};
|
|
|
|
float readADC_Avg(int pin)
|
|
{
|
|
float avg = analogRead(pin);
|
|
for (int i = 0; i < 10; i++)
|
|
{
|
|
avg = (avg + analogRead(pin)) / 2;
|
|
delay(20);
|
|
}
|
|
return avg;
|
|
}
|
|
|
|
void setup()
|
|
{
|
|
Serial.begin(115200);
|
|
pinMode(lm35_pin, INPUT);
|
|
|
|
analogSetClockDiv(255);
|
|
}
|
|
|
|
void loop()
|
|
{
|
|
float analogValue = readADC_Avg(lm35_pin);
|
|
float millivolts = analogValue * (ADC_VREF_mV / ADC_RESOLUTION) * 2;
|
|
// float millivolts = analogReadMilliVolts(lm35_pin);
|
|
float celsius = millivolts / 10; // 6.5 is the callibration offset measured using an oscilliscope
|
|
Serial.print("raw= ");
|
|
Serial.print(analogValue);
|
|
Serial.print(" in DegreeC= ");
|
|
Serial.println(celsius);
|
|
delay(1000);
|
|
} |