11. Input devices
THIS WEEK GROUP ASSIGNMENT(click the title)
Examples of input devices
Input devices can be defined as hardware components that allow users to feed data or instructions into a computer system. They translate human actions or physical conditions into signals that a computer can understand and process such as sensors and microphones.
What I did
I used the PCB I designed on electronics week and used during output week and used it to connect a microphone that lights up LEDs when it receives a signal above a
certain level.
For this project, I integrated a microphone with my custom-designed PCB and Seeeduino XIAO (RP32C2). The PCB facilitated easy connection
and reliable performance, allowing the LEDs to light up in response to sound signals.
Introduction
I used the PCB I designed during output week and used it to connect a microphone that lights up NeoPixel LEDs when it receives a signal above a certain level. In this project, I integrated a microphone with my custom-designed PCB and Seeeduino XIAO (RP32C2). The LEDs respond dynamically to sound levels, providing visual feedback.
Hardware Setup
- Microphone: Connected to the analog input pin A0 on the XIAO.
- NeoPixel LEDs: Connected to pin 7 on the XIAO via the custom-designed PCB.
Arduino Code
Here’s the Arduino sketch used to control the NeoPixel LEDs based on microphone input:
#include <Adafruit_NeoPixel.h>
#ifdef AVR
#include <avr/power.h> // Required for 16 MHz Adafruit Trinket
#endif
#define PIN 7 // Output pin
#define NUMPIXELS 60 // Number of NeoPixels
Adafruit_NeoPixel pixels(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
#define DELAYVAL 1 // Delay value in milliseconds
const int pinAdc = A0;
void setup() {
Serial.begin(115200);
pixels.begin(); // Initialize NeoPixel object (REQUIRED)
}
void loop() {
long sum = 0;
for (int i = 0; i < 32; i++) {
sum += analogRead(pinAdc);
}
sum >>= 5; // Divide by 32 using bit shift
Serial.println(sum);
delay(1);
// Turn on NeoPixel LEDs if analog signal is greater than 1000
if (sum > 1000) {
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(255, 255, 255)); // White color
}
pixels.show(); // Show the color
} else {
for (int i = 0; i < NUMPIXELS; i++) {
pixels.setPixelColor(i, pixels.Color(0, 0, 0)); // Turn off LEDs
}
pixels.show(); // Show the change
}
delay(DELAYVAL); // Add delay if needed
}
Explanation
- The code initializes the NeoPixel library and sets up communication via Serial for debugging.
- Inside the
loop()
function, it reads the analog value from the microphone connected topinAdc
. - If the average analog value exceeds 1000, all NeoPixel LEDs are set to white (255, 255, 255).
- Otherwise, all NeoPixel LEDs are turned off (0, 0, 0).
- The
delay(DELAYVAL)
ensures stable operation and adds a slight delay between operations.
having detected the microphone i changed the bauds to 17500 so it would detect the sound and i was not really sure what it was but changing that parameter worked in that the microphone started receiving signals.
This is how it looked at the end
Conclusion
I´m sure i can improve the functioning as the copper that isn't completly covered are making a lot of noise and it makes so that the reading im getting from the microphone isnt completely acurate and is making so that theres a delay when im receiving the data of the microphone and as far as i tested it is not the delay from the code.