// KY-009 Laser Transmitter Demo by Brad White 12/09/2015 /* Don't forget to open Arduino's serial monitor to see the ouput * from this sketch. The serial monitor can be opened by clicking the serial monitor icon located * in the top right corner of the Arduino interface, or select TOOLS / Serial Monitor * or press CTRL+SHIFT+M */ int Laser = 2; // creating a variable named Laser which is assigned to digital pin 2 int voltage = 0; // creating a variable named voltage and setting is value to zero void setup() { Serial.begin(9600); // starting the USB serial interface and setting the baud rate (transmission speed) to 9600 pinMode (Laser,OUTPUT); // designating digital pin 2 for output (we can use "Laser" instead of the pin # because we assigned pin 2 to Laser above) digitalWrite(Laser,LOW); // just making sure the laser is off at startup or reset } void loop() { digitalWrite(Laser,HIGH); // turning the laser on voltage = analogRead(A0); //reading the voltage on A0 and storing the value received in "voltage" float voltage1 = voltage * (5.0 / 1023.0); // transforming the value stored in "voltage" to readable information Serial.print("the laser is ON and the voltage on the center pin is "); //sending that sentence to the serial monitor Serial.println(voltage1); // adding the value in voltage1 to the end of the sentence above and starting a new line on the monitor Serial.println(); // adding a blank line for readability delay(1000); // waiting for one second before continuing sketch digitalWrite(Laser,LOW); // turning the laser off voltage = analogRead(A0); // reading the voltage on A0 and storing the value received in "voltage" float voltage2 = voltage * (5.0 / 1023.0); // transforming the value stored in "voltage" to readable information Serial.print("the laser is OFF and the voltage on the center pin is "); // sending that sentence to the serial monitor Serial.println(voltage2); // adding the value in voltage2 to the end of the sentence above and starting a new line on the monitor Serial.println(); // adding a blank line for readability delay(1000); // waiting for one second before continuing sketch /* You can play with a couple of things with this sketch * 1. you can play with the "delay" times, turning the laser on and off faster or slower * 2. place a resistor in-line with the power to the module resulting in differant voltages * displaying on the serial monitor. */ }