A simple, but useful, sketch with analog sensors is to use the raw voltage from any analog sensor to control the frequency of the sound produced. This sketch is based on the Tone2 Tutorial.
Read the voltage from the analog sensor in the normal way. Then use the Map and Tone commands to produce the tone. There are several ways that we have found this kind of system useful. First, for blind or low-vision students, it is great to have a tone produced that indicates the sensor reading. Also, sometimes when you are looking for a change in a sensor reading, it is easier to listen for a change than it is to stare at a meter or a graph.
Note that you do not need to deal with calibration in this sketch, since it is the raw voltage from the sensor that controls the frequency.
You can modify this sketch in many ways:
/* VernierFrequency (v 2017.07) This sketch produces a tone on a speaker connected to pin D9 of the Arduino. It is based on the Tone 2 tutorial. (see http://arduino.cc/en/Tutorial/Tone2). Note that you do not deal with calibration here. Any Vernier Analog sensor which uses the Sig1 (0 to 5 volt) line will work if it is plugged into the BTA 1 connector. If you want to change the range of frequencies, change the last two numbers in the line: int thisPitch = map(sensorReading, 400, 1000, 120, 1500) They are the minimum and maximum frequencies produced. If you want to change the sensitiviy of the system, change the first two numbers of the same line. They are the range of expected readings from the sensor. See www.vernier.com/arduino for details. */ int outputPin=9; void setup() { // initialize serial communications (for debugging only): Serial.begin(9600); } void loop() { // read the sensor: int sensorReading = analogRead(A0); // print the sensor reading so you know its range Serial.println(sensorReading); // map the analog input range (in this case, 400 - 1000 from the photoresistor) // to the output pitch range (120 - 1500Hz) // change the minimum and maximum input numbers below // depending on the range your sensor's giving: int thisPitch = map(sensorReading, 400, 1000, 120, 1500); // play the pitch: tone(outputPin, thisPitch, 10); delay(1); // delay in between reads for stability }
Cookie | Type | Duration | Description |
---|---|---|---|
Chatra | third party | 1 week | Used for chat widget |
CloudFlare (__cfduid) | persistent | 1 month | Used by CloudFlare service for rate limiting |
Cookie Consent: Necessary | session | 12 hours | Used to preserve cookie consent answer for necessary cookies |
Cookie Consent: Non-Necessary | persistant | 1 year | Used to preserve cookie consent answer for non-necessary cookies |
Cookie Consent: Viewed Cookie Policy | persistent | 1 year | Used to remember if user viewed the cookie policy |
Google Analytics (_ga) | persistent | 2 years | Used to distinguish users for Google Analytics |
Google Analytics (_gat) | persistent | 1 minute | Used to throttle request rate of Google Analytics |
Google Analytics (_gid) | persistent | 24 hours | Used to distinguish users for Google Analytics |
PHP Session | session | session | Used to store API results for better performance |
WooCommerce: Cart | temporary | session | Helps WooCommerce determine when cart contents/data changes. |
WooCommerce: Items in Cart | session | session | Helps WooCommerce determine when cart contents/data changes. |
WooCommerce: Session | persistent | 2 days | Helps WooCommerce by creating an unique code for each customer so that it knows where to find the cart data in the database for each customer. |
WordPress: Login Session | persistent, session | Session or 2 weeks (if user clicks remember me) | Used by WordPress to indicate that a user is signed into the website |
WordPress: Secured Account Details | persistent, session | Session or 2 weeks if user chose to remember login | Used by WordPress to securely store account details |
WordPress: Test Cookie | session | Session | Used by WordPress to check if the browser accepts cookies |
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies.