I am wanting to use Arduino Uno to create a variable frequency generator. Frequency controlled by one potentiometer. The frequency to be displayed on a 16*2 LCD display.
I know how to do it using a 555 timer and Schmitt trigger, but I want to eliminate these 2 items and do it all with the Arduino Uno. Are there any examples on the internet with circuit and code? Thanks.
And of course you did you google "Arduino variable frequency generator"... what was wrong with the answers? what did you try?
What is the range of frequency and the ratio of ON/OFF time of a cycle?
Yes, I did google that. I found one example titled: "How to make a simple variable frequency generator." It uses a Arduino mini Pro, not a Arduino Uno. Problem was there was several commercial ads covering up important information.
You don't say anything about the frequency. You do not say anything about the signal shape or duty cycle. For the simplest option, I can think of a tone () and use only an Arduino. For a complex option, you will need additional hardware similar to the AD9833.
Here is how I am wanting to construct. I want to wire a potentiometer into an ADC of the Arduino Uno. This is basically a volt meter on the micro. I want to use a timer interruption to create a time base to replace the 555. Then I want to wire the LCD display to the Arduino. I understand basis of how to do it, but not the hookup to Arduino and the code.
I am wanting from the Arduino Uno-- square wave generator with variable frequency. I want that frequency displayed on the 16*2 LCD display.
Hello KeithHilton
Post your current sketch, well formated, with comments and in so called code tags "</>" and schematic to see how we can help.
Have a nice day and enjoy coding in C++.
I have it figured out! I hooked the Arduino and LCD display up and ran the code below. It worked. The only thing that did not work was a RED LED I had hooked up. analogOut Pin = 6
I am trying to also figure out where to come off with a signal to a op-amp that will drive a line level signal. Below is the code that worked. I used a 10K pot. I am new at C++ so forgive my mistakes doing code tags!
//include the library code
#include<LiquidCrystal.h>
//initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,5,4,3,2);
//Analog input pin that the potentiometer wiper is attached to
const int analogInPin= A0;
//Analog output pin that the red LED is attached to.
const int analogOutPin = 6;
int potvalue=0;
int outputvalue=0;
void setup()
{
//setup the LCD's number of colums and rows and clear it.
lcd.begin(16,2);
lcd.clear();
//set the first printing on the first row, starting at left most.
lcd.setCursor (0, 0);
lcd.print("Song Frequency");
}
void loop()
{
//read the analog value
potvalue = analogRead(analogInPin);
//generate the frequency at the same value
tone(8,potvalue);
//set the cursor on the second line, starting at left most.
lcd.setCursor(0,1);
lcd.print(potvalue);
lcd.print("HZ");
delay(1000);
//stop the waveform and start with the new analog input value.
noTone(8);
}
Sorry about that---I did not use a 10K pot, it was a 5K pot.
I think I know why my red LED is not lighting up.
code says: const int analogOutPin =6
In my circuit I have the anode of the LED hooked to digital output 6. The cathode is not the problem, it is hooked to ground through a 1K resistor.
Arduino Uno does not have a analog out pin 6, so I will plug it into pin 5 on the analog.
My solution to getting the red LED lighting up did not work, so I hooked it up back to digital pin 6. I got out the digital logic probe I made, and it showed a low signal going to the anode of the LED not a pulse signal. I reversed the anode and cathode and that still did not light up the LED.
At this point I don't know what I need to do to get the LED lighting up?
Connect the anode terminal of your RED LED at digital DPin-8 (the tone pin). Slowly vary the pot and check that LED blinks. Connect a pizeo buzzer at DPin-8 and observe that it delivers sound.
Nothing to do with C++, please read How to get the best out of this forum and modify your post accordingly (including code tags)
Your LED doesn't work, maybe because you don't use it anywhere in your program - you don't define it as an output and you don't turn it on / off or whatever you want it to do. Your program is limited to 1023Hz (the tone command executes a minimum frequency of 31Hz). Yoy don't want a bigger range? If you want a larger range you can use a map (). Also, I think it's better not to use noTone () just to change the frequency.
Still can’t see code tags in post #10
Hi, @KeithHilton
To add code please click this link;
What frequency range are you aiming for it to work over?
Thanks.. Tom...
Lower case Z - Hz.
Thanks to all who have replied, it has helped me understand. I still have some questions, and I will address them individually.
GolamMostafa --Thanks for your help! I changed the code to const int analogOutPin =8 I hooked the red LED's anode to digital pin 8 and the LED glowed red. I thought it would dim or brighten as I turned the 5K potentiometer who's wiper is connected to analog pin A0. The LED stayed the same brightness as I turned the potentiometer. No change in brightness turning the potentiometer--and---I am wondering why? Maybe you can help? If I want to add another output, can I simply say in the code something like const int analogOutPin =9 ? Then hook to digital pin 9 and ground?
flashko---Thanks for your help! You are correct about the LED. I changed the code to const int analogOutPin = 8 Then hooked the anode of the LED to digital pin 8, and lit the LED.
You are 1/2 correct in saying the LCD frequency print out is limited to 1023Hz and a minimum of 31Hz. In reading the LCD, yes 1023Hz is the maximum Hz, but my LCD will go all the way down to 0Hz. So the arrangement is not limited to 31Hz. Wonder why? Now about not using noTone() in the code. Are you saying to eliminate it from the code and everything will work OK?
TomGeorge---To answer your question, 0 to 1023Hz is the range I was hoping for.
I do have a question for everyone: As I turn the 5K potentiometer and look at the LCD print out, something strange happens. In the range of 1023 to around 842Hz-----there is only one Hz printed on the LCD screen. Below 842Hz there are two zz's. Meaning Hzz. Sometimes when I take the Hz down below 100Hz I will get three z's. Meaning Hzzz. Why is this doing this?
I'm guessing (without looking at your code) that the mystery 'z's are because you are not clearing the lcd line first, before writing to it.