# generating 55 hertz on an arduino

let me preface that I have no arduino programming experience (though I do have a little bit in python)

Is there a way I can generate 55 hz on an arduino? if so how?

This should produce a 55 Hz square wave on pin 13

``````unsigned long lastEdge;

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
unsigned long topLoop = micros();
if (topLoop - lastEdge > 9091) {  // 1000000 / (55 * 2)
lastEdge = topLoop;
}
}
``````

bravoechonovember1:
let me preface that I have no arduino programming experience (though I do have a little bit in python)

Is there a way I can generate 55 hz on an arduino? if so how?

there is loads out there on Timer Interrupts

Is there a way I can generate 55 hz on an arduino? if so how?

The tone function might be useful.

``````tone(your pin# here,55)
``````

https://www.arduino.cc/en/Reference/Tone

Whandall:
This should produce a 55 Hz square wave on pin 13

``````unsigned long lastEdge;
``````

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
unsigned long topLoop = micros();
if (topLoop - lastEdge > 9091) {  // 1000000 / (55 * 2)
lastEdge = topLoop;
}
}

thanks! I forgot to add that I have an uno this will still work right?

Yes.

``````#define OUTPUT_FREQUENCY (55) //put this near the top of your program
//...
if (topLoop - lastEdge >= 1000000UL/(OUTPUT_FREQUENCY*2)) {  // use compiler arithmetic
``````

is better.