How to average a, int * time

bdw am bad

#include <LiquidCrystal.h>

LiquidCrystal lcd(11, 12, 2, 3, 4, 5);
int multy = A0;      // potentiometer output.
int heat = 0;        // i set up a int to compared desired temperature.
int sensorPin = A1;  // termostat output.


void setup() {
  pinMode(8, INPUT);
  pinMode(9, INPUT);
  pinMode(7, OUTPUT);
  lcd.begin(16, 2);  // set up cld.
  Serial.begin(2400);
  lcd.print("Hello world");  // make sure cld is working.
  delay(1000);
  lcd.clear();
  // rust is good.
}

void loop() {
  
  int button1 = (digitalRead(9));  //  set up  push buttons.
  int button2 = (digitalRead(8));
  int multyrn = digitalRead(multy);
  int sensorVal = analogRead(sensorPin);
  float volt = (sensorVal / 1024.0) * 5.0;  // i turn voltage into Celsius from termostat.
  float temp1 = (volt - .5) * 100;          // I want to average out temp1 / time.
  int temp2 = (temp1 + multyrn);              // I want to calibrate output with a potentiometer because my Voltage is to high for my temp sensor.
  if ( button1 >= 1) {                          // I check if I want to increase heat.
    heat = heat + 1;
  }
  if (button2 >= 1) {  // I check if I want to decreases heat.
    heat = heat - 1;
  }
  if (heat < temp1) {
    analogWrite(7, HIGH);  // Check the desired temperature + room temp to check if I need to turn on heat.
  }
  lcd.print("temp rn:");  // I start to print att values to a lcd.
  lcd.setCursor(8, 0);
  lcd.print(temp1);
  lcd.setCursor(0, 1);
  lcd.print("heat to:");
  lcd.setCursor(8, 1);
  lcd.print(heat);
  lcd.setCursor(0, 0);  // i stop.

  Serial.print(",pin 9:");  //  Serial print in stuf for diagnosis.
  Serial.print(button1);
  Serial.print(",pin 8:");
  Serial.print(button2);
  Serial.print(",heat to:");
  Serial.print(heat);
  Serial.print(",volt:");
  Serial.print(volt);
  Serial.print(",temp:");
  Serial.println(temp2);
  delay(1000);
}

Thanks for using code tags! What is the question?

Your app will be quite slow reacting to your buttons. They are read less than once per sec...
Multy is never updated in loop...
Analogwrite(HIGH) seems odd.

If you have connected them to a button, you should name them as buttons. It will help identify their purpose when you are reading the code. "pin9" tells me nothing about what the pin does.

how to average a int Overtime.
I want to take an average of temp1 over ten seconds.

Take 10 samples, add them in a sum and divide by 10...

TupButton
And outside brackets are not needed.

Arduino-Filters: Simple Moving Average

how

I am going to sleep brb

int sum=0;
for(int i=0; i<10; i++) {
    sum = sum + analogRead(somePin);
    delay(100);
}
int avg = sum/10;

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.