Skip to content

11. Input devices

This week I worked on defining my final project idea and started to getting used to the documentation process.

Assignments in this week

Group Assignment:

  • [x] probe an input device’s analog levels and digital signals

Individual assignment:

  • [ ] measure something: add a sensor to a microcontroller board that you have designed and read it

Group Assignment

This part was completed after I completed my personal assignment. Since we have already learned the data transmission format and method of DHT11 sensor. I found the memory in the laboratory and observed the following results by connecting the X1 of the memory to the GND of the board and the signal terminal SIG of DHT11 respectively. Through observation with the oscilloscope, I clearly saw that there are 43 level changes in the picture. According to the description in the datasheet of DHT11, after the initialization level of a part of the MCU, it is the data bit signal of DHT11.

Analog Input Usage: Rotary Angle Sensor

1. Principles of Rotary Angle Sensor.

By using ChatGPT,I got the following answers.
Rotary angle sensors, also known as potentiometers or angle transducers, work based on the principle of variable resistance. Here’s how they typically function:
A. Rotational Movement: These sensors are designed to measure the angular position or rotation of an object. As the object rotates, the sensor detects this movement.
B. Variable Resistance: Inside the rotary angle sensor, there is a resistive element. This element is typically a thin strip of resistive material. As the sensor rotates, the wiper (a conductive element) moves along this resistive strip.
C. Voltage Divider: The resistive strip acts as one part of a voltage divider circuit. The wiper, which moves along the strip, divides the voltage between the input and output terminals of the sensor.
D. Output Voltage: The position of the wiper along the resistive strip determines the resistance between the input and output terminals, thereby determining the output voltage of the sensor. This output voltage is typically proportional to the angular position of the sensor.
E. Measurement: By measuring the output voltage, the angular position or rotation of the sensor can be determined. This measurement is often converted into a digital signal for further processing or display.
Overall, rotary angle sensors provide a simple and effective way to measure angular position in various applications, such as robotics, automotive systems, industrial machinery, and consumer electronics.

2. Features of Rotary Angle Sensor.

The rotary angle sensor I took this time is actually a large rotating resistor. I measured it with a voltmeter and found that the resistance value is about 10K ohms. Its main working principle is to obtain different resistance value distribution by rotating the knobs at different positions, so that the output voltage signals are different.

  | Item         | Min  | Typical   | Max  | Unit |
  |--------------|------|-----------|------|------|
  | Voltage      | 4.75 | 5.0       | 5.25 | VDC  |
  | Rotary Angle | 0    | /         | 300  | Deg  |
  | Dimension    | /    | 19*19*30.1| /    | mm   |

3. Tests of Rotary Angle Sensor.

First, I used a voltmeter to actually measure the output resistance value of the module. By rotating it, I found that the maximum resistance value was 11.62 KΩ and the minimum resistance value was 0.04 KΩ.

Secondly, I connected the module to the A0/D0 interface of XIAO SAMD21, and at the same time connected an LED module to the IIC interface, and wrote the following program through ChatGPT.

/*macro definitions of Rotary angle sensor and LED pin*/
#define ROTARY_ANGLE_SENSOR A0
#define LED 5  //the Grove - LED is connected to PWM pin D3 of Arduino
#define ADC_REF 5 //reference voltage of ADC is 5v.If the Vcc switch on the seeeduino
                    //board switches to 3V3, the ADC_REF should be 3.3
#define GROVE_VCC 5 //VCC of the grove interface is normally 5v
#define FULL_ANGLE 300 //full value of the rotary angle is 300 degrees

void setup()
{
    Serial.begin(9600);
    pinMode(ROTARY_ANGLE_SENSOR, INPUT);
    pinMode(LED,OUTPUT);   
}

void loop()
{   
    float voltage;
    int sensor_value = analogRead(ROTARY_ANGLE_SENSOR);
    voltage = (float)sensor_value*ADC_REF/1023;
    float degrees = (voltage*FULL_ANGLE)/GROVE_VCC;
    Serial.println("The angle between the mark and the starting position:");
    Serial.println(degrees);

    int brightness;
    brightness = map(degrees, 0, FULL_ANGLE, 0, 255);
    analogWrite(LED,brightness);
    delay(500);
}

Finally, by rotating and twisting the rotary angle sensor, we can see that the brightness of the LED lamp post changes accordingly.

Digital Input: DHT11 Temperature & Humidity Sensor

1. Principles of DHT11 Temperature and Humidity Sensor.

The DHT11 sensor detects temperature and humidity using two main components: a capacitive humidity sensor and a thermistor.
A. Capacitive Humidity Sensor:
* The capacitive humidity sensor measures humidity levels by detecting changes in capacitance.
* It consists of a moisture-sensitive capacitor made of a polymer material.
* When exposed to air, this material absorbs or releases water molecules, causing the capacitance of the sensor to change.
* The sensor then converts this change in capacitance into an electrical signal, which is processed to determine the relative humidity.
B. Thermistor for Temperature Sensing:
* The DHT11 sensor includes a thermistor, which measures temperature by sensing changes in electrical resistance.
* The thermistor is typically made of a semiconductor material whose resistance decreases as temperature increases.
* As the ambient temperature changes, the resistance of the thermistor changes accordingly.
* The DHT11 measures this resistance and converts it into a corresponding temperature reading.
In summary, the DHT11 sensor employs a capacitive humidity sensor to measure humidity levels based on changes in capacitance caused by moisture absorption or release, and it uses a thermistor to measure temperature by detecting changes in electrical resistance. These two measurements are then processed and converted into digital signals for output.

