Hello,
I am a beginner (please use laymen's terms or something I can easily look up).
How do I set up and program an LED to flash at 190 Hz??
Thank you!
Hello,
I am a beginner (please use laymen's terms or something I can easily look up).
How do I set up and program an LED to flash at 190 Hz??
Thank you!
Take a look at the blink without delay example, and do some arithmetic.
Or, use the [u]tone()[/u] function.
Why do you need to flash an LED at 190Hz?
Your eyes/brain can only detect flashing at a maximum of a few Hz, so it will look as it is on continuously.
JohnLincoln:
Why do you need to flash an LED at 190Hz?Your eyes/brain can only detect flashing at a maximum of a few Hz, so it will look as it is on continuously.
Indeed, however, this is not for me. Many insects, especially flies, communicate in wing beat frequencies.
A flashing LED fly repellant! Brilliant! The kid wanting an innovative science fair project may be interested in this. Are you an entomologist? Can this phenomenon also be used with mosquitoes?
ChrisTenone:
A flashing LED fly repellant! Brilliant! The kid wanting an innovative science fair project may be interested in this. Are you an entomologist? Can this phenomenon also be used with mosquitoes?
It is not a repellent but an attractant. (It is much easier to get an insect to do what it already wants to do.)
Many flies use light reflected of their wings (flashing wing frequency) to recognize potential mates. Yes, I am an entomologist at Ohio University. Yes, it works with mosquitos (patent pending).
DVDdoug:
Or, use the [u]tone()[/u] function.
Thank you for your help. I also need the LED to run at a 3% duty cycle. I used the tone function coupled with digital write and delay microseconds (see below). Does this code look correct.
void setup()
{
//pinMode(12, OUTPUT);
tone (13, 290);
}
void loop()
{
digitalWrite(13, HIGH);
delayMicroseconds(8.7); // Approximately 3% duty cycle @ 1KHz
digitalWrite(13, LOW);
delayMicroseconds(290-8.7);//3% of the hertz
}
I also need the LED to run at a 3% duty cycle. I used the tone function coupled with digital write and delay microseconds (see below). Does this code look correct.
Not at all.
First, if you are not using the square wave (50%on--50%off) forget about using tone(). You can delete it from the sketch.
Do you want 190 Hz, or 290 Hz at 3% duty cycle?
Your math is not correct. Also, delayMicroseconds() does not take a value with a decimal point.
One period at 290 Hz = 1/290 = 3448 microseconds. 3% duty cycle on is 103 microseconds on and 3345 microseconds off.
One period at 190 Hz= 1/190 = 5263 microseconds. 3% duty cycle on is 158 microseconds on and 5105 microseconds off.
Using delay to generate the on/off times will block your program from doing anything else. You can generate the pulse using the method of the "blink without delay" example in the 02 - Digital examples of the IDE.
Another approach would be to use the TimerOne library which as a PWM function which you can set for a period and a duty cycle. It is available through the library manager.
Very interesting project. I learned something reading OP's response. To set duty cycle in a nicer way, use TimerOne library:
http://playground.arduino.cc/Code/Timer1
Here is some simple code:
#include <TimerOne.h>
#define freq 190 ///< Operating frequency
#define full_duty 1024 ///< The PWM has 0-1023 duty range
#define PWMPin 13
int duty=3.0/100.0*full_duty
void setup()
{
Timer1.initialize(1000000UL/freq);
Timer1.pwm(PWMPin, duty);
}
void loop()
{
// nothing to do or you can write some code to adjust the duty cycle or frequency for different insects?
}
liuzengqiang:
Very interesting project. I learned something reading OP's response. To set duty cycle in a nicer way, use TimerOne library:
Very nice indeed. Thanks for posting that.
Southpark:
Very nice indeed. Thanks for posting that.
I was using this library to control the output of an IR laser (pulse width is related to output power). Here is what it looks like:
https://www.youtube.com/watch?v=JJ7qNUc7Dn4
The full code is a bit long but can be provided if someone is interested. You need an arduino, an LCD and a rotary encoder for the user interface.
cecropia99:
It is not a repellent but an attractant. (It is much easier to get an insect to do what it already wants to do.)
Many flies use light reflected of their wings (flashing wing frequency) to recognize potential mates. Yes, I am an entomologist at Ohio University. Yes, it works with mosquitos (patent pending).
Thank you for that information! This sounds like a fascinating project.