Hi I have a question, my Arduino to control a laser TTL 5V .... what works out pretty well.
Only with one exception, in certain intervals he sets out and give full power ... why is that?
Here is the code:
const int analogInPin = A0; / / Analog input pin did the potentiometer is attached to
const int analogOutPin = 9; / / Analog output pin did the LED is attached to
sensor int value = 0; / / Value read from the pot
int output value = 0; / / Value output to the PWM (analog out)
void setup () {
/ / Initialize serial communications at 9600 bps:
Serial.begin (9600);
}
void loop () {
/ / Read the analog in value:
sensor analog value = read (analogInPin);
/ / Map it to the range of the analog out:
output value = map (sensor value, 0, 1023, 253, 0);
/ / Change the analog out value:
analog write (analogOutPin, output value);
/ / Print the results to the serial monitor:
Serial.print ("sensor =");
Serial.print (sensor value);
Serial.print ("\ t output =");
Serial.println (output value);
/ / Wait 2 milliseconds before the next loop
/ / For the analog-to-digital converter to settle
/ / After the load reading:
delay (2);
}
even if I take out this part of the problem still exists.:
.......
/ / Wait 2 milliseconds before the next loop
/ / For the analog-to-digital converter to settle
/ / After the load reading:
delay (2);
}
Most lasers are set up to either transmit or not. You can't vary their brightness. To do that you need a special driver circuit that uses a measurement of the output brightness to vary the power fed to the laser in real time.
Your code is using analogWrite to control the laser. That uses PWM (Pulse Width Modulation) to send a square wave signal to the laser. What changes is the percentage of the time the square wave is HIGH. At 255, the output is always on. At 254, the output is high except 1/256th of the time, when it drops to zero very briefly. At 127 the output is on 50% of the time and off 50% of the time.
This causes the laser to switch on and off. The average light output per second gives you your desired output brightness, but at any given instant the laser is either fully on, fully off, or powering up/down. (If you're just turning the power to the laser on and off then the laser pointer's voltage regulator may take time to bring the output power up to fully power or cause the power level to slide down to zero when switched off, rounding the corners of the output square wave and smoothing the output somewhat. Lasers meant for communications have a logic signal that lets you turn them on and off instantly. I just bought a pair of these from Adafruit.)
Ajatuksia:
Hi I have a question, my Arduino to control a laser TTL 5V .... what works out pretty well.
Only with one exception, in certain intervals he sets out and give full power ... why is that?
Here is the code:
const int analogInPin = A0; / / Analog input pin did the potentiometer is attached to
const int analogOutPin = 9; / / Analog output pin did the LED is attached to
sensor int value = 0; / / Value read from the pot
int output value = 0; / / Value output to the PWM (analog out)
void setup () {
/ / Initialize serial communications at 9600 bps:
Serial.begin (9600);
}
void loop () {
/ / Read the analog in value:
sensor analog value = read (analogInPin);
/ / Map it to the range of the analog out:
output value = map (sensor value, 0, 1023, 253, 0);
/ / Change the analog out value:
analog write (analogOutPin, output value);
/ / Print the results to the serial monitor:
Serial.print ("sensor =");
Serial.print (sensor value);
Serial.print ("\ t output =");
Serial.println (output value);
/ / Wait 2 milliseconds before the next loop
/ / For the analog-to-digital converter to settle
/ / After the load reading:
delay (2);
}
even if I take out this part of the problem still exists.:
.......
/ / Wait 2 milliseconds before the next loop
/ / For the analog-to-digital converter to settle
/ / After the load reading:
delay (2);
}