The humidity sensing component has two electrodes with a moisture-holding substrate (usually a salt or conductive plastic polymer) in between. As the humidity rises, the substrate absorbs water vapor, resulting in the release of ions and a decrease in the resistance between the two electrodes. This change in resistance is proportional to the humidity, which can be measured to estimate relative humidity.
 The sensor also includes a NTC thermistor for measuring temperature. A thermistor is a type of resistor whose resistance varies with temperature.
Technically, all resistors are thermistors in the sense that their resistance changes slightly with temperature, but the change is typically very small and difficult to measure.
Thermistors are designed so that their resistance changes dramatically with temperature (by 100 ohms or more per degree). The term “NTC” stands for “Negative Temperature Coefficient,” which means that resistance decreases as temperature rises.

Parameters:
Relative Humidity
Resolution:16Bit
Repeatability:±1%RH
Accuracy:25℃ ±5%RH
Interchangeability:Fully interchangeable
Response time:1/e (63%)25℃ 6s
1m/s Air 6s
Hysteresis:<±0.3%RH
Long-term stability:<±0.5%RH/yr
Temperature
Resolution:16Bit
Repeatability:±1℃
Accuracy:25℃ ±2℃
Response time:1/e (63%) 10S
Electrical Characteristics
Power supply:DC 3.3~5.5V
Supply current:Measure 0.3mA Standby 60μA
Sampling period:Secondary Greater than 2 seconds

Communication protocol and Data format * Single wire bidirectional: DHT11 only have one data line with a 40-bit data. It will need different resister when you have longer cable connection.
* Data formats: 8bit humidity integer data + 8bit decimal data +8 bit temperature and humidity data + 8bit temperature decimal integer data +8 bit parity bit.

2. Features of DHT11 Temperature and Humidity Sensor.

  | Item     | Grove - DHT11 | Grove - DHT20     | Grove - DHT22     |
  | Humidity    -------------------------------------------------------|
  | Range      | 5 ~ 95%RH     | 0 ~ 100%RH        | 0 ~ 100%RH        |
  | Accuracy | ±5% (Typical) | ±3% RH(Typical)   | ±2% RH(Typical)   |
  |----------|---------------|-------------------|-------------------|
  | Temperature ---------------------------------------------------- |
  | Range      | -20 ~ 60℃     | -40 ~ 80 ℃        | -40 ~ 80 ℃        |
  | Accuracy | ±2% (Typical) | ±0.5% RH(Typical) | ±0.5% RH(Typical) |

3. Tests of DHT11 Temperature and Humidity Sensor.

First, I connect the DHT11 sensor to the interface of D0, and then output the following program.

// Example testing sketch for various DHT humidity/temperature sensors
#include <Arduino.h>
#include <U8x8lib.h>
#include <Wire.h>
#include "Grove_Temperature_And_Humidity_Sensor.h"
U8X8_SSD1306_128X64_NONAME_HW_I2C u8x8(/* clock=*/ PIN_WIRE_SCL, /* data=*/ PIN_WIRE_SDA, /* reset=*/ U8X8_PIN_NONE);   // OLEDs without Reset of the Display
// Uncomment whatever type you're using!
#define DHTTYPE DHT11   // DHT 11

/*Notice: The DHT10 and DHT20 is different from other DHT* sensor ,it uses i2c interface rather than one wire*/
/*So it doesn't require a pin.*/
#define DHTPIN 0     // what pin we're connected to(DHT10 and DHT20 don't need define it)
DHT dht(DHTPIN, DHTTYPE);   //   DHT11 DHT21 DHT22

void setup() {
    u8x8.begin();
    u8x8.setFlipMode(1);   // set number from 1 to 3, the screen word will rotary 180
    Serial.begin(115200);
    Serial.println("DHTxx test!");
    Wire.begin();

    /*if using WIO link,must pull up the power pin.*/
    // pinMode(PIN_GROVE_POWER, OUTPUT);
    // digitalWrite(PIN_GROVE_POWER, 1);
    dht.begin();
}

void loop() {
    float temp_hum_val[2] = {0};
    // Reading temperature or humidity takes about 250 milliseconds!
    // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
    u8x8.setFont(u8x8_font_chroma48medium8_r);
    u8x8.setCursor(0, 0);

    if (!dht.readTempAndHumidity(temp_hum_val)) {
        Serial.print("Humi: ");
        Serial.print(temp_hum_val[0]);
        Serial.print(" %\t");
        Serial.print("Temp: ");
        Serial.print(temp_hum_val[1]);
        Serial.println(" *C");

        u8x8.print("Humi: ");
        u8x8.print(temp_hum_val[0]);
        u8x8.println(" %\t");
        u8x8.print("Temp: ");
        u8x8.print(temp_hum_val[1]);
        u8x8.println(" *C");

    } else {
        Serial.println("Failed to get temprature and humidity value.");
        u8x8.print("Failed to get temprature and humidity value."); 
    }
    delay(1500);
}

Finally I saw the sensor readings from both the serial monitor and the OLED display.