Warning: ob_start(): function '' not found or invalid function name in /www/htdocs/w00fbde5/overunity/Sources/PortaMx/PortaMxSEF.php on line 340

Notice: ob_start(): failed to create buffer in /www/htdocs/w00fbde5/overunity/Sources/PortaMx/PortaMxSEF.php on line 340
Arduino code for pulsing H-Bridge at exact frequencies

Solid States Devices > Resonance Circuits and Systems

Arduino code for pulsing H-Bridge at exact frequencies


I just wanted to post this in case it helps others..

Using arduino and H-bridge to flip polarities, it can be difficult to pulse DC square waves at exact controllable frequencies without complex timers, etc.  And counting delay microseconds is hit or miss..

I figured out a way to use the "Tone Function" to control frequency of pulses.  Just have to change the Hz value in the code and it's dead on..  I been playing with a resonance circuit and the frequency on the scope is exact..  Be aware- it will only work up to 31 Khz tho..

!!!!!!!!!!!!!!!!!!!!!!!!!!  CODE !!!!!!!!!!!!!!!!!!!!!!!

int r1 = 6;
int r2 = 7;
int receiver = 8;

void setup(){

   pinMode(r1, OUTPUT);
   pinMode(r2, OUTPUT);
   pinMode(receiver, INPUT);
   tone(5, 1000);


void loop() {
if (receiver == HIGH)
  digitalWrite(r1, LOW);
   digitalWrite(r2, HIGH);
digitalWrite(r1, HIGH);
digitalWrite(r2, LOW);



Now on the arduino, put a jumper from D5 to D8.   And connect your H bridge PWM inputs to pins 6 and 7.  Thats it....
To change frequency-  find this code "tone(5, 1000);"   and change 1000 to whatever hertz you want up to 31000 Hz.

Maybe someone will find this useful!  Easier than messing with 555 timers..


[0] Message Index

Go to full version