Sunday 5 April 2015

Arduino Uno, Laser, Morse Code, LCD and Humidity / Temperature Sensor


Simple Laser Communication Project


Overview

The temperature and humidity sensor sends its output to the first Ardunio Uno who creates the text which is displayed on the LCD.  The text is converted to Morse Code on the first Arduino and transmitted to the second Arduino using a red laser.

The second Arduino receives the laser light via a photosensitive resistor and decodes the received Morse Code into ASCII which it then sends both the original Morse Code and ASCII to the LCD.


  


Shopping list

Although this project looks complicated it's simply a number of smaller projects coupled together, if you're new to the Arduino take a look at 'Learning the basics'.


Hardware

  • 2 * Ardunio Uno
  • 1 * Laser Diode (Keyes KY008)
  • 1 * Photosensitive Resistor (Keyes KY018)
  • 1 * Temperature and Humidity Sensor (Keyes KY015)
  • 1 * Piezo buzzer (optional)
  • 1 * LCD 
  • 2 * 10K ohm resistors
  • 1 * 50 ohm resistor
  • 1 * 100 ohm resistor




Aurdino software and libraries



Receiver Circuit


Most of this circuit is devoted to wiring up the LCD.


















Transmitter Circuit

As a reminder the Arduino on the left in the video is responsible for reading the temperature sensor, created the text for the LCD, generating the Morse Code and transmitting through the laser.


For the Transmitting Arduino...

// Usage: morse( <pin number>, <speed WPM>, <1=beep, 0=PTT> )
//        sendmsg( "<text-to-send>" )

#include <Morse.h>
#include <dht11.h>
#define DHT11PIN 2

// Use pin 13 (built-in LED of Arduino 2009)
Morse morse(13, 8, 0);
dht11 DHT11;
String strMessage = "";

void setup()
{
    //Serial.begin(9600);
}

void loop()
{
      int chk = DHT11.read(DHT11PIN);

      Serial.print("Read sensor: ");
      switch (chk)
      {
        case 0: Serial.println("OK"); break;
        case -1: Serial.println("Checksum error"); break;
        case -2: Serial.println("Time out error"); break;
        default: Serial.println("Unknown error"); break;
      }

      // Use a . for a space as Morse Code does not have spaced!     
      strMessage = ".HUMIDITY." + String(DHT11.humidity) + ".PERCENT...TEMP.." + String(DHT11.temperature) + ".CELSIUS..";
  
      //Serial.print(strMessage);

      int intLength = strMessage.length() + 1;
      char charMessage[intLength];
      strMessage.toCharArray(charMessage, intLength);

      morse.sendmsg(charMessage);
     
      delay(30000);
}

For the receiving Arduino...

#include <LiquidCrystal.h>

int LDR_Pin = A0; //analog pin 0
int led = 13;
String strMorse = "";
String strMessage = "";
String strTemp = "";
int LDR_Maxvalue=1000;
int dot_length=800;
int dash_length=2500;
int letter_pause=2400;
int counter_high = 0;
int counter_low = 0;

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup()
{
        //Serial.begin(9600);
pinMode(led, OUTPUT);  
lcd.begin(16,2);
        lcd.setCursor(0, 0);
}

