Tabular Data Display from DHT and ATM

code.pdf (185.3 KB)

The above is a code I have bee working on to read and display sensor reading from my ATM and DHT. The data is displayed in the Serial Monitor in a Tabular format for easy viewing. For some reason I am receiving the exact same data for each of the 5 reading I have it set to take and display. I am including a photo of what the Serial Monitor is showing. Each line should be different yet it is the same. My analogRead() is different each time for the ATM as you can see but the data displayed is the same.

I'd really appreciate any help.

Please post your code.
In code tags.

How exactly do I do that? It's been awhile since I posted here.

type or paste code here#include "DHT.h"
#include <Adafruit_Sensor.h>
#include <LiquidCrystal.h>
#define DHTTYPE DHT11
#define DHTPIN 5
DHT dht(DHTPIN, DHTTYPE);
float celsius =0;
float fahrenheit =0;
float h =0;
float t =0;
float f =0;
float hif =0;
float hic =0;
void setup(){
Serial.begin(9600);
dht.begin();}

void findTemps_ATM(){
float voltage =0;
float sensor =0;
sensor=analogRead(0);
voltage=(sensor + 100) * 5000 / 1024;
voltage=voltage - 500;
celsius=voltage / 10;
fahrenheit=(1.8 * celsius) + 32;}
void findTemps_DHT(){
h = dht.readHumidity();
t = dht.readTemperature();
f = dht.readTemperature(true);
if(isnan(h) || isnan(t) || isnan(f)){
Serial.println(F("Failed to read from DHT sensor!"));
return;}
hif = dht.computeHeatIndex(f, h);
hic = dht.computeHeatIndex(t, h, false);}
void displayTemps(){
Serial.println("\nTemperature\tCelsisus\tFahrenheit");
Serial.println("------------------------------------------");
for(int i=0;i<5;i++){
Serial.print("Current Temp:\t");
Serial.print(celsius, 2);
Serial.print("\t\t");
Serial.println(fahrenheit, 2);
//Serial.println(analogRead(0)); //for debugging and calibration
delay(5000);}delay(1000);
Serial.println("\nHumidity\tTemp:\tCelsisus\tFahrenheit\tIndex 
Temp:\tCelsisus\tFahrenheit");
Serial.println("-------------------------------------------------------------------------
-------------------------");
for(int i=0;i<5;i++){Serial.print(h);
Serial.print("\t\t\t");
Serial.print(t);
Serial.print("\t\t");
Serial.print(f);
Serial.print("\t\t\t\t");
Serial.print(hic);
Serial.print("\t\t");
Serial.print(hif);
Serial.println("\t");
delay(5000);}delay(1000);}
void loop(){
findTemps_ATM();
findTemps_DHT();
displayTemps();
delay(1000);}

I got it.

It looks to me like you're printing the same value five times

That's what I'm trying to get figured out, it should be changing for each reading, and I still have more sensors to add yet.

Your code formatting makes your code hard to follow, and even the IDE's auto format tool struggled, so I did a little manual formatting

#include "DHT.h"
#include <Adafruit_Sensor.h>
#include <LiquidCrystal.h>

#define DHTTYPE DHT11
#define DHTPIN 5

DHT dht(DHTPIN, DHTTYPE);

float celsius = 0;
float fahrenheit = 0;
float h = 0;
float t = 0;
float f = 0;
float hif = 0;
float hic = 0;

void setup() 
{
  Serial.begin(9600);
  dht.begin();
}

void findTemps_ATM() 
{
  float voltage = 0;
  float sensor = 0;
  sensor = analogRead(0);
  voltage = (sensor + 100) * 5000 / 1024;
  voltage = voltage - 500;
  celsius = voltage / 10;
  fahrenheit = (1.8 * celsius) + 32;
}

void findTemps_DHT() 
{
  h = dht.readHumidity();
  t = dht.readTemperature();
  f = dht.readTemperature(true);
  if (isnan(h) || isnan(t) || isnan(f)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  hif = dht.computeHeatIndex(f, h);
  hic = dht.computeHeatIndex(t, h, false);
}

void displayTemps() 
{
  Serial.println("\nTemperature\tCelsisus\tFahrenheit");
  Serial.println("------------------------------------------");
  for (int i = 0; i < 5; i++) {
    Serial.print("Current Temp:\t");
    Serial.print(celsius, 2);
    Serial.print("\t\t");
    Serial.println(fahrenheit, 2);
    //Serial.println(analogRead(0)); //for debugging and calibration
    delay(5000);
  } 
  delay(1000);
  Serial.println("\nHumidity\tTemp:\tCelsisus\tFahrenheit\tIndex
                 Temp:\tCelsisus\tFahrenheit");
  Serial.println("-------------------------------------------------------------------------
                 -------------------------");
  for (int i = 0; i < 5; i++) {
    Serial.print(h);
    Serial.print("\t\t\t");
    Serial.print(t);
    Serial.print("\t\t");
    Serial.print(f);
    Serial.print("\t\t\t\t");
    Serial.print(hic);
    Serial.print("\t\t");
    Serial.print(hif);
    Serial.println("\t");
    delay(5000);
  } 
  delay(1000);
}

void loop() 
{
  findTemps_ATM();
  findTemps_DHT();
  displayTemps();
  delay(1000);
}

I can't see what leads you to think

I don' t think I'll ever understand this programming construct.

That specific part is how my code book showed. Sensor needs to be introduced or defined so it's floated with a value of 0 since the next line assigns the value coming from analogRead(0) to sensor. Then the math is done in following lines.

I just sat down this morning and rewrote the entire code. Now I am getting the correct readings. Turned out I failed to take into account that the Sensors were only being read in the 'findTemps' sections. And then one value was displayed in the 'displayTemps'. So I have got that fixed.