2024-03-12 16:24:30 +01:00

View File

@@ -111,9 +111,12 @@ the code used looks like this:
DHT dht(DHTPIN, DHTTYPE); DHT dht(DHTPIN, DHTTYPE);
void setup() { void setup() {
//the //the serial port:
Serial.begin(9600); Serial.begin(9600);
//the initial test if the code works
Serial.println(F("DHTxx test!")); Serial.println(F("DHTxx test!"));
//the library start
dht.begin(); dht.begin();
} }
@@ -121,9 +124,12 @@ dht.begin();
void loop() { void loop() {
delay(2000); delay(2000);
//a float has decimal numbers and the library reads the measurements.
float h = dht.readHumidity(); float h = dht.readHumidity();
float t = dht.readTemperature(); float t = dht.readTemperature();
float f = dht.readTemperature(true); float f = dht.readTemperature(true);
//isnan = there is no reading , the || is "or"
if (isnan(h) || isnan(t) || isnan(f)) { if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!")); Serial.println(F("Failed to read from DHT sensor!"));
@@ -164,11 +170,13 @@ This output signal can activate over multiple pins so this one button can set of
The code is short and simple: The code is short and simple:
``` ```
//set up some variables
int button = 20; int button = 20;
int buzzerone = 12; int buzzerone = 12;
int buzzertwo = 11; int buzzertwo = 11;
void setup() { void setup() {
//put down some pins that will output , and some that input.
pinMode(button, INPUT); pinMode(button, INPUT);
pinMode(buzzerone, OUTPUT); pinMode(buzzerone, OUTPUT);
pinMode(buzzertwo, OUTPUT); pinMode(buzzertwo, OUTPUT);
@@ -177,6 +185,7 @@ pinMode(buzzertwo, OUTPUT);
void loop() { void loop() {
//read is there is input on the button pin, if so send output to the other pins., otherwise keep them off.
if(digitalRead(button) == HIGH){ if(digitalRead(button) == HIGH){
digitalWrite(buzzerone, HIGH); digitalWrite(buzzerone, HIGH);
digitalWrite(buzzertwo, HIGH); digitalWrite(buzzertwo, HIGH);