Advertisement
learnelectronics

Arduino Theramin

Jan 13th, 2023
1,515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 1.32 KB | Music | 0 0
  1. /**************************************************************************
  2.  *            Arduino Theramin                                            *
  3.  *            learnelectronics                                            *
  4.  *            10 JAN 2023                                                 *
  5.  *            https://www.youtube.com/learnelectronics                    *
  6.  *            Adapted and modified from an original                       *
  7.  *            sketch by Øyvind Nydal Dahl                                 *
  8.  *            see original sketch here:                                   *
  9.  *            https://www.build-electronic-circuits.com/arduino-theremin/ *
  10.  **************************************************************************/
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19. int analogPin = A0; // Input from photoresistor connected to A0
  20. int buzzerPin = 4; // Positive buzzer pin connected to pin 4
  21.  
  22. long max_frequency = 2000; // Max frequency for the buzzer
  23.  
  24. long frequency; // The frequency to buzz the buzzer
  25. int readVal; // The input voltage read from photoresistor
  26.  
  27.  
  28. void setup() {
  29.     pinMode(buzzerPin, OUTPUT); // set a pin for buzzer output
  30.    
  31. }
  32.  
  33. void loop() {
  34.     readVal = analogRead(analogPin); // Reads 0-1023
  35.     frequency = (readVal * max_frequency) / 1023;
  36.     tone(buzzerPin, frequency);
  37.    
  38. }
  39.  
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement