int pin = 3;//your ir transmitter output pin int dot_count=0;//here we count all dots int dash_count=0;//same here but we count dashs unsigned long duration; int code=0; int cn=0; int c=0; int d,ds,f,f1,s,s2,s3,a; void setup() {Serial.begin(9600); pinMode(pin, INPUT); } void loop() { duration = pulseIn(pin, LOW); if((duration>2000)||(c==1)){ code ++; c=1; } if((duration>=800)&&(duration<=1100)){ //here we detect dots dot_count++; d=1; } //Serial.println(duration); // Serial.print("Dots are="); // Serial.println(dot_count); if((duration>=1500)&&(duration<=1800)){ //here we detect dashes dash_count++; ds=1; } if((code>=2)&&(code<=6)) { f=dot_count; f1=dash_count; if(code==2){ if(d==1){ cn=0; } else cn=1; } if(code==6){ morse(); f=0; f1=0; dash_count=0; dot_count=0; s2=s; // Serial.print(s2); } } if((code>=7)&&(code<=11)) { f=dot_count; f1=dash_count; if(code==7){ if(d==1){ cn=0; } else cn=1; } if(code==11){ morse(); f=0; f1=0; dash_count=0; dot_count=0; s3=s; } } //Serial.println(dash_count); //Serial.print("Tiretata sa="); //debuging stuff //Serial.println(dash_count); if(code==11){ c=0; code=0; } d=0; ds=0; a=s2*10+s3; Serial.println(a); } void morse(){ if(cn==0){ if((f==1)&&(f1==4)){ // Serial.print("1"); s=1; } if((f==2)&&(f1==3)){ // Serial.print("2"); s=2; } if((f==3)&&(f1==2)){ // Serial.print("3"); s=3; } if((f==4)&&(f1==1)){ // Serial.print("4"); s=4; } if((f==5)&&(f1==0)){ // Serial.print("5"); s=5; } } if(cn==1){ if((f==4)&&(f1==1)){ // Serial.print("6"); s=6; } if((f==3)&&(f1==2)){ // Serial.print("7"); s=7; } if((f==2)&&(f1==3)){ // Serial.print("8"); s=8; } if((f==1)&&(f1==4)){ // Serial.print("9"); s=9; } if((f==0)&&(f1==5)){ // Serial.print("0"); s=0; } } }