Arduino Full Stack
Ctrlk
  • Preface
  • Part 1 - Introduction
  • Chapter 1. Getting Started with Arduino
  • Chapter 2. Programming Grammar
  • Part 2 - Sensors
  • Chapter 3. LED Sensors
  • Chapter 4. Infrared Sensors
  • Chapter 5. Audio Sensors
    • 5.1 Passive Buzzer
    • 5.2 Active Buzzer
    • 5.3 Microphone Big Sound
    • 5.4 Microphone
  • Chapter 6. Magnetic Sensors
  • Chapter 7. Touch Sensors
  • Chapter 8. Thermist Sensors
  • Chapter 9. Switches
  • Chapter 10. Other Sensors
  • Chapter 11. More Discussions on Sensors
  • Part 3 - Motors
  • Chapter 12. Motors
  • Part 4 - Display
  • Chapter 13. Display
  • Part 5 - Communication
  • Chapter 14. Communication
  • Part 6 - Arduino Based Mini Automated Vehicle
  • Chapter 15. Assemble a Mini Automated Vehicle
  • Chapter 16. Remote Control
Powered by GitBook
On this page
  1. Chapter 5. Audio Sensors

5.4 Microphone

Hardware Wiring

Microphone

Sketch

The code can be found at Examples_Arduino - sensor-kit-for-arduino - _034_Microphone - _034_Microphone.ino.

Previous5.3 Microphone Big SoundNextChapter 6. Magnetic Sensors

Last updated 7 years ago

  • Hardware Wiring
  • Sketch
int Led=13;       // Define LDE Pin
int buttonpin=3;  // Define D0 sensor's pin
int val;          // Define Variable val
void setup()
{
  pinMode(Led,OUTPUT);      // Define LED as output
  pinMode(buttonpin,INPUT); // Define sensor D0 as output
  Serial.begin(9600);
}
void loop()
{
  val=digitalRead(buttonpin); // Assign digital pin 3's value to val
  if(val==HIGH)   // if anything detected by D0 sensor, LED starts flashing
  {
    digitalWrite(Led,HIGH);
  }
  else
  {
    digitalWrite(Led,LOW);
  }
  Serial.println(val, DEC);
}