hello we are doing a project using arduino...we are doing IR communication in it...on the transmitter side we are sending a value 25...and on the receiver side we are getting 25 along with some garbage values as 255,254,158 etc..so how can we remove these garbage values? does, using of special characters like "$" will help us to remove garbage values, by sending "$25" ?and we are sending values as bytes....
this is our code
//transmitter code//
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
int num1;
//dirt cheap wireless TX
//generates 38kHz carrier wave on pin 9 and 10
//sends data via TX every 500ms
//void transmitter(void);
void receiver(void);
void setup()
{lcd.begin(16, 2);
// Print a message to the LCD.
//lcd.print("100");
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
// Clear Timer on Compare Match (CTC) Mode
bitWrite(TCCR1A, WGM10, 0);
bitWrite(TCCR1A, WGM11, 0);
bitWrite(TCCR1B, WGM12, 1);
bitWrite(TCCR1B, WGM13, 0);
// Toggle OC1A and OC1B on Compare Match.
bitWrite(TCCR1A, COM1A0, 1);
bitWrite(TCCR1A, COM1A1, 0);
bitWrite(TCCR1A, COM1B0, 1);
bitWrite(TCCR1A, COM1B1, 0);
// No prescaling
bitWrite(TCCR1B, CS10, 1);
bitWrite(TCCR1B, CS11, 0);
bitWrite(TCCR1B, CS12, 0);
OCR1A = 210;
OCR1B = 210;
Serial.begin(2400);
}
void loop()
{
//lcd.print("550");
//for(int num1 = 11; num1 < 16; num1++){
num1=11;
lcd.setCursor(8,1);
lcd.print(num1);
Serial.print(num1,BYTE);
//Serial.println("55");
//Serial.println("hello world");
//Serial.println("testing testing testing");
delay(500);
}
}
//receiver code//
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
byte num1;// The higher the number, the slower the timing.
void module2(void);
void setup()
{lcd.begin(16, 2);
Serial.begin(2400);
pinMode(13, OUTPUT);
}
void loop()
{
// if incoming serial
// delay(200);
if (Serial.available())
module2();
else
//module1();
digitalWrite(13, LOW);
}
void module2() {
if (Serial.available()) {
num1=Serial.read();
if((num1)==11)
{
digitalWrite(13, HIGH);
lcd.setCursor(8,1);
lcd.print(int(num1));
delay(100);
}
else {
digitalWrite(13, LOW);
}
}
}