Last active
July 30, 2019 00:54
-
-
Save futureshocked/f8cfd0e547a22fae39410705cb8941b8 to your computer and use it in GitHub Desktop.
This sketch demonstrates how to use the Grove sound sensor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* 04.030 - Grove sound sensor | |
| * | |
| This sketch demonstrates how to use the Grove sound sensor. | |
| The sound sensor is an analog device. It outputs a voltage | |
| level that depends on the intensity of the sound it captures. | |
| This sketch calculates the volume of the sound based on the | |
| last 32 samples it captures. | |
| Upload this sketch and start the Serial monitor (you can also use | |
| the serial plotter). Clap your hands near the sensor and notice the | |
| change in the output displayed in the monitor. | |
| Components | |
| ---------- | |
| - Grove Base Shield | |
| - An Arduino Uno compatible board (such as Arduino/Genuino Uno or Seeeduino) | |
| - Grove sound sensor | |
| - One Grove cable | |
| IDE | |
| --- | |
| Arduino IDE | |
| Libraries | |
| --------- | |
| - | |
| Connections | |
| ----------- | |
| Use a Grove cable to connect the sound sensor module to Base Shield connector A0. | |
| Other information | |
| ----------------- | |
| - Use this sketch along side the video lecture 04.030 of Grove For Busy People | |
| - Grove documentation: http://wiki.seeedstudio.com/Grove-Sound_Sensor/ | |
| - Grove component: https://txplo.re/e171e | |
| - Bitshift right operator: https://www.arduino.cc/reference/en/language/structure/bitwise-operators/bitshiftright/ | |
| Github Gist | |
| ----------- | |
| <script src="https://gist.github.com/futureshocked/f8cfd0e547a22fae39410705cb8941b8.js"></script> | |
| https://gist.github.com/futureshocked/f8cfd0e547a22fae39410705cb8941b8 | |
| For course information, please go to https://techexplorations.com/product/grove-for-busy-people/ | |
| Created on July 5 2019 by Peter Dalmaris | |
| */ | |
| const int pinAdc = A0; // Analog pin A0 is available through Grove connector A0 | |
| void setup() | |
| { | |
| Serial.begin(115200); | |
| } | |
| void loop() | |
| { | |
| long sum = 0; | |
| for(int i=0; i<32; i++) | |
| { | |
| sum += analogRead(pinAdc); | |
| } | |
| sum >>= 5; // The >> operator is "bitshift right". It will shift the value stored in sum by 5 bits to the right. | |
| Serial.println(sum); | |
| delay(10); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment