Article Catalog

  • Experiment 5-Transducer
  • Experiment 6-Environmental monitor


Experiment 5-Transducer

Overview
The purpose of this experiment is to make a project involving switches and sensors with arduino.

Materials
1 Arduino development board
2 temperature and humidity sensor
3 resistor
4 switch
5 Jumper wires

Circuit connection method
We used ThinkerCAD to create the circuit diagram.

Circuit simulation after running the code.

Production process
Connect the switch and DHT11 temperature and humidity sensor to the Arduino as per the next diagram.

First, install the library: DHT and upload the sample code.

1 Including DHT library:
2 Define the pin of the DHT sensor connection, connected to digital pin 2.
3 Define the DHT sensor type: DHT11.
4 Initialize a dht object named DHT using the pin and the previously defined type.
5 In setup (), initialize the serial monitor at a baud rate of 9600 for debugging.
6 Use the.begin () method to initialize the DHT sensor.
7 At the beginning of loop (), there is a 2-second delay. This delay is needed to give the sensor enough time to take a reading.
8 Use the readHumidity () method on dht objects to save the humidity in the h variable.
9 Read the temperature using the readTemperature () method.
10 All readings are displayed on the serial monitor.

The code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#include <dht11.h>
const int ldrPin = A0;
dht11 DHT11;

#define DHT11PIN 2

void setup()
{

Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
pinMode(ldrPin, INPUT);
}

void loop()
{ int ldrValue = analogRead(A0);
Serial.print("ldrValue = ");
Serial.println(ldrValue);
delay(500);
Serial.println("\n");

int chk = DHT11.read(DHT11PIN);

Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}

Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);

Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);

Serial.print("Temperature (oF): ");
Serial.println(Fahrenheit(DHT11.temperature), 2);

Serial.print("Temperature (K): ");
Serial.println(Kelvin(DHT11.temperature), 2);

Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

delay(2000);

}

Achievement display
When the switch is pressed, the temperature and humidity are read and the results are displayed on the serial monitor.

Summary:
Through this experiment, we successfully learned how to use the switch and sensor, and we can get the relevant information we want through the sensor.



Experiment 6-Environmental monitor

Overview
The purpose is to build an environment monitor with arduino.

Materials
1 Arduino development board
2 temperature and humidity sensor
3 LDR
4 resistor
5 Jumper wires

Circuit connection method
We used ThinkerCAD to create the circuit diagram.

Production process
Use Arduino Uno to drive the DHT11 temperature/humidity module and photoresistor.
After the program is run, the sensor will display the temperature, humidity and light intensity of the sensing test through the serial port monitor of the Arduino IDE.

The code is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
double Fahrenheit(double celsius) 
{
return 1.8 * celsius + 32;
}
double Kelvin(double celsius)
{
return celsius + 273.15;
}

double dewPoint(double celsius, double humidity)
{
double A0= 373.15/(273.15 + celsius);
double SUM = -7.90298 * (A0-1);
SUM += 5.02808 * log10(A0);
SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ;
SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ;
SUM += log10(1013.246);
double VP = pow(10, SUM-3) * humidity;
double T = log(VP/0.61078); // temp var
return (241.88 * T) / (17.558-T);
}

double dewPointFast(double celsius, double humidity)
{
double a = 17.271;
double b = 237.7;
double temp = (a * celsius) / (b + celsius) + log(humidity/100);
double Td = (b * temp) / (a - temp);
return Td;
}

#include <dht11.h>
const int ldrPin = A0;
dht11 DHT11;

#define DHT11PIN 2

void setup()
{

Serial.begin(9600);
Serial.println("DHT11 TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT11LIB_VERSION);
Serial.println();
pinMode(ldrPin, INPUT);
}

void loop()
{ int ldrValue = analogRead(A0);
Serial.print("ldrValue = ");
Serial.println(ldrValue);
delay(500);
Serial.println("\n");

int chk = DHT11.read(DHT11PIN);

Serial.print("Read sensor: ");
switch (chk)
{
case DHTLIB_OK:
Serial.println("OK");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.println("Checksum error");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.println("Time out error");
break;
default:
Serial.println("Unknown error");
break;
}

Serial.print("Humidity (%): ");
Serial.println((float)DHT11.humidity, 2);

Serial.print("Temperature (oC): ");
Serial.println((float)DHT11.temperature, 2);

Serial.print("Temperature (oF): ");
Serial.println(Fahrenheit(DHT11.temperature), 2);

Serial.print("Temperature (K): ");
Serial.println(Kelvin(DHT11.temperature), 2);

Serial.print("Dew Point (oC): ");
Serial.println(dewPoint(DHT11.temperature, DHT11.humidity));

Serial.print("Dew PointFast (oC): ");
Serial.println(dewPointFast(DHT11.temperature, DHT11.humidity));

delay(2000);

}

Achievement display
When the switch is pressed, the light intensity and temperature/humidity are read and the results are displayed on the serial monitor.

Summary
Through this experiment, we have successfully learned how to use photoresistor and temperature/humidity sensor to build environmental monitoring equipment, and we can obtain the relevant information we want through the environmental monitoring equipment built.



Reference

https://blog.csdn.net/weixin_42645653/article/details/112172242
https://blog.csdn.net/qq_44176343/article/details/111913717
https://blog.csdn.net/zbp_12138/article/details/111149026