I would appreciate help. I want to transmit a word in PWM modulation, at a relatively high frequency (4kHz). My goal is to use the laser to transmit information while the duty cycle represents the information. Does anyone have an example of something similar or can direct me how to do it?
This tutorial might be helpful: IR Communication - SparkFun Learn
Start with an LED, then graduate to a laser diode.
Timer0 on the Atmega328 can do that for you and give you two channels with 4KHz PWM
Outputs on D5 and D6
Calculated with this web timer calculator
/**
* URL: https://dbuezas.github.io/arduino-web-timers/#mcu=ATMEGA328P&timer=0&clockPrescalerOrSource=8&timerMode=PCPWM&CompareOutputModeA=clear-up%2C+set-down&OCR0A=190&CompareOutputModeB=set-up%2C+clear-down&OCR0B=121
* Mode : PCPWM
* Period : 255 us
* Frequency: 3.92157 kHz
* Outputs :
* - D6: 74.51%, clear-up, set-down
* - D5: 54.12%, set-up, clear-down
*/
void setup(){
noInterrupts();
TCCR0A =
1 << COM0A1 |
1 << COM0B1 |
1 << COM0B0 |
1 << WGM00;
TCCR0B =
1 << CS01;
DDRD =
1 << DDD5 |
1 << DDD6;
interrupts();
}
void loop() {
OCR0A = 190;// change this value from 0-255 to get your desired PWM
OCR0B = 117; // or this one as second output channel
}
That seems to require three different PWM widths. One width for idle, one for a zero and another for a one.
The goal is to transfer information to 100-200, I don't think that Led will allow me to do that
Do you have a recommendation for a good detector?
100 - 200 what? The best approach is to get the circuit working on your bench, with an LED, before moving out into the wild, where you have to deal with extreme background interference from sunlight, the aiming problem, etc.
It already works at ten meters at lower frequencies (500 Hz) so I'm currently trying to increase the frequency. Agree that I don't need to jump forward quickly, but it already works on the table
What is limiting your project to ten meters?
The size of the lab
If you have already have the thing working, why did you post such a vague, completely misleading question?
What is your real question?
Many years before there was an internet, data was sent from building to building in a campus environment using IR. Just like the IR remote controls, they used an IR light modulated, off/on, at a high frequency to eliminate noise and interference from sunlight. Then the modulated the base frequency to add data to the signal. Decoded at the receiving end, just like your TV decodes the remote control.
Is this what you are trying to do?
No, but the idea is quite close.
As I wrote, it works at low frequencies (500Hz), but I want to transmit the information at 4000Hz because 500 is too slow
The TimerOne library can do PWM at different frequencies:
Here's its FanSpeed example (for 4kHz you'd use 250us):
#include <TimerOne.h>
// This example creates a PWM signal with 25 kHz carrier.
//
// Arduino's analogWrite() gives you PWM output, but no control over the
// carrier frequency. The default frequency is low, typically 490 or
// 3920 Hz. Sometimes you may need a faster carrier frequency.
//
// The specification for 4-wire PWM fans recommends a 25 kHz frequency
// and allows 21 to 28 kHz. The default from analogWrite() might work
// with some fans, but to follow the specification we need 25 kHz.
//
// http://www.formfactors.org/developer/specs/REV1_2_Public.pdf
//
// Connect the PWM pin to the fan's control wire (usually blue). The
// board's ground must be connected to the fan's ground, and the fan
// needs +12 volt power from the computer or a separate power supply.
const int fanPin = 4;
void setup(void)
{
Timer1.initialize(40); // 40 us = 25 kHz
Serial.begin(9600);
}
void loop(void)
{
// slowly increase the PWM fan speed
//
for (float dutyCycle = 30.0; dutyCycle < 100.0; dutyCycle++) {
Serial.print("PWM Fan, Duty Cycle = ");
Serial.println(dutyCycle);
Timer1.pwm(fanPin, (dutyCycle / 100) * 1023);
delay(500);
}
}
Nothing mysterious I just don't know how to explain what I'm building because it doesn't have a name.
A system that transmits a code using an infrared laser, the sensor verifies the code and sends a new
code. It should be something similar to a laser tag, it's not a complicated project
I described it in the original post
I would appreciate it if you could expand on this, it sounds very interesting and could help me.
In addition, if you have an example of the code that someone wrote for it, I would appreciate it if you could send it to me or a link to it.
Bro, it's not my idea or anything like that, a teacher told me to build a communication system using a laser, that's how he described it to me, I'm trying to figure out how to build it. I managed to write code that works up to 500 Hz and after that my measurement and transmission go crazy.
So show the code? Your working sub-500Hz demo sounds like a great example of what you want to do at 4kHz.