#include <EEPROM.h>
int thermistorPin = A0; // Arduino-pin connected between thermistor and 10k-resistor
int Vo;
float R1 = 10000; // Constant resistor-value
float T0 = 298.15; // T0 for thermistor
float Rntc, temp, temp_c; //
float beta = 3486; // Found via https://www.elfadistrelec.no/Web/Downloads/_t/ds/bx_cx_dx_gx_rx-series_eng_jap_tds.pdf
float temperatureInC(int pinNumber){
/*Calculates temperature in celsius using a simplified version of
the Steinhart-Hart-formula
*/
int voltage;
voltage = analogRead(pinNumber);
Rntc = R1 * (1023.0 / Vo - 1.0); // 1023 is the number og analog-levels on arduino-pin
temp = 1 / T0;
temp += 1/beta * log(Rntc/R1);
temp = 1 / temp; // Here the temperature is calculated in Kelvin
temp = temp - 273.15;
return temp;
}
int address = 0;
int address2 = 0;
int valueEEPROM = analogRead(thermistorPin) / 5;
float tempEEPROM(int something){
EEPROM.read(something);
}
void setup() {
Serial.begin(9600);
}
void loop() {
float printValue = valueEEPROM * 5;
for(int i = 0; i < 12; i++){
EEPROM.write(address, valueEEPROM);
address++;
delay(3000);
if(address = EEPROM.length()){
address = 0;
}
if(EEPROM.read(address2) != 0){
temp_c = temperatureInC(printValue);
Serial.print(temp_c);
address2++;
}
}
}
I am a poorly experienced programmer and have only been programing in c on the arduino for about two weeks as part of a school-subject (in other words: don't be too harsh if my code is completely useless). What I want and try to do here, is reading an analog-pin (A0) and store that value in EEPROM. When an address's value no longer equals to 0, I want to convert this value to a temperature in celsuis and print this on-screen. Using the delay-function, the loop reads the thermistorpin every 3000nd millisecond, hence, the temperature is being calculated every 3000nd millisecond. For later, I would also want to advance the code to write at what time the different measurements from the different addresses were taken, but I think I would be able to manage myself.
This is all part of an assignment that calls for us to measure the temperature in a room over the course of a day. The arduino will be left in the room with a battery as the power-source. The data shall be retrieveable when the computer is connected to the arduino and I figured using EEPROM would be fitting for this task.
So far the code will compile for the arduino, but nothing is being printed.
I am using an arduino Uno