Hi there,
Need your help again.
I have succesfully implemented the smoothing piece of code for my temperture readings.
Only with the example code i found here: https://www.arduino.cc/en/tutorial/smoothing
const int numReadings = 10;
int readings[numReadings];Â Â Â // the readings from the analog input
int readIndex = 0;Â Â Â Â Â Â Â // the index of the current reading
int total = 0;Â Â Â Â Â Â Â Â Â // the running total
int average = 0;Â Â Â Â Â Â Â Â // the average
int inputPin = A0;
void setup() {
 // initialize serial communication with computer:
 Serial.begin(9600);
 // initialize all the readings to 0:
 for (int thisReading = 0; thisReading < numReadings; thisReading++) {
  readings[thisReading] = 0;
 }
}
void loop() {
 // subtract the last reading:
 total = total - readings[readIndex];
 // read from the sensor:
 readings[readIndex] = analogRead(inputPin);
 // add the reading to the total:
 total = total + readings[readIndex];
 // advance to the next position in the array:
 readIndex = readIndex + 1;
 // if we're at the end of the array...
 if (readIndex >= numReadings) {
  // ...wrap around to the beginning:
  readIndex = 0;
 }
 // calculate the average:
 average = total / numReadings;
 // send it to the computer as ASCII digits
 Serial.println(average);
 delay(1);    // delay in between reads for stability
}
..my output average reading is 23 instead of 23.4.
Somewhere in the smoothing code the digits after the comma are ignored.
My code, on line 99 is the average that prints only 23:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp; // I2C
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
char auth[] = "29bd3d4e947446a9966fe41797e26809";
//char ssid[] = "STYLEMATHOT_1";
//char pass[] = "LetMeNotIn29";
char ssid[] = "CapljeBB";
char pass[] = "Ubzkn3jumh3v";
BlynkTimer timer;
int ledState = LOW;
unsigned long previousMillis = 0;
const long intervalled = 100;
unsigned long currentMillisled;
unsigned long startMillis;
unsigned long currentMillis;
const unsigned long period = 8000;
#define PWM D8
#define relais D3
#define pirsensor D0
int pirsensorstate;
char tension12[5];
const int numReadings = 10;
int readings[numReadings];Â Â Â // the readings from the analog input
int readIndex = 0.0;Â Â Â Â Â Â Â // the index of the current reading
int total = 0.0;Â Â Â Â Â Â Â Â Â // the running total
int average = 0.0;Â
void setup() {
 Blynk.begin(auth, ssid, pass);
 timer.setInterval(2000L, myTimerEvent);
for (int thisReading = 0; thisReading < numReadings; thisReading++) {
  readings[thisReading] = 0;
 }
 lcd.init();
 lcd.clear();
 lcd.backlight();
 lcd.setCursor(0, 0);        // 0 place on row 0
 lcd.print("Opstraten...");
 Serial.begin(115200);
 delay(1000);
 lcd.clear();
 pinMode(pirsensor, INPUT);
 pinMode(PWM, OUTPUT);
 pinMode(relais, OUTPUT);
 pinMode(LED_BUILTIN, OUTPUT);
 if (!bmp.begin()) {
  lcd.print("Zoeken sensor..");
  while (1);
 }
}
void loop()
{
 Blynk.run();
 timer.run(); // Initiates BlynkTimer
total = total - readings[readIndex];
 readings[readIndex] = (bmp.readTemperature());
 total = total + readings[readIndex];
 readIndex = readIndex + 1;
 if (readIndex >= numReadings) {
  readIndex = 0;
 }
 // calculate the average:
 average = total / numReadings;
 // send it to the computer as ASCII digits
 //delay(1);    // delay in between reads for stability
 lcd.setCursor(0, 0);        // 0 place on row 0
 lcd.print(bmp.readTemperature()-2.1, 1);
 lcd.print((char)223);
 lcd.print("C");
 lcd.print(" ");
 lcd.setCursor(0, 1);
 lcd.print(average);
 analogWrite(PWM, 500);
 pirsensorstate = digitalRead(pirsensor);
 //Serial.println(digitalRead(D6));
 //***********************************************************
 //            PIR SENSOR
 //***********************************************************
 if (pirsensorstate == 1) {
  digitalWrite(relais, 1);
 }
 if (pirsensorstate == 0) {
  currentMillis = millis();
  if (currentMillis - startMillis >= period) {
   startMillis = currentMillis;
   pirsensorstate = digitalRead(pirsensor);
   if (pirsensorstate == 0) {
    digitalWrite(relais, 0);
   }
  }
 }
 //***********************************************************
 //            BLINK THE LED
 //***********************************************************
 currentMillisled = millis();
 if (currentMillisled - previousMillis >= intervalled) {
  previousMillis = currentMillisled;
  if (ledState == LOW)
   ledState = HIGH; // Note that this switches the LED *off*
  else
   ledState = LOW; // Note that this switches the LED *on*
  digitalWrite(LED_BUILTIN, ledState);
 }
 //**************************************************************
}
void myTimerEvent() {
 dtostrf(bmp.readTemperature()-2.1, 5, 1, tension12);
 Blynk.virtualWrite(V5, tension12);
 Blynk.virtualWrite(V6, 30);
 Blynk.virtualWrite(V8, 12);
}
Can any one help the get the readings with 1 digit after the comma?
By the way the raw readings from the temperature sensor are with 3 digits after the comma.