Welcome To Atul Ravi’s Project Blog!

Arduino Based CW Oscillator

Code:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/*
Arduino CW oscillator by ESC crasci
*/

#include "pitches.h"
int buttonState = 0; 
const int threshold = 10;    // minimum reading of the sensors that generates a note
const int buttonPin =4;
const int ledPin =  5;  
// notes to play, corresponding to the 3 sensors:
int notes[] = {
  NOTE_A4
};

void setup() {
  pinMode(buttonPin, INPUT);

  pinMode(ledPin, OUTPUT);
}

void loop() {
    buttonState = digitalRead(buttonPin);

    if (buttonState == HIGH) {
      // play the note corresponding to this sensor:
      tone(8, notes[0], 20);
      digitalWrite(5,HIGH);
    }
    else{
      digitalWrite(5,LOW);
      }
  }

Pin 8: Speaker (10K resistor to be added to ground to prevent debounce)

pin 4: Button (use key of choice)

Use jacks of choice to connect all devices to the main board. I have used female 3.4mm headphone jack sockets. It’s completely up to you!

Purchase links: ( Not Affiliate)

Stereo Socket 3.5mm PCB Mount SMD [5543] : Sunrom Electronics

Enclosure 70x45x18mm Black [4795] : Sunrom Electronics

10K CFR 1/4 0.25 Watt Resistor Through Hole [4036] : Sunrom Electronics

Arduino Pro Mini 5V – QuartzComponents


Leave a Reply

Your email address will not be published. Required fields are marked *