Thermal Printer, Panel Printer, with Arduino RS232, Serial Communication

Thermal Printer, Panel Printer, with Arduino RS232, Serial Communication



Features


1) Compact Design

2) High Speed

3) High Resolution
4) Light Weight
5) Low Noise
6) Easy Loading
7) Electrostatic Protection
8) Tough Body
9) Pannel Paper Cutter

Outline

Printing Method: Thermal
Paper Width: 57.5mm
Paper Diameter: 55mm
Resolution: 203DPI
Printing Speed: Up to 90mm/s
Barcode Supported: I25,UPC-A,UPC-E,EAN-8, EAN-13,Codebar,Code39, Code93,Code128,Code11,MSI
Font: ASCII(12x24)
Graphic printing: Direct bitmap printing
Paper Sensor: Photo-sensor
Head tempeture detection: Thermistor
Communication Interface: RS232 or RS232 with TTL level
Power supply: 5V-9V
Head Life: 50km
Printing width: 48mm
Operation condition: 5~45c, 20~90%RH(40c)
Storage condition: -40~60c, 20~93%RH(40c)

Control Board Details


Printing Test

After power up, connect J1 and disconnect, one test page will be printed.

On board LED  

There is one LED on board to indicate the status of the board. The indicator is as follows: 
Blink one:  Work well 
Blink two:  No printer is detected 
Blink three:  No paper is detected 
Blank five:  Printer mechanism is overheat.

Serial Communication.

this printer integrate 2 serial communication connectors.

The RS232 connector is specially dedicated to the full RS232 protocol (+/- 12V levels), when the TTL connector is designed to handle TTL levels (0/5V levels).




RS232 and TTL Connector details.




Ghostbusters Toaster—A Solenoid Lesson

With the help of some solenoids, the Dancing Ghostbusters Toaster really topped off my Halloween costume this year!
Although I can't speak for the most recent reboot, the original films are classics. With all the recent hype, I figured what better Halloween costume than a Ghostbuster! Of course, it was pure instinct to take it a bit too far, so I built the Dancing Toaster from the 1989 sequel!

BOM:

  • Arduino
  • Adafruit motor shield
  • Some solenoids
  • Hefty 12VDC power supply
  • Toaster
  • Ghostbusters costume

Why?

When I thought of the idea for the Dancing Toaster, I figured what better way to teach viewers at home what a solenoid is and the proper use of one!
For this project, I used several solenoids, triggered at various times, to get my toaster groovin'. Although an Arduino was used, it really only contained simple code for triggering the solenoids. Most of the work was done by my strong power supply and the Adafruit motor-drive shield, which (as you can see in the video) is handy for driving solenoids as well.
With proper care, this could have been an analog project with individual buttons for each of the solenoids. Then you and your friends could see who could get it to flip over first! (Flip The Toaster™©.). The Arduino simply gave us more flexibility without the inconvenience of continuously hitting different buttons.

A simple push-pull solenoid!

How?

Some of my previous material has taught you how to use an Arduino, so for this project we're skipping right to the nitty gritty.
Solenoids are electromagnetic devices and are the driving force behind the toaster's dancing. When voltage is applied to the solenoid's winding, a magnetic field is generated. Solenoids are designed to concentrate this magnetic field along the interior of the winding, which is why the plunger forcefully moves when you apply voltage.
The solenoids used with the toaster are designed for 12V, and to ensure that we have plenty of power available for the solenoids, I used a hefty (8.5 amp) power supply. The Adafruit motor shield contains the high-current drive circuits that deliver power to the solenoids.
Driving a solenoid is not much different from driving a motor, so it's no surprise that the motor shield works just fine as a solenoid controller. The 12V supply is connected to the motor shield and the Arduino can be powered from a separate USB port or from the DC barrel jack—just as long as the "VIN Jumper" on the motor shield is not connected. All I had to do was plug each of the solenoids into an M-port on the shield, which can drive up to four separate DC motors (or solenoids).

The multipurpose Adafruit motor shield!













