How to make a 'function generator' with an increasing frequency

Hi, we have to make a 'function generator' with an arduino and it has to have square waves with an increasing frequency. Could someone explain to us how to make this or even write a code for us because we have no idea how we could do this. We do not know the frequencies yet so is it possible to write a code where we can write the frequencies in later and alter them? Is it also possible to alter rise in frequency? Hopefully someone can help us.

How much are you paying?

Do you have any specifications on frequency range and duration?

Voltage or current output specifications?

Flokjo:
Hi, we have to make a 'function generator' with an arduino and it has to have square waves with an increasing frequency. Could someone explain to us how to make this or even write a code for us because we have no idea how we could do this. We do not know the frequencies yet so is it possible to write a code where we can write the frequencies in later and alter them? Is it also possible to alter rise in frequency? Hopefully someone can help us.

. Reminds me a lot of this

Start by making a square wave, then add the frequency-sweep. Take it one small step at a time and "develop" your program until it does everything it's supposed to do.

If this is for sound, you'll need a piezo transducer or an amplified/powered speaker. (Don't directly connect a 4-Ohm or 8-Ohm speaker!)

The [u]Blink Example[/u] generates a 1/2 Hz square wave (high for one second, low for one second, giving a period of 2 seconds or a frequency of 1/2 Hz). A shorter delay will, of course, give you a higher frequency.

The [u]tone()[/u] function also generates a square wave.

A [u]for-loop[/u] will allow you to change the time or frequency very time through the loop. You can use a delay in the loop to determine how fast the frequency sweeps.

We do not know the frequencies yet so is it possible to write a code where we can write the frequencies in later and alter them?

You need to define the following variables:

StartFrequency
EndFrequency
SweepTime (or SweepSpeed)

Of course, you don't have to use those exact variable names. And, you can start-out with fixed values (constant "literals") instead of variables (like the "1000" in the Blink example).

Hi, we have to make a 'function generator' with an arduino and it has to have square waves

FYI - That would be a square wave generator, not a function generator. A function generator generates a variety of different wave shapes, and is not an easy thing to make with an Arduino which doesn't have a DAC.

Thanks for your reaction DVDdoug. We found this on the arduino website https://www.arduino.cc/en/Tutorial/DueSimpleWaveformGenerator and that is exactly what we need however we want to increase the frequency. Can you help us with that because we have no experience with these arduino boards. By the way we want this code for electromagnets because we need to change the polarity of the electromagnets faster and faster. However maybe we can also use a normal sin wave. But I am not sure. We have to do this for a school project.

Ah, the old x-y problem

My crystal ball sees an anti-gravity project. Suspending an object above an electromagnet, aka magnetic repulsion. Is that your goal?

Not really, we are building a miniature Hyperloop and we are levitating it with permanent magnets however for the propulsion system we use electromagnets. These electromagnets need to switch their polarity after a certain amount of time and this faster and faster. However we are complete noobs so we have not clue how to program this.