Skip to content

11. Input devices

Welcome to Input Devices Week! This week, we’re delving into the realm of input devices tailored for microcontrollers. From buttons to sensors, join us as we explore the diverse range of tools that empower interaction with microcontroller-based systems.

Types of sensors

Temperature Sensors

These measure temperature variations and are used in applications ranging from weather monitoring to industrial processes.

Pressure Sensors

They detect changes in pressure and are employed in devices like barometers, blood pressure monitors, and industrial equipment.

Proximity Sensors

These sensors detect the presence or absence of nearby objects without physical contact, commonly used in smartphones for touchless interfaces and in industrial machinery for object detection.

Motion Sensors

Used to detect movement, these sensors are prevalent in security systems, automatic doors, and gaming consoles.

Light Sensors

Also known as photodetectors, these sensors measure light intensity and are found in cameras, automatic lighting systems, and solar panels.

Humidity Sensors

These measure the moisture content in the air and are crucial in weather stations, HVAC systems, and industrial processes.

Accelerometers

They detect changes in velocity or acceleration and are extensively used in devices like smartphones, gaming controllers, and vehicle airbag systems.

Gyroscopes

These sensors measure angular velocity or rotational motion and are utilized in devices such as drones, navigation systems, and virtual reality headsets.

Magnetic Sensors

Used to detect magnetic fields, these sensors are found in compasses, electronic devices, and automotive applications like speedometers.

Gas Sensors

These detect the presence of various gases and are used in environmental monitoring, industrial safety, and air quality control.

Biometric Sensors

They measure unique biological traits such as fingerprints, iris patterns, or facial features and are employed in security systems, access control, and smartphones for authentication.

Force Sensors

These measure the force applied to them and are utilized in applications like industrial automation, medical devices, and automotive systems.

Sound Sensors/Microphones

They detect sound waves and are found in smartphones, voice recognition systems, and noise pollution monitoring devices.

The Sensor I used

Sound Sensor

This is the pin out for the sound sensor

Microcontroller Board

For the electronics Design week I had made a breakout board for the seed Xiao RP2040

I used the same PCB to connect the sound sensor. During the whole day there is a lot of chaos and noise around and I just need 5 mins of the time to be alone and silent so what I did was when there will be sound going beyond 50 Decibel level the red light would turn on which would indicate that Pleasee leave me alone!!!

Lights up when it goes beyond 40 Decibel level

The output

the serial monitor prints the decibel level

The code

// Pin definitions
const int soundSensorPin = A1; // GPIO 0 for sound sensor
const int ledPin = D7;         // GPIO 1 for LED

// Threshold for sound level to detect speech
const float speechThreshold = 39.0; // Adjust this threshold as needed

void setup() {
  pinMode(soundSensorPin, INPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, LOW); // Ensure LED is initially off
  Serial.begin(9600);
}

void loop() {
  // Read the analog value from the sound sensor
  int soundValue = analogRead(soundSensorPin);

  // Convert analog value to decibels (assuming linear relationship, may vary with sensor)
  float soundDecibel = 20 * log10(soundValue);

  // Print the sound level in decibels to the serial monitor
  Serial.print("Sound level (dB): ");
  Serial.println(soundDecibel);

  // If sound level exceeds the speech threshold, turn on the LED
  if (soundDecibel > speechThreshold) {
    digitalWrite(ledPin, HIGH); // Turn on LED
  } else {
    digitalWrite(ledPin, LOW); // Turn off LED
  }

  // Add a delay to avoid flooding the serial monitor
  delay(500);
}

Sign Board

I made this sign board for the people so that they dont get confused about the LED

Group Assignment

For the group work Please refer to Himanshi Jain’s Webpage : Himanshi Jain

Code Files

Sound Sensor