To get the toaster to jump around, I searched for the smallest and lightest toaster I could find, regardless of color (although thefilm's toaster is silver). The less weight my solenoids have to fight against, the better the dance moves! I hastily threw this prop together using 5-minute Gorilla Epoxy but you can do better than I did!
To save money on parts, I usually search through local second-hand stores for cheap, abandoned toys, props, and components. The toaster was only $1.60. Choosing a lightweight toaster and fairly strong solenoids ensured that I could get the toaster moving. I found a toaster with flat, metal interior walls, and an easy-to-remove bottom tray, making installation and ease-of-access a cinch.
The Arduino code is straightforward and just turns individual solenoids on and off at different times. Attach some solenoids to your mom's favorite toaster and play around with the code to see which combination of solenoid triggers gets your toaster jumping the most!
Solenoids are quite useful and sometimes overlooked. They can certainly do more than just bring a toaster to life. 
By choosing the right type of solenoid, you can pull or push a mechanical load. Solenoids are found in various everyday machines and mechanisms: car door locks, automated air and water valves, mechanical doorbells, dialysis machines, etc.
How are you going to use your solenoid?
My love for solenoids lifts me higher, and lifts my toaster higher too! While the toaster is a pretty ridiculous design, you can take the knowledge you now have and implement your own design! Maybe you can even incorporate a solenoid into your Halloween costume! And if your toaster starts moving on its own without the help of electronics, who ya gonna call!!!!!!

Make a Web-Controlled Servo with an Arduino

In this project, we are going to control the servo motor through a webpage. The webpage will be created using an ESP8266 module and, by moving the slider on the webpage, the servo motor will move accordingly.


Required Materials

The components required for this project are as follows:
  • Arduino Uno
  • Servo motor (sg90)
  • ESP8266
  • ESP-01 adapter
  • Connecting wires

Connecting the Arduino UNO to the ESP8266



Web-controlled servo circuit diagram

First of all, connect the ESP8266 with Arduino. We have used an adapter to connect the esp8266 with the Arduino, which will make the connection very easier. The adapter has 5 to 3.3V regulator and you don’t need to connect any external resistors with it.
  • Connect the GND of adapter to the GND of Arduino
  • Connect the VCC of adapter to the 5V of Arduino
  • Connect the RX from the adapter to the pin 2 of Arduino
  • Connect the TX pin from the adapter to the pin 3 of Arduino
After that, connect the servo motor with the Arduino. Make the connections of the servo motor with the Arduino as follows:
  • Black wire of servo motor to the GND pin of Arduino
  • Red wire of servo motor to the 5V pin of Arduino
  • Yellow wire of servo motor to the pin 8 of Arduino

Creating the Webpage

To control the servo motor through the webpage, we will have to make a webpage using the HTML language. The HTML code we created for our project can be downloaded from the end of this article. If you want to rename the file, then change the filename but make sure that it has “.html” at the end.
After that, download the JQUERY file (which is also given at the end of the article) and place this file in the same folder where you have placed the HTML file. After that, open the HTML and the webpage will look like this:
Now, change the Wi-Fi name and password in the Arduino code with your Wi-Fi name and password. Then upload the code.Open the serial monitor and it will show you the IP address as shown in the figure below:

Type this IP address in the space given on the webpage.
Now, when you move the slider, the servo motor will move.

Code:

#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial esp8266(2,3);

#define DEBUG true 
#define sg90_pin 8 

Servo sg90; 

int current_position = 170;
int vel = 10; 
int minimum_position = 20; 
int maximum_position = 160;


void setup()
{
  sg90.attach(sg90_pin);
  sg90.write(maximum_position);
  sg90.detach();
  Serial.begin(9600);
  esp8266.begin(9600);

  esp8266Data("AT+RST\r\n", 2000, DEBUG); //reset module
  esp8266Data("AT+CWMODE=1\r\n", 1000, DEBUG); //set station mode
  esp8266Data("AT+CWJAP=\"Tenda_31BC98\",\"barcelona\"\r\n", 2000, DEBUG);   //connect wifi network
  while(!esp8266.find("OK")) { //wait for connection
  } 
  esp8266Data("AT+CIFSR\r\n", 1000, DEBUG); 
  esp8266Data("AT+CIPMUX=1\r\n", 1000, DEBUG); 
  esp8266Data("AT+CIPSERVER=1,80\r\n", 1000, DEBUG); 
}


void loop()
{
  if (esp8266.available())  
  {
    if (esp8266.find("+IPD,")) 
    {
      String msg;
      esp8266.find("?"); 
      msg = esp8266.readStringUntil(' '); 
      String command = msg.substring(0, 3); 
      String valueStr = msg.substring(4);   
      int value = valueStr.toInt();         
      if (DEBUG) {
        Serial.println(command);
        Serial.println(value);
      }
      delay(100);

      
      //move servo1 to desired angle
      if(command == "sr1") {
         //limit input angle
         if (value >= maximum_position) {
           value = maximum_position;
         }
         if (value <= minimum_position) {
           value = minimum_position;
         }
         sg90.attach(sg90_pin); //attach servo
         while(current_position != value) {
           if (current_position > value) {
             current_position -= 1;
             sg90.write(current_position);
             delay(100/vel);
           }
           if (current_position < value) {
             current_position += 1;
             sg90.write(current_position);
             delay(100/vel);
           }
         }
         sg90.detach(); //dettach
      }


    }
  }
}


String esp8266Data(String command, const int timeout, boolean debug)
{
  String response = "";
  esp8266.print(command);
  long int time = millis();
  while ( (time + timeout) > millis())
  {
    while (esp8266.available())
    {
      char c = esp8266.read();
      response += c;
    }
  }
  if (debug)
  {
    Serial.print(response);
  }
  return response;
}

Code Explanation

First of all, include the libraries for the software serial and for the servo. The software serial library will help us in using the TX and RX communication on other pins of the Arduino. The servo library will help us in moving the servo easily. After that, we defined the pins where we have connected the RX and TX from the esp8266 and then we defined the pin where we attached the servo motor.
After that, we define the pins where we have connected the RX and TX from the ESP8266 and then we define the pin where we attached the servo motor.

#include <SoftwareSerial.h>
#include <Servo.h>
SoftwareSerial esp8266(2,3);
#define DEBUG true 
#define sg90_pin 8 

Then in the setup function, we tell the Arduino which pin we have connected the servo motor to and we moved the motor to the maximum position. Then we set the baud rate for the serial communication and the esp8266 at 9600. Set the baud rate of esp8266 according to your esp8266’s baud rate. Your esp8266 might have different baud rate.
Then we set the baud rate for the serial communication and the ESP8266 at 9600. You’ll need to set the baud rate of ESP8266 according to your ESP8266’s baud rate. Your ESP8266 might have different baud rate.

sg90.attach(sg90_pin);
  sg90.write(maximum_position);
  sg90.detach();
  Serial.begin(9600);
  esp8266.begin(9600);

The following commands connect the ESP8266 to your Wi-Fi network and set the webserver at the IP address and port. It will show this in the serial monitor after uploading the code.

esp8266Data("AT+RST\r\n", 2000, DEBUG); //reset module
  esp8266Data("AT+CWMODE=1\r\n", 1000, DEBUG); //set station mode
  esp8266Data("AT+CWJAP=\"Tenda_31BC98\",\"barcelona\"\r\n", 2000, DEBUG);   //connect wifi network
    while(!esp8266.find("OK")) { //wait for connection
  } 
  esp8266Data("AT+CIFSR\r\n", 1000, DEBUG); 
  esp8266Data("AT+CIPMUX=1\r\n", 1000, DEBUG); 
  esp8266Data("AT+CIPSERVER=1,80\r\n", 1000, DEBUG); 

The Arduino will see if the data is available or not. If the slider on the webpage is moved, then the ESP8266 sends the data to the Arduino according to the slider moved. The Arduino moves the servo motor according to the value given by the ESP8266.

if (esp8266.available())  
  {
    if (esp8266.find("+IPD,")) 
    {
      String msg;
      esp8266.find("?"); 
      msg = esp8266.readStringUntil(' '); 
      String command = msg.substring(0, 3); 
      String valueStr = msg.substring(4);   
      int value = valueStr.toInt();         

The following function sends the commands to the ESP8266 and will print the response of the ESP8266 on the serial monitor.

String esp8266Data(String command, const int timeout, boolean debug)
{
  String response = "";
  esp8266.print(command);
  long int time = millis();
  while ( (time + timeout) > millis())
  {
    while (esp8266.available())
    {
      char c = esp8266.read();
      response += c;
    }
  }

DOWNLOAD CODE:

Arduino Home Automation Using RF

Home automation is one of in demand concepts in today’s world. Hobbyists do simple automation systems with the components readily available. If we are more concerned about the reliability and performance of the system, then we can go for the expensive Home Automation Consoles.
Home automation reduces the physical efforts and integrates the control for any number of appliances in to a single control unit. Hence, a simple home automation system is a remote control of different electrical appliances i.e. turning them on or off with the help of a remote.
There are many ways to implement this remote control system. With the extensive use of smart phones and tablets, Bluetooth may be the best option to implement the home automation. And one is implemented here in Bluetooth based Home Automation using Arduino.  The other methods of remote controlled home automation system are ZigBee, Wi-Fi, Radio Frequency (RF Module), GSM etc.
In this project, a simple but efficient home automation system using RF Module (Transmitter – Receiver pair) is designed. The system is designed with Arduino (ATmega 328) as the main processing unit.

Circuit Diagram

The circuit diagram is divided in to the transmitter section and receiver section for easy understanding. The transmitter section of the project is shown on the following image.
transmitter
The receiver section of the project is shown in the following image.
receiver

Required Component

The list of components mentioned here are specifically for controlling two different loads. The list of components may vary if the no. of loads is more.
Transmitter Section
  • Arduino UNO
  • 434 MHz RF Transmitter
  • Push Buttons X 4
  • 1 KΩ Resistor X 4
  • Prototyping Board
  • 9V Battery
  • Connecting wires
Receiver Section
  • Arduino UNO
  • 434 MHz RF Receiver
  • 2N2222 NPN Transistor X 2
  • 1 KΩ Resistor X 2
  • 1N4007 PN Junction Diode X 2
  • 12V Relay X 2
  • Prototyping Board
  • Power Supply (Adapter)
  • Connecting wires

Component Description

Arduino UNO:
Two Arduino UNO’s is used in the project, one in the transmitter section which reads the inputs from switches and transmit the message and the other is used in receiver section to decode the message and control the loads.
434 MHz RF Module:
The 434 MHz Radio Frequency Transmitter – Receiver Module is the best and cheapest way to implement a wireless communication for a reasonably longer ranges.


Relay Board:

A relay board consists of all the components that are required for a relay to be operated by a microcontroller. A four channel relay board is used although only two relays are used in the practical implementation.

Circuit Design

The design of the circuit is explained with respect to transmitter section and receiver section individually.
Transmitter Circuit Design:
The first component we need to connect to the Arduino UNO is the RF Transmitter module. The data in pin of the RF Transmitter module is connected to the 8th digital I/O pin of Arduino. The other pins of the transmitter module i.e. VCC and GND are connected to 5V and ground pins of the Arduino respectively. An optional antenna wire can be connected to the antenna pin of the transmitter module.
The next step is to connect the push buttons. First, we need to pull down the digital I/O pins 3 through 6 with the help of four 1KΩ resistors. Then connect four switches to these four pins with the other ends of the switches connected to 5V supply.
Receiver Circuit Design:
The RF Receiver receives the data through RF links and must transmit this data to the Arduino. Hence, the data out pin of the receiver module must be connected to digital I/O pin 11 of the Arduino.
The VCC and GND pins of the receiver module are connected to 3.3V and ground pins of the Arduino. An antenna can be connected to the antenna terminal of the module.
If you are using a relay board, as we are in this project, simply connect the digital I/O pins 4 and 5 of the Arduino to the input pins of the relay.
If you are not using the relay board, the connections must be made as per the circuit diagram.
Note: We need to be extremely careful when connecting AC Mains supply to the relay board.

Project Working Process

Home Automation System is a useful and helpful way to manage electrical appliances without any physical contact with the switch. This is possible by utilizing the wireless communication technologies. In this project, an RF based home automation system is implemented using Arduino. The working of the project is explained here.
At the transmitter section, the Arduino continuously monitors the status of the switches (or buttons). Whenever a switch is pressed, a logic HIGH is detected at that particular I/O pin. As a result, the Arduino transmits a suitable message corresponding to the switch pressed.
For example, if LOAD1_ON switch, which is connected to pin 6, is pressed, Arduino detects a logic HIGH at pin 6. Hence, Arduino sends a message as “@ABC$” via the RF transmitter.
At the receiver end, the RF receiver receives this message and transmits the same to Arduino for decoding. When the Arduino at the receiver end decodes the message and understands that the transmitter characters are “@ABC$”, it then writes a HIGH signal on the digital I/O pin 4.
As a result, the relay connected to load 1 is activated and the load is turned on.
Similar actions are performed when other switches are pushed.
If there is any error in the data transmission i.e. the desired data is not transmitted, the Arduino at the receiver section lights up the error LED which is connected to the 13th pin.
A data transmission successful LED and an error buzzer can also be implemented to indicate those actions more efficiently.

Applications

  • Although Bluetooth based home automations are easy to implement as almost everyone has a smart phone, the advantage of the RF based home automation system is the range of communication. RF based system is useful if we have a large house where Bluetooth might go out of range.
  • The system can be expanded to a smart home system with security by integrating several sensors like temperature, humidity, light and security devices like burglar sensors, CCTV’s etc.

Project Images






CODE

/**** RF TRANSMITTER LINK SETUP ******/
#include <VirtualWire.h> 
//int RF_TX_PIN = 2;
#undef int
#undef abs
#undef double
#undef float
#undef round
char msg[6] = "";
int bulbON = 0;
int bulbOFF = 0;
int fanON = 0;
int fanOFF = 0;
int doorOPEN = 0;
int doorCLOSE = 0;
/**** RF TRANSMITTER LINK SETUP ******/

/**** PUSH BUTTON SETUP ******/
#define FAN_ON 8
#define FAN_OFF 7
#define DOOR_OPEN 6
#define DOOR_CLOSE 5
#define BULB_ON 4
#define BULB_OFF 3
/**** PUSH BUTTON SETUP ******/

/**** ALARM LED BUZZER SETUP ******/
#define BUZZER_PIN 9
#define LED_PIN 11
/**** ALARM LED BUZZER SETUP ******/

void setup()
{
  Serial.begin(9600);
  // Initialise the IO and ISR
  vw_set_ptt_inverted(true); // Required for DR3100
//  vw_set_tx_pin(RF_TX_PIN); // Setup transmit pin
  vw_setup(2000); // Transmission speed in bits per second.  
  
  // Setup Pin Mode as INPUT for Push Buttons
  pinMode(BULB_ON, INPUT);
  pinMode(BULB_OFF, INPUT);
  pinMode(FAN_ON, INPUT);
  pinMode(FAN_OFF, INPUT);
  pinMode(DOOR_OPEN, INPUT);
  pinMode(DOOR_CLOSE, INPUT);
  
  // Setup Pin Mode as OUTPUT for LED and BUZZER
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);  
}

void loop()
{
  // Start Get Push Buttons Data    
  bulbON = digitalRead(BULB_ON);
  bulbOFF = digitalRead(BULB_OFF);
  fanON = digitalRead(FAN_ON);
  fanOFF = digitalRead(FAN_OFF);
  doorOPEN = digitalRead(DOOR_OPEN);
  doorCLOSE = digitalRead(DOOR_CLOSE);  
  // End Get Push Buttons Data    
  
  if (bulbON == HIGH)
  {    
    strcpy(msg, "@BON$");    
  }
  
  if (bulbOFF == HIGH)
  {    
    strcpy(msg, "@BOFF$");    
  }
  
  if (fanON == HIGH)
  {
    strcpy(msg, "@FON$");    
  }
  
  if (fanOFF == HIGH)
  {
    strcpy(msg, "@FOFF$");    
  }
  
  if (doorOPEN == HIGH)
  {
    strcpy(msg, "@DON$");    
  }
  
  if (doorCLOSE == HIGH)
  {
    strcpy(msg, "@DOFF$");    
  }
  
  if(strlen(msg)>0)
  {    
    sendRFMsg(msg);    
  }
  
  strcpy(msg, "");  
  resetButtons();
}

// Send Message Via RF 433 MHz Link
void sendRFMsg(char msg[])
{  
  vw_send((uint8_t *)msg, strlen(msg));
  vw_wait_tx(); // Wait until the whole message is gone   
  delay(400);
  LedBuzzer();
  Serial.print("Message Sent-->");
  Serial.println(msg);
}

// Send Message Via RF 433 MHz Link
void LedBuzzer()
{
  digitalWrite(BUZZER_PIN, HIGH);
  digitalWrite(LED_PIN, HIGH);  
  delay(500);
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);  
}

// Reset variables for buttons
void resetButtons()
{
  bulbON = 0;
  bulbOFF = 0;
  fanON = 0;
  fanOFF = 0;
  doorOPEN = 0;
  doorCLOSE = 0;
}
*********************************************************************************
/**** RF RECEIVER LINK SETUP ******/
#include <VirtualWire.h> 
//int RF_RX_PIN = 2;
#undef int
#undef abs
#undef double
#undef float
#undef round
/**** RF RECEIVER LINK SETUP ******/

/**** ALARM LED BUZZER SETUP ******/
#define BUZZER_PIN 6
#define LED_PIN 7
#define ERROR_LED 8
/**** ALARM LED BUZZER SETUP ******/

/**** LED SETUP ******/
#define FAN_LED 3
#define DOOR_LED 4
#define BULB_LED 5
boolean bBulb = false;
boolean bFan = false;
int iFan = 0;
int iDoor = 0;
/**** LED SETUP ******/

/**** MOTOR SETUP ******/
#define DOOR_MOTOR_A A0
#define DOOR_MOTOR_B A1
#define FAN_MOTOR_A  A2
/**** MOTOR SETUP ******/

void setup()
{
  Serial.begin(9600);
  Serial.println("setup");
  // Initialise the IO and ISR
  vw_set_ptt_inverted(true); // Required for DR3100
  //vw_set_rx_pin(RF_RX_PIN);  // Setup receive pin.
  vw_setup(2000); // Transmission speed in bits per second.
  vw_rx_start(); // Start the PLL receiver.
  
  // Set pinmode for LED, BUZZERS
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(LED_PIN, OUTPUT);
  pinMode(ERROR_LED, OUTPUT);
  pinMode(FAN_LED, OUTPUT);
  pinMode(DOOR_LED, OUTPUT);
  pinMode(BULB_LED, OUTPUT);
  bBulb = false;
  bFan = false;
  iDoor = 0;
}
void loop()
  uint8_t buf[VW_MAX_MESSAGE_LEN];
  uint8_t buflen = VW_MAX_MESSAGE_LEN;  
  if(vw_get_message(buf, &buflen)) // non-blocking I/O
  { 
    delay(500); 
    ProcessCommand ( (char *) buf);
    delay(500); 
  } 
  
  if(bBulb == true)
  {
    digitalWrite(BULB_LED, HIGH);
  }

  if(bBulb == false)
  {
    digitalWrite(BULB_LED, LOW);
  }
  
  if(iFan == 1)
  {
    digitalWrite(FAN_LED, HIGH);
    RunFan();
  }
  
  if(iFan == 2)
  {
    StopFan();
    digitalWrite(FAN_LED, LOW);
    iFan = 0;
  }
  
  if(iDoor == 1 )
  {
    digitalWrite(DOOR_LED, HIGH);
    OpenDoor();
    digitalWrite(DOOR_LED, LOW);
    iDoor =0;
  }
  else  if ( iDoor == 2)
  {
    digitalWrite(DOOR_LED, HIGH);
    CloseDoor();
    digitalWrite(DOOR_LED, LOW);
    iDoor =0;
  }
  else
  {
    iDoor = 0;
    digitalWrite(DOOR_LED, LOW);
  }
  
  /*Serial.println("Fan, Door, Lights");
  Serial.print(iFan);
  Serial.print(",");
  Serial.print(iDoor);
  Serial.print(",");
  Serial.print(bBulb);*/
  
}

void ProcessCommand(char msg[])
{
  if (strlen(msg) ==0) { ErrorAlarm(); return; }  
  
  Serial.println("Message Received-->");
  Serial.println(msg);  
   // check if the string doesn't have valid string
 if ( compareTag(msg, '@') == false || compareTag(msg, '$') == false) { ErrorAlarm(); return;}  
 SucessAlarm();
 Serial.println("Command Received-->");
 Serial.println(msg);  

 char cTag[5] ="";
 int index =0;
 boolean batFound = false;
 boolean dollarFound = false;
 int iLoop = IndexOf(msg,'@');
 if(iLoop == -1){ ErrorAlarm(); return;}
 iLoop++;
 while (iLoop < strlen(msg))
 {
   if(msg[iLoop] == '$'){break;}
   else{cTag[index] = msg[iLoop]; index++;}
   
   iLoop ++;
 }
 String sTag = String(cTag);

  if (sTag.equals("BON")) { bBulb = true; Serial.println("Compared BON - 1");}

  if (sTag.equals("BOFF")) { bBulb = false; Serial.println("Compared BOFF - 0");}

  if (sTag.equals("FON")) { iFan = 1; bFan = true; Serial.println("Compared FON -1");}

  if (sTag.equals("FOFF")) { iFan = 2; bFan = false; Serial.println("Compared FOFF - 0");}
  
  if (sTag.equals("DON")) { iDoor = 1; Serial.println("Compared DON - 1" ); }

  if (sTag.equals("DOFF")) { iDoor = 2; Serial.println("Compared DON - 2"); }
  
}

int IndexOf(char msg[], char tag)
{
  if (strlen(msg) ==0) return false;
  boolean bFlag = false;
  int iIndex = -1;
  
  for( int i=0; i<strlen(msg); i++)
  {
    if(msg[i]== tag)
    iIndex = i;
  }
  
  return iIndex;
}

boolean compareTag (char msg[], char tag)
{
  if (strlen(msg) ==0) return false;
  boolean bFlag = false;
  
  for( int i=0; i<strlen(msg); i++)
  {
    if(msg[i]== tag)
    bFlag = true;
  }
  
  return bFlag;
}

void RunFan()
{
  Serial.println("Running Fan");
  analogWrite(FAN_MOTOR_A, 150);  
}

void StopFan()
{
  Serial.println("Stopping Fan");
  analogWrite(FAN_MOTOR_A, 0);
  delay(50);
}

void OpenDoor()
{
  Serial.println("Open Door");
 analogWrite(DOOR_MOTOR_A, 150);
 analogWrite(DOOR_MOTOR_B, 0);
 delay(1000);
 analogWrite(DOOR_MOTOR_A, 0); 
 analogWrite(DOOR_MOTOR_B, 0);
}

void CloseDoor()
{
 Serial.println("Close Door");
 analogWrite(DOOR_MOTOR_A, 0); 
 analogWrite(DOOR_MOTOR_B, 150); 
 delay(1000);
 analogWrite(DOOR_MOTOR_A, 0);
 analogWrite(DOOR_MOTOR_B, 0);
}

// Function provides alarm in case of success
void SucessAlarm()
{
  digitalWrite(BUZZER_PIN, HIGH);
  digitalWrite(LED_PIN, HIGH);  
  delay(500);
  digitalWrite(BUZZER_PIN, LOW);
  digitalWrite(LED_PIN, LOW);  
}

// Function provides alarm in case of error
void ErrorAlarm()
{
  digitalWrite(ERROR_LED, HIGH);
  digitalWrite(BUZZER_PIN, HIGH);
  delay(500);
  digitalWrite(ERROR_LED, LOW);
  digitalWrite(BUZZER_PIN, LOW);
}