Advertisement
safwan092

Untitled

Nov 9th, 2021
325
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. int analogValue; // This is where we'll store our audio to digital value. More sound = higher number
  2. int LED_Pin = 13; // Set up the LED indicator
  3. int Sound_Pin = A0;
  4. boolean toggle = false; // setup a boolean function called toggle which will help us to choose which mode we're in
  5. int t =548 ;
  6. void setup()
  7. {
  8. pinMode(LED_Pin,OUTPUT); // Pin#5 should be conencted to an LED through a 300-600 ohm resistor
  9. Serial.begin(9600); // This is optional - It just helps you to calibrate sensitivity after the fact
  10. }
  11.  
  12. void loop()
  13. {
  14. /*analogValue = analogRead(Sound_Pin);
  15. Serial.println(analogValue);
  16. delay(50);*/
  17.  
  18. if (toggle == false) // When you power up your arduino, boolean "toggle" is set to false, so the following section of code will commence. The "ELSE" is ignored for now.
  19. {
  20. digitalWrite(LED_Pin,LOW); // Turn the LED off
  21. analogValue = analogRead(Sound_Pin); // Take an analog reading from A0 line. No sounds should be offer a returned value of "0"
  22.  
  23. if (analogValue >t) // If higher than 8 is returned, then change state of boolean "toggle" to true, display analogValue to serial monitor and wait 200ms.
  24. // The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to your wanted sensitivity =D
  25. {
  26. toggle = true;
  27. Serial.println(analogValue);
  28. delay(200);
  29. }
  30. }
  31. else // If boolean "toggle" has beenchanged to true, then the above section of code will be ignored, and the code below will commence.
  32. {
  33. digitalWrite(LED_Pin,HIGH); // Turn the LED on
  34. analogValue = analogRead(0); // Take an analog reading from A0 line. No sounds should be offer a returned value of "0"
  35.  
  36. if (analogValue > t) // If higher than 8 is returned, then change state of boolean "toggle" back to false, print analogValue to serial monitor and wait 200ms.
  37. // The higher the value in the above "if" statement, the less sensitive your clapper will be. Use the serial monitor to calibrate to your wanted sensitivity =D
  38. {
  39. toggle = false;
  40. Serial.println(analogValue);
  41. delay(200);
  42. }
  43. }
  44.  
  45. }
  46.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement