Morse Code Communication Using Laser Module (Both)
This is using the laser transmitter and receiver to communicate, and using the Morse code given by the laser transmitter to the receiver.
Components and supplies
2
Breadboard (generic)
1
Jumper wires (generic)
1
Photo resistor
2
Arduino UNO
1
LASER TRANSMITTER
Apps and platforms
1
Arduino IDE
Project description
Code
CODE-1- FOR CONTROLLING THE LASER EMITTER
arduino
1int led13 = 13; // blink an led on output 13 2 3/* 4 Set the speed of your morse code 5 Here are the ratios code elements: 6 Dash length = Dot length x 3 7 Pause between elements = Dot length 8*/ 9int dotLen = 200; // length of the morse code 'dot' 10int dashLen = dotLen * 3; // length of the morse code 'dash' 11int elemPause = dotLen;// length of the pause between elements of a character 12int Spaces = dotLen * 3; // length of the spaces between characters 13int wordPause = dotLen * 7; // length of the pause between words 14 15void setup() { 16 // initialize the digital pin as an output for LED lights. 17 pinMode(led13, OUTPUT); 18} 19 20// Create a loop of the letters/words you want to output in morse code (defined in string at top of code) 21void loop() 22{ 23 24 // Loop through the string and get each character one at a time until the end is reached 25 for (int i = 0; i < sizeof(stringToMorseCode) - 1; i++) 26 { 27 // Get the character in the current position 28 char tmpChar = stringToMorseCode[i]; 29 // Set the case to lower case 30 tmpChar = toLowerCase(tmpChar); 31 // Call the subroutine to get the morse code equivalent for this character 32 GetChar(tmpChar); 33 } 34 35 // At the end of the string long pause before looping and starting again 36 LightsOff(8000); 37} 38 39// DOT 40void MorseDot() 41{ 42 digitalWrite(led13, HIGH); // turn the LED on 43 delay(dotLen); // hold in this position 44} 45 46// DASH 47void MorseDash() 48{ 49 digitalWrite(led13, HIGH); // turn the LED on 50 delay(dashLen); // hold in this position 51} 52 53// Turn Off 54void LightsOff(int delayTime) 55{ 56 digitalWrite(led13, LOW); // turn the LED off 57 delay(delayTime); // hold in this position 58} 59 60// *** Characters to Morse Code Conversion *** // 61void GetChar(char tmpChar) 62{ 63 // Take the passed character and use a switch case to find the morse code for that character 64 switch (tmpChar) { 65 case 'a': 66 MorseDot(); 67 LightsOff(elemPause); 68 MorseDash(); 69 LightsOff(elemPause); 70 break; 71 case 'b': 72 MorseDash(); 73 LightsOff(elemPause); 74 MorseDot(); 75 LightsOff(elemPause); 76 MorseDot(); 77 LightsOff(elemPause); 78 MorseDot(); 79 LightsOff(elemPause); 80 break; 81 case 'c': 82 MorseDash(); 83 LightsOff(elemPause); 84 MorseDot(); 85 LightsOff(elemPause); 86 MorseDash(); 87 LightsOff(elemPause); 88 MorseDot(); 89 LightsOff(elemPause); 90 break; 91 case 'd': 92 MorseDash(); 93 LightsOff(elemPause); 94 MorseDash(); 95 LightsOff(elemPause); 96 MorseDot(); 97 LightsOff(elemPause); 98 break; 99 case 'e': 100 MorseDot(); 101 LightsOff(elemPause); 102 break; 103 case 'f': 104 MorseDot(); 105 LightsOff(elemPause); 106 MorseDot(); 107 LightsOff(elemPause); 108 MorseDash(); 109 LightsOff(elemPause); 110 MorseDot(); 111 LightsOff(elemPause); 112 break; 113 case 'g': 114 MorseDash(); 115 LightsOff(elemPause); 116 MorseDash(); 117 LightsOff(elemPause); 118 MorseDot(); 119 LightsOff(elemPause); 120 break; 121 case 'h': 122 MorseDot(); 123 LightsOff(elemPause); 124 MorseDot(); 125 LightsOff(elemPause); 126 MorseDot(); 127 LightsOff(elemPause); 128 MorseDot(); 129 LightsOff(elemPause); 130 break; 131 case 'i': 132 MorseDot(); 133 LightsOff(elemPause); 134 MorseDot(); 135 LightsOff(elemPause); 136 break; 137 case 'j': 138 MorseDot(); 139 LightsOff(elemPause); 140 MorseDash(); 141 LightsOff(elemPause); 142 MorseDash(); 143 LightsOff(elemPause); 144 MorseDash(); 145 LightsOff(elemPause); 146 break; 147 case 'k': 148 MorseDash(); 149 LightsOff(elemPause); 150 MorseDot(); 151 LightsOff(elemPause); 152 MorseDash(); 153 LightsOff(elemPause); 154 break; 155 case 'l': 156 MorseDot(); 157 LightsOff(elemPause); 158 MorseDash(); 159 LightsOff(elemPause); 160 MorseDot(); 161 LightsOff(elemPause); 162 MorseDot(); 163 LightsOff(elemPause); 164 break; 165 case 'm': 166 MorseDash(); 167 LightsOff(elemPause); 168 MorseDash(); 169 LightsOff(elemPause); 170 break; 171 case 'n': 172 MorseDash(); 173 LightsOff(elemPause); 174 MorseDot(); 175 LightsOff(elemPause); 176 break; 177 case 'o': 178 MorseDash(); 179 LightsOff(elemPause); 180 MorseDash(); 181 LightsOff(elemPause); 182 MorseDash(); 183 LightsOff(elemPause); 184 break; 185 case 'p': 186 MorseDot(); 187 LightsOff(elemPause); 188 MorseDash(); 189 LightsOff(elemPause); 190 MorseDash(); 191 LightsOff(elemPause); 192 MorseDot(); 193 LightsOff(elemPause); 194 break; 195 case 'q': 196 MorseDash(); 197 LightsOff(elemPause); 198 MorseDash(); 199 LightsOff(elemPause); 200 MorseDot(); 201 LightsOff(elemPause); 202 MorseDash(); 203 LightsOff(elemPause); 204 break; 205 case 'r': 206 MorseDot(); 207 LightsOff(elemPause); 208 MorseDash(); 209 LightsOff(elemPause); 210 MorseDot(); 211 LightsOff(elemPause); 212 break; 213 case 's': 214 MorseDot(); 215 LightsOff(elemPause); 216 MorseDot(); 217 LightsOff(elemPause); 218 MorseDot(); 219 LightsOff(elemPause); 220 break; 221 case 't': 222 MorseDash(); 223 LightsOff(elemPause); 224 break; 225 case 'u': 226 MorseDot(); 227 LightsOff(elemPause); 228 MorseDot(); 229 LightsOff(elemPause); 230 MorseDash(); 231 LightsOff(elemPause); 232 break; 233 case 'v': 234 MorseDot(); 235 LightsOff(elemPause); 236 MorseDot(); 237 LightsOff(elemPause); 238 MorseDot(); 239 LightsOff(elemPause); 240 MorseDash(); 241 LightsOff(elemPause); 242 break; 243 case 'w': 244 MorseDot(); 245 LightsOff(elemPause); 246 MorseDash(); 247 LightsOff(elemPause); 248 MorseDash(); 249 LightsOff(elemPause); 250 break; 251 case 'x': 252 MorseDash(); 253 LightsOff(elemPause); 254 MorseDot(); 255 LightsOff(elemPause); 256 MorseDot(); 257 LightsOff(elemPause); 258 MorseDash(); 259 LightsOff(elemPause); 260 break; 261 case 'y': 262 MorseDash(); 263 LightsOff(elemPause); 264 MorseDot(); 265 LightsOff(elemPause); 266 MorseDash(); 267 LightsOff(elemPause); 268 MorseDash(); 269 LightsOff(elemPause); 270 break; 271 case 'z': 272 MorseDash(); 273 LightsOff(elemPause); 274 MorseDash(); 275 LightsOff(elemPause); 276 MorseDot(); 277 LightsOff(elemPause); 278 MorseDot(); 279 LightsOff(elemPause); 280 break; 281 default: 282 // If a matching character was not found it will default to a blank space 283 LightsOff(Spaces); 284 } 285} 286
CODE-2 - FOR THE RECEIVER END
arduino
1int sensorPin = 0; // select the input pin for ldr 2int sensorValue = 0; // variable to store the value coming from the sensor 3int a, f; // flags 4void setup() { 5Serial.begin(9600); //sets serial port for communication 6} 7void loop() { 8 9sensorValue = analogRead(sensorPin); // read the value from the sensor 10//Serial.println(sensorValue); 11if(sensorValue>1000)// calculating the number of dots and dashes 12{ 13 for(int i=0;i<=13;i++) 14 { 15 sensorValue=analogRead(sensorPin); 16 if(sensorValue>1000) 17 { 18 a++; //calculating the number of dots and dashes in the character 19 delay(200); 20 } 21 else 22 { 23 f++; // calculating the number of spaces in dots and dashes 24 delay(200); 25 } 26 27 } 28} 29//Serial.print("a= "+a); 30//Serial.println("f= "+f); 31//Serial.println(); 32/* 33 * Checking the set of dots, dashes and spaces 34 */ 35 36if(a==4 && f==10) 37{ 38 Serial.print("a"); 39} 40if(a==6 && f==8) 41{ 42 Serial.print("b"); 43} 44if(a==8 && f==6) 45{ 46 Serial.print("c"); 47} 48if(a==1 && f==13) 49{ 50 Serial.print("e"); 51} 52if(a==2 && f==12) 53{ 54 Serial.print("i"); 55} 56if(a==10 && f==4) 57{ 58 Serial.print("j"); 59} 60if(a==7 && f==7) 61{ 62 Serial.print("g"); 63} 64if(a==9 && f==5) 65{ 66 Serial.print("o"); 67} 68if(a==3 && f==11) 69{ 70 Serial.print("s"); 71} 72f=a=0; 73delay(200); 74 75}
CODE-1- FOR CONTROLLING THE LASER EMITTER
arduino
1int led13 = 13; // blink an led on output 13 2 3/* 4 Set the speed of your morse code 5 Here are the ratios code elements: 6 Dash length = Dot length x 3 7 Pause between elements = Dot length 8*/ 9int dotLen = 200; // length of the morse code 'dot' 10int dashLen = dotLen * 3; // length of the morse code 'dash' 11int elemPause = dotLen;// length of the pause between elements of a character 12int Spaces = dotLen * 3; // length of the spaces between characters 13int wordPause = dotLen * 7; // length of the pause between words 14 15void setup() { 16 // initialize the digital pin as an output for LED lights. 17 pinMode(led13, OUTPUT); 18} 19 20// Create a loop of the letters/words you want to output in morse code (defined in string at top of code) 21void loop() 22{ 23 24 // Loop through the string and get each character one at a time until the end is reached 25 for (int i = 0; i < sizeof(stringToMorseCode) - 1; i++) 26 { 27 // Get the character in the current position 28 char tmpChar = stringToMorseCode[i]; 29 // Set the case to lower case 30 tmpChar = toLowerCase(tmpChar); 31 // Call the subroutine to get the morse code equivalent for this character 32 GetChar(tmpChar); 33 } 34 35 // At the end of the string long pause before looping and starting again 36 LightsOff(8000); 37} 38 39// DOT 40void MorseDot() 41{ 42 digitalWrite(led13, HIGH); // turn the LED on 43 delay(dotLen); // hold in this position 44} 45 46// DASH 47void MorseDash() 48{ 49 digitalWrite(led13, HIGH); // turn the LED on 50 delay(dashLen); // hold in this position 51} 52 53// Turn Off 54void LightsOff(int delayTime) 55{ 56 digitalWrite(led13, LOW); // turn the LED off 57 delay(delayTime); // hold in this position 58} 59 60// *** Characters to Morse Code Conversion *** // 61void GetChar(char tmpChar) 62{ 63 // Take the passed character and use a switch case to find the morse code for that character 64 switch (tmpChar) { 65 case 'a': 66 MorseDot(); 67 LightsOff(elemPause); 68 MorseDash(); 69 LightsOff(elemPause); 70 break; 71 case 'b': 72 MorseDash(); 73 LightsOff(elemPause); 74 MorseDot(); 75 LightsOff(elemPause); 76 MorseDot(); 77 LightsOff(elemPause); 78 MorseDot(); 79 LightsOff(elemPause); 80 break; 81 case 'c': 82 MorseDash(); 83 LightsOff(elemPause); 84 MorseDot(); 85 LightsOff(elemPause); 86 MorseDash(); 87 LightsOff(elemPause); 88 MorseDot(); 89 LightsOff(elemPause); 90 break; 91 case 'd': 92 MorseDash(); 93 LightsOff(elemPause); 94 MorseDash(); 95 LightsOff(elemPause); 96 MorseDot(); 97 LightsOff(elemPause); 98 break; 99 case 'e': 100 MorseDot(); 101 LightsOff(elemPause); 102 break; 103 case 'f': 104 MorseDot(); 105 LightsOff(elemPause); 106 MorseDot(); 107 LightsOff(elemPause); 108 MorseDash(); 109 LightsOff(elemPause); 110 MorseDot(); 111 LightsOff(elemPause); 112 break; 113 case 'g': 114 MorseDash(); 115 LightsOff(elemPause); 116 MorseDash(); 117 LightsOff(elemPause); 118 MorseDot(); 119 LightsOff(elemPause); 120 break; 121 case 'h': 122 MorseDot(); 123 LightsOff(elemPause); 124 MorseDot(); 125 LightsOff(elemPause); 126 MorseDot(); 127 LightsOff(elemPause); 128 MorseDot(); 129 LightsOff(elemPause); 130 break; 131 case 'i': 132 MorseDot(); 133 LightsOff(elemPause); 134 MorseDot(); 135 LightsOff(elemPause); 136 break; 137 case 'j': 138 MorseDot(); 139 LightsOff(elemPause); 140 MorseDash(); 141 LightsOff(elemPause); 142 MorseDash(); 143 LightsOff(elemPause); 144 MorseDash(); 145 LightsOff(elemPause); 146 break; 147 case 'k': 148 MorseDash(); 149 LightsOff(elemPause); 150 MorseDot(); 151 LightsOff(elemPause); 152 MorseDash(); 153 LightsOff(elemPause); 154 break; 155 case 'l': 156 MorseDot(); 157 LightsOff(elemPause); 158 MorseDash(); 159 LightsOff(elemPause); 160 MorseDot(); 161 LightsOff(elemPause); 162 MorseDot(); 163 LightsOff(elemPause); 164 break; 165 case 'm': 166 MorseDash(); 167 LightsOff(elemPause); 168 MorseDash(); 169 LightsOff(elemPause); 170 break; 171 case 'n': 172 MorseDash(); 173 LightsOff(elemPause); 174 MorseDot(); 175 LightsOff(elemPause); 176 break; 177 case 'o': 178 MorseDash(); 179 LightsOff(elemPause); 180 MorseDash(); 181 LightsOff(elemPause); 182 MorseDash(); 183 LightsOff(elemPause); 184 break; 185 case 'p': 186 MorseDot(); 187 LightsOff(elemPause); 188 MorseDash(); 189 LightsOff(elemPause); 190 MorseDash(); 191 LightsOff(elemPause); 192 MorseDot(); 193 LightsOff(elemPause); 194 break; 195 case 'q': 196 MorseDash(); 197 LightsOff(elemPause); 198 MorseDash(); 199 LightsOff(elemPause); 200 MorseDot(); 201 LightsOff(elemPause); 202 MorseDash(); 203 LightsOff(elemPause); 204 break; 205 case 'r': 206 MorseDot(); 207 LightsOff(elemPause); 208 MorseDash(); 209 LightsOff(elemPause); 210 MorseDot(); 211 LightsOff(elemPause); 212 break; 213 case 's': 214 MorseDot(); 215 LightsOff(elemPause); 216 MorseDot(); 217 LightsOff(elemPause); 218 MorseDot(); 219 LightsOff(elemPause); 220 break; 221 case 't': 222 MorseDash(); 223 LightsOff(elemPause); 224 break; 225 case 'u': 226 MorseDot(); 227 LightsOff(elemPause); 228 MorseDot(); 229 LightsOff(elemPause); 230 MorseDash(); 231 LightsOff(elemPause); 232 break; 233 case 'v': 234 MorseDot(); 235 LightsOff(elemPause); 236 MorseDot(); 237 LightsOff(elemPause); 238 MorseDot(); 239 LightsOff(elemPause); 240 MorseDash(); 241 LightsOff(elemPause); 242 break; 243 case 'w': 244 MorseDot(); 245 LightsOff(elemPause); 246 MorseDash(); 247 LightsOff(elemPause); 248 MorseDash(); 249 LightsOff(elemPause); 250 break; 251 case 'x': 252 MorseDash(); 253 LightsOff(elemPause); 254 MorseDot(); 255 LightsOff(elemPause); 256 MorseDot(); 257 LightsOff(elemPause); 258 MorseDash(); 259 LightsOff(elemPause); 260 break; 261 case 'y': 262 MorseDash(); 263 LightsOff(elemPause); 264 MorseDot(); 265 LightsOff(elemPause); 266 MorseDash(); 267 LightsOff(elemPause); 268 MorseDash(); 269 LightsOff(elemPause); 270 break; 271 case 'z': 272 MorseDash(); 273 LightsOff(elemPause); 274 MorseDash(); 275 LightsOff(elemPause); 276 MorseDot(); 277 LightsOff(elemPause); 278 MorseDot(); 279 LightsOff(elemPause); 280 break; 281 default: 282 // If a matching character was not found it will default to a blank space 283 LightsOff(Spaces); 284 } 285} 286
CODE-2 - FOR THE RECEIVER END
arduino
1int sensorPin = 0; // select the input pin for ldr 2int sensorValue = 0; // variable to store the value coming from the sensor 3int a, f; // flags 4void setup() { 5Serial.begin(9600); //sets serial port for communication 6} 7void loop() { 8 9sensorValue = analogRead(sensorPin); // read the value from the sensor 10//Serial.println(sensorValue); 11if(sensorValue>1000)// calculating the number of dots and dashes 12{ 13 for(int i=0;i<=13;i++) 14 { 15 sensorValue=analogRead(sensorPin); 16 if(sensorValue>1000) 17 { 18 a++; //calculating the number of dots and dashes in the character 19 delay(200); 20 } 21 else 22 { 23 f++; // calculating the number of spaces in dots and dashes 24 delay(200); 25 } 26 27 } 28} 29//Serial.print("a= "+a); 30//Serial.println("f= "+f); 31//Serial.println(); 32/* 33 * Checking the set of dots, dashes and spaces 34 */ 35 36if(a==4 && f==10) 37{ 38 Serial.print("a"); 39} 40if(a==6 && f==8) 41{ 42 Serial.print("b"); 43} 44if(a==8 && f==6) 45{ 46 Serial.print("c"); 47} 48if(a==1 && f==13) 49{ 50 Serial.print("e"); 51} 52if(a==2 && f==12) 53{ 54 Serial.print("i"); 55} 56if(a==10 && f==4) 57{ 58 Serial.print("j"); 59} 60if(a==7 && f==7) 61{ 62 Serial.print("g"); 63} 64if(a==9 && f==5) 65{ 66 Serial.print("o"); 67} 68if(a==3 && f==11) 69{ 70 Serial.print("s"); 71} 72f=a=0; 73delay(200); 74 75}
Downloadable files
CONNECTIONS
CONNECTIONS

Documentation
CONNECTIONS
CONNECTIONS

CONNECTIONS
CONNECTIONS

Comments
Only logged in users can leave comments