In this assigment I used the Fabduino PCB Board, designed in past assignments. A sensor DHT22 is connected to the board. This sensor has 3 pins: +5VDC, out and GND. to read temperature and humidity.
DHT22 digital temperature and humidity sensor is a calibrated digital signal output temperature and humidity combined sensor, which application-specific modules capture technology and digital temperature and humidity sensor technology to ensure that products with high reliability and excellent long-term stability.
No pullup resistor needed. Just plug right in to Arduino or ESP8266.
1. VCC: It has a power supply of 3.5V to 5.5V.
2. Data: The temperature and humidity output signals via serial data.
3. Ground: The module usually connects to the ground of a circuit.
Main Chip:AM2302
Temperature range: -40 to 80 degree celsius
Temperature measurement accuracy: +/- 0.5℃ degree celsius
Humidity measuring range: 0~100%RH
Humidity measurement accuracy: ±2%RH
Ultra-low power consumption
No additional components
Excellent long-term stability
Single-bus digital signal output, bidirectional serial data
Completely interchangeable
Long distance signal transmission
Size: 28 x 12 x 10 mm (L / W / H)
Screw hole diameter: 2.6mm
Weight: 4g
I used my Fabduino board to do this assignment. Previously designed in other assignment: Assignment 8 Electronics Design.
So, I made the next circuit to test the sensor.
I chose the digital pin (pin D2), VCC and GND.
As we know, the DHT22 sensor has a single data output pin, which uses SDA for communication and synchronization between the microprocessor and the AM2302, single bus data format, a transmission of 40 bytes of data.
To make these measurements I used an oscilloscope, where I connected to the output pin and ground to the probe. Obtaining the following results.
In the signal you can see the levels according to the previous graph. And the voltage of 5.07V
In the programming IDE we must select the board Arduino UNO (Fabduino)
Using the FabISP to program the board in Assignment 4: Electronics Production.
The connection is shown below:
I need to install the DHT sensor library, lastest version. Go to Manage Libraries.
//Code was taken from adafruit github repository
// DHT Temperature & Humidity Sensor
// Unified Sensor Library Example
// Written by Tony DiCola for Adafruit Industries
// Released under an MIT license.
// REQUIRES the following Arduino libraries:
// - DHT Sensor Library: https://github.com/adafruit/DHT-sensor-library
// - Adafruit Unified Sensor Lib: https://github.com/adafruit/Adafruit_Sensor
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include <DHT_U.h>
#define DHTPIN D2 // Digital pin connected to the DHT sensor
// Feather HUZZAH ESP8266 note: use pins 3, 4, 5, 12, 13 or 14 --
// Pin 15 can work but DHT must be disconnected during program upload.
// Uncomment the type of sensor in use:
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// See guide for details on sensor wiring and usage:
// https://learn.adafruit.com/dht/overview
DHT_Unified dht(DHTPIN, DHTTYPE);
uint32_t delayMS;
void setup() {
Serial.begin(9600);
// Initialize device.
dht.begin();
Serial.println(F("DHTxx Unified Sensor Example"));
// Print temperature sensor details.
sensor_t sensor;
dht.temperature().getSensor(&sensor);
Serial.println(F("------------------------------------"));
Serial.println(F("Temperature Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("°C"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("°C"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("°C"));
Serial.println(F("------------------------------------"));
// Print humidity sensor details.
dht.humidity().getSensor(&sensor);
Serial.println(F("Humidity Sensor"));
Serial.print (F("Sensor Type: ")); Serial.println(sensor.name);
Serial.print (F("Driver Ver: ")); Serial.println(sensor.version);
Serial.print (F("Unique ID: ")); Serial.println(sensor.sensor_id);
Serial.print (F("Max Value: ")); Serial.print(sensor.max_value); Serial.println(F("%"));
Serial.print (F("Min Value: ")); Serial.print(sensor.min_value); Serial.println(F("%"));
Serial.print (F("Resolution: ")); Serial.print(sensor.resolution); Serial.println(F("%"));
Serial.println(F("------------------------------------"));
// Set delay between sensor readings based on sensor details.
delayMS = sensor.min_delay / 1000;
}
void loop() {
// Delay between measurements.
delay(delayMS);
// Get temperature event and print its value.
sensors_event_t event;
dht.temperature().getEvent(&event);
if (isnan(event.temperature)) {
Serial.println(F("Error reading temperature!"));
}
else {
Serial.print(F("Temperature: "));
Serial.print(event.temperature);
Serial.println(F("°C"));
}
// Get humidity event and print its value.
dht.humidity().getEvent(&event);
if (isnan(event.relative_humidity)) {
Serial.println(F("Error reading humidity!"));
}
else {
Serial.print(F("Humidity: "));
Serial.print(event.relative_humidity);
Serial.println(F("%"));
}
}
Serial Monitor console showing the temperature and humidity values
A piezoelectric sensor is a device that uses the piezoelectric effect to measure changes in pressure, acceleration, temperature, strain, or force by converting them to an electrical charge.
Piezoelectricity is the charge created across certain materials when a mechanical stress is applied. Piezoelectric pressure sensors exploit this effect by measuring the voltage across a piezoelectric element generated by the applied pressure. They are very robust and are used in a wide range of industrial applications.
1. Center: Positive terminal
2. Edge: Negative terminal
//The code is located in arduino github repository
//https://github.com/arduino/arduino-examples/blob/main/examples/01.Basics/AnalogReadSerial/AnalogReadSerial.ino
//I've modified for input pullup type pin and the time for reading serial data
const int Sensor = A2; // Sensor connected to analog pin A2
void setup()
{
pinMode(Sensor, INPUT_PULLUP);
Serial.begin(9600);
}
void loop()
{
// read the sensor and store it in the variable sensorReading:
int sensorReading = analogRead(Sensor);
delay(100);
Serial.println(sensorReading);
}
Testing Fabduino with piezo electric connected
When I press the electric piezo, a variation occurs in the analog port A2
Serial plotter ADC value vs tieme (100msec)
created with
Website Builder Software .