Hello,
I am new to Arduino and I am looking for support.
currently, I am working on a project to read the temperature and humidity through an extender ( PCF8574AT). if I am using the Arduino pins then I will use the sense pin in the following function DHT HT(sensePin, Type) is the pin number i.e. 2 but when it comes to the extender, I am not able to define the pin that I am attaching the DHT11 to i.e. P0
here is the code that I am using
#include <DHT.h>
#include <Adafruit_Sensor.h>
#define Type DHT11
#include <LiquidCrystal.h>
int rs=7;
int en=8;
int d4=9;
int d5=10;
int d6=11;
int d7=12;
LiquidCrystal lcd(rs,en,d4,d5,d6,d7);
int sensePin=2;
DHT HT(sensePin, Type);
int wait=500;
float humidity;
float temp;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
HT.begin();
delay(wait);
lcd.begin(16,2);
}
void loop() {
lcd.setCursor(0,0);
lcd.print("Hello World!");
// put your main code here, to run repeatedly:
humidity = HT.readHumidity()-10;
temp = HT.readTemperature();
lcd.setCursor(0,1);
lcd.print("H:");
lcd.print(humidity);
lcd.print("% T:");
lcd.print(temp);
Serial.print("H:");
Serial.print(humidity);
Serial.print("% T:");
Serial.print(temp);
delay(2000);
lcd.clear();
}
You would need to install the PCF8574 library and use it to control the pins on the extender board. This instructible should give you the general idea:
BTW, the library can be installed via Tools -> Manage Libraries...
However, I am not sure, but I don't think you will be able to bind the PCF8574 pin to the DHT library via the DHT HT() function so you would probably need to read the pin directly and extract the data being transmitted instead of relying on the DHT library to do it for you. The following provides some information on how to do that and a code example:
You would need to adapt it to use the PCF8574 pin calls.
micros() returns a type unsigned long and you have declared startTime as unsigned long. The result of micros() - startTime would therefore already be of type unsigned long and would not require casting to unsigned long. The receiving variable 'live' therefore ought also be of type unsigned long, not of type byte.
Alternatively, if you want to store the result in an 8-bit byte, then you would cast the result to a byte:
live = (byte) (micros() - startTime);
You might also try explicitly initialising live to 0, i.e.:
byte live = 0;
I am not sure it is needed, but it would rule out the possibility of the variable 'live' being initialised to some random value or the value from the previous loop and behaving cumulatively.