void loop()
{
int LDRReading = analogRead(LDR_Pin); 


//Serial.println(LDRReading);

if (LDRReading >= LDR_Maxvalue)
{
      counter_high++ ;
      if (counter_low > 0)
{
        //Serial.print("Low\t");
      // Serial.print(counter_low);
      // Serial.print("\n");
}

if (counter_low >= letter_pause) 
{        
                        //Serial.println(strMorse);
                        
                        switch (strMorse.toInt())
                        {
                           case 12 : 
                              Serial.println("= A");
                              strMessage += "A";
                              break;
                           case 2111 :
                              Serial.println(" = B");
                              strMessage += "B";
                              break;                           
                            case 2121 :
                             Serial.println(" = C");
                              strMessage += "C";
                              break;        
                            case 211 :
                              Serial.println(" = D");
                              strMessage += "D";
                              break;   
                            case 1:
                              Serial.println(" = E");
                              strMessage += "E";
                              break;    
                            case 1121 :
                              Serial.println(" = F");
                              strMessage += "F";
                              break;  
                            case 221 : 
                              Serial.println(" = G");
                              strMessage += "G";
                              break;
                           case 1111 :
                              Serial.println(" = H");
                              strMessage += "H";
                              break;                           
                            case 11 :
                              Serial.println(" = I");
                              strMessage += "I";
                              break;        
                            case 1222 :
                              Serial.println(" = J");
                              strMessage += "J";
                              break;   
                            case 212:
                              Serial.println(" = K");
                              strMessage += "K";
                              break;    
                            case 1211 :
                              Serial.println(" = L");
                              strMessage += "L";
                              break;  
                           case 22 : 
                              Serial.println(" = M");
                              strMessage += "M";
                              break;
                           case 21 :
                              Serial.println(" = N");
                              strMessage += "N";
                              break;                           
                            case 222 :
                              Serial.println(" = O");
                              strMessage += "O";
                              break;        
                            case 1221 :
                              Serial.println(" = P");
                              strMessage += "P";
                              break;   
                            case 2212 :
                              Serial.println(" = Q");
                              strMessage += "Q";
                              break;    
                            case 121 :
                              Serial.println(" = R");
                              strMessage += "R";
                              break;  
                            case 111 : 
                              Serial.println(" = S");
                              strMessage += "S";
                              break;
                           case 2 :
                              Serial.println(" = T");
                              strMessage += "T";
                              break;                           
                            case 112 :
                              Serial.println(" = U");
                              strMessage += "U";
                              break;        
                            case 1112 :
                              Serial.println(" = V");
                              strMessage += "V";
                              break;   
                            case 122:
                              Serial.println(" = W");
                              strMessage += "W";
                              break;    
                            case 2112 :
                              Serial.println(" =X");
                              strMessage += "X";
                              break; 
                            case 2122 :
                              Serial.println(" = Y");
                              strMessage += "Y";
                              break;    
                            case 2211 :
                              Serial.println(" = Z");
                              strMessage += "Z";
                              break; 
                            case 22222 :
                              Serial.println(" = 0");
                              strMessage += "0";
                              break;
                            case 12222 :
                              Serial.println(" = 1");
                              strMessage += "1";
                              break;       
                            case 11222 :
                              Serial.println(" = 2");
                              strMessage += "2";
                              break;      
                            case 11122 :
                              Serial.println(" = 3");
                              strMessage += "3";
                              break;   
                            case 11112 :
                              Serial.println(" = 4");
                              strMessage += "4";
                              break;   
                            case 11111 :
                              Serial.println(" = 5");
                              strMessage += "5";
                              break;   
                            case 21111 :
                              Serial.println(" = 6");
                              strMessage += "6";
                              break;   
                            case 22111 :
                              Serial.println(" = 7");
                              strMessage += "7";
                              break;   
                            case 22211 :
                              Serial.println(" = 8");
                              strMessage += "8";
                              break;   
                            case 22221 :
                              Serial.println(" = 9");
                              strMessage += "9";
                              break;
                            case 212121 :
                              Serial.println(" = ");
                              strMessage += " ";
                              break;   
                            case 221212 :
                              Serial.println(" = !");
                              strMessage += "!";
                              break;                                
                            }
                                                     
                        lcd.clear();   
                        lcd.setCursor(0, 1);
                                                
                        if (strMessage.length() >= 17) 
                        {
                          Serial.print("in loop");
                          strTemp = strMessage.substring(1, 17);
                          strMessage = strTemp; 
                        }
                        
                        lcd.print(strMessage);
                        strMorse = "";
        lcd.setCursor(0, 0);         
     
     
      counter_low=0;
digitalWrite(led, HIGH);

else 
{
//Serial.print(".");
counter_low++;
  
      if (counter_high > 0)
{
        //Serial.print("High\t");  
//Serial.print(counter_high);
}
  
      if ((counter_high <= letter_pause) && (counter_high >=dot_length))
{
        //Serial.print(counter_high);
                        strMorse += "1";
       Serial.print(".");
       lcd.print(".");
      }
  
if (counter_high > letter_pause)
{
        //Serial.print(counter_high);
                        strMorse += "2";
       Serial.print("-");
       lcd.print("-");
}

      counter_high=0;
      digitalWrite(led, LOW);
}
}

No comments:

Post a Comment