Skip to content

Commit

Permalink
temperature
Browse files Browse the repository at this point in the history
  • Loading branch information
leon-thomm committed Oct 20, 2022
1 parent 92b6be5 commit f8a072e
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 43 deletions.
52 changes: 52 additions & 0 deletions src/buoy_wemos/temperature/temperature.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#include "../adc/adc.h"

namespace temperature {
// #define TEMP_PIN A0
#define TEMP_VOLAGE 3.3

int adc_channel;

// https://arduinomodules.info/ky-013-analog-temperature-sensor-module/

float R1 = 10000; // value of R1 on board
float logR2, R2, T;
float c1 = 0.001129148,
c2 = 0.000234125,
c3 = 0.0000000876741;
//steinhart-hart coeficients for thermistor

void init(int adc_ch) {
adc_channel = adc_ch;
// pinMode(TEMP_PIN, INPUT);
}

float read() {
int v = adc::read(adc_channel) * 1024.0;
// int v = analogRead(TEMP_PIN);

R2 = R1 * (1023.0 / (float)v - 1.0); // calculate resistance on thermistor
logR2 = log(R2);
T = (1.0 / (c1 + c2*logR2 + c3*logR2*logR2*logR2)); // temperature in Kelvin
T = T - 273.15; // convert Kelvin to Celcius
// T = (T * 9.0)/ 5.0 + 32.0; //convert Celcius to Farenheit
return T;
}
}

/*
example:
void setup()
{
Serial.begin(9600);
initialize_temp();
}
void loop()
{
Serial.print("Temperature:\t\t");
Serial.println(read_temp());
delay(1000); //waiting a second
}
*/
43 changes: 0 additions & 43 deletions src/buoy_wemos/temperature/temperature.ino

This file was deleted.

0 comments on commit f8a072e

Please sign in to comment.