Voice Activated TV

Hello, I have a problem with a project I'm working on. I have written a c# program that uses voice recognition to send a serial response to an arduino. The arduino then uses an IR Led to send a code to either the TV or cable box. I used the ken shirriff's irdemo to implement this. I had everything working and then when I put everything in a project box I purchased from radio shack it started acting weird. I have the Raw codes stored in an array and some of the codes work and some of them don't I put in a println statement to print the array out to make sure that I was sending the right codes, however on the codes that are not working, it skips the first element of the array. In the beginning of the code where I declare the arrays, if I move an array down to the bottom of the list, that array will then work, however a different will stop working. Also, when I println a string, it prints out complete garbage, for example if I println "off" it prints out:

bô?&?ôb&?ô?&?&?ô?&?&?ôb&?ôb&0&(#0&0&?&0&b&0&0Xf&?&f&?&fXf&?&fXf&?&ö"?&?&bXfXf&?Xb&?Xf&?&?&?&fXfXb&?&?&ö"bôb&bô?&0&bôÊô?&?ô?&?&?ô?&?ôÊôbôÊôö"bôb&?ôb&?ôb&0&?&?ô?&?ôÊô?&?ôÊô?&bôö"b&?&f&?&?ôb&0&?&?&f&?&?ô?&bô?&bôb&0

I have listed part of the code below but i couldn't post all of it because it was too long. I am completely stumped. Is it possible that I have messed up the Arduino when I was putting it in the project box. I have tried it with other components but I don't have another arduino to test it out. Any thoughts are greatly appreciated.

unsigned int rew[35] = {8950 ,4450 ,550 ,2200 ,500 ,4450 ,550 ,4450 ,500 ,4450 ,500 ,4450 ,550 ,2200 ,500 ,2250 ,500 ,2200 ,550 ,2200 ,500 ,2200 ,550 ,2200 ,550 ,2200 ,500 ,4450 ,550 ,2200 ,500 ,2200 ,550 ,2200 ,500};
unsigned int exitbtn[35] = {8950 ,4500 ,500 ,2200 ,550 ,4450 ,500 ,2200 ,550 ,2200 ,500 ,4450 ,550 ,2200 ,500 ,2200 ,550 ,2200 ,550 ,2200 ,500 ,2200 ,550 ,2200 ,550 ,2200 ,500 ,4450 ,550 ,2200 ,500 ,4450 ,550 ,4400 ,550};
unsigned int dvr[35] = {9000, 4400, 550, 4400, 550, 2200, 550, 4400, 550, 4450, 550, 4400, 550, 4400, 600, 2150, 550, 2200, 550, 2150, 550, 2200, 550, 2150, 600, 2150, 550, 2200, 550, 2150, 600, 2150, 550, 2200, 550};
unsigned int info[35] = {8950,4500,550,4500,550,4450,600,2150,600,2150,550,4500,600,4450,550,2200,600,2150,550,2200,550,2200,550,2200,550,2150,600,2150,600,4450,550,2200,550,4500,550};
unsigned int play[35] = {8950 ,4450 ,500 ,4450 ,550 ,4450 ,500 ,2200 ,550 ,4400 ,550 ,4450 ,500 ,2250 ,500 ,2200 ,550 ,2200 ,500 ,2200 ,550 ,2200 ,550 ,2200 ,500 ,2200 ,550 ,2200 ,500 ,2250 ,500 ,4450 ,500 ,2250 ,500};
unsigned int down[35] = {8950,4450,500,4450,550,2200,500,4450,550,2200,500,4450,550,4400,550,2200,550,2200,500,2200,550,2200,500,2250,500,2200,550,2200,500,2250,500,2200,550,4450,500};
unsigned int guide[35] = {8950,4450,550,2200,550,2150,550,2200,550,2200,500,4450,550,4400,550,2200,550,2200,550,2150,550,2200,550,2200,500,2200,550,4450,500,2200,550,4450,500,4450,550};
char c = '0';

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

}

void loop() {
  
   while (Serial.available() == 0);
  
  
   c = Serial.read();
   
  
  if (c == '2') {
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(50);
    }
  }
  
  if (c == '0') {
    for (int i = 0; i < 3; i++) {
      irsend.sendSony(0xa90, 12); // Sony TV power code
      delay(50);
      Serial.println("off");
    }
  }
  
  if (c == '3'){
    for (int i=0; i<3; i++){
      irsend.sendSony(0x490, 12);
      delay(50);
    }
  }
  if (c == '4'){
    for (int i=0; i<3; i++){
      irsend.sendSony(0xC90, 12);
      delay(50);
    }
  }
  if (c == '5'){
    for (int i=0; i<3; i++){
      irsend.sendSony(0x290, 12);
      delay(50);
    }
  }
  if (c == '8')
  irsend.sendRaw(eight, 35, 36);
  
  if (c == '7')
  irsend.sendRaw(seven, 35, 36);
  
  if (c == '6')
  irsend.sendRaw(six, 35, 36);
  
  if (c == '9')
  irsend.sendRaw(nine, 35, 36);
  
  if (c == 'A'){
  irsend.sendRaw(five, 35, 36);
  Serial.print("five");
  }
  
  if (c == 'B')
  irsend.sendRaw(four, 35, 36);
  
  if (c == 'C')
  irsend.sendRaw(three, 35, 36);
  
  if (c == 'D')
  irsend.sendRaw(two, 35, 36);
  
  if (c == 'E')
  irsend.sendRaw(one, 35, 36);
  
  if (c == 'F')
  irsend.sendRaw(zero, 35, 36); 
  
  if (c == 'G')
  irsend.sendRaw(select, 35, 36);
  
  if (c == 'H')
  irsend.sendRaw(pause, 35, 36);
  
  if (c == 'I')
  irsend.sendRaw(play, 35, 36);
  
  if (c == 'J')
  irsend.sendRaw(ff, 35, 36);
  if (c == 'K')
  irsend.sendRaw(rew, 35, 36);
  if (c == 'L')
  irsend.sendRaw(stopbtn, 35, 36);
  if (c == 'M')
  irsend.sendRaw(rec, 35, 36);
  if (c == '1')
  {
    Serial.print(c);
  irsend.sendRaw(guide, 35, 36);
  }
  if (c == 'a')
  {
    Serial.println(c);
    for (int i= 0; i<35; i++)
    {
      Serial.println(info[i]); 
    }
  irsend.sendRaw(info,35, 36);
  }
  if (c == 'b')
  irsend.sendRaw(chup, 35, 36);
  if (c == 'c')
  irsend.sendRaw(chdown, 35, 36);
  if (c == 'd')
  irsend.sendRaw(last, 35, 36);
  if (c == 'e')
  irsend.sendRaw(see, 35, 36);
  if (c == 'f')
  irsend.sendRaw(b, 35, 36);
  if (c == 'g')
  irsend.sendRaw(a, 35, 36);
  if (c == 'h')
  irsend.sendRaw(live, 35, 36);
  if (c == 'i')
  irsend.sendRaw(demand, 35, 36);
  if (c == 'j')
  irsend.sendRaw(left, 35, 36);
  if (c == 'k')
  irsend.sendRaw(right, 35, 36);
  if (c == 'l')
  irsend.sendRaw(up, 35, 36);
  if (c == 'm')
  irsend.sendRaw(down, 35, 36);
  if (c == 'n')
  irsend.sendRaw(pageup, 35, 36);
  if (c == 'o')
  irsend.sendRaw(pagedown, 35, 36);
  if (c == 'p')
  {
    Serial.println(c);
    for (int i= 0; i<35; i++)
    {
     Serial.println(exitbtn[i]); 
    }
  irsend.sendRaw(exitbtn, 35, 36);
  }
  if (c == 'q')
  {
    Serial.println(c);
    for (int i= 0; i<35; i++)
    {
      Serial.println(dvr[i]); 
    
    }
    
  irsend.sendRaw(dvr, 35, 36);
  }
  

}

z28power:
if I move an array down to the bottom of the list, that array will then work, however a different will stop working.

I have listed part of the code below but i couldn't post all of it because it was too long.

These two things suggest that you have a memory issue - your sketch is consuming too much of it. It may well be that putting the hardware into the box, you disconnected something, and now, your debugging code you subsequently addded has pushed you over the edge and your stack and heap are colliding.

Looks like you figured out the issue with printing your strings at least :wink:

I was saying that it was too long because when I made my post it was over 9500 characters so I couldn't post it in the forums.

If my program is compiling and only like 8kb does that mean that I'm not using too much memory or does that not include the variables I'm using? Sorry if that's an obvious question but I'm still new at all this.

What would cause the garbage to be printed during the println statements?

The space for the code and data are separate. There isn't much RAM available for your variables - which Arduino do you have? I notice a lot of command strings that you had to cut out of your code to be able to post it (try adding it as an attachment) - they may have pushed you close enough to the edge that a few debug lines finished you off.

I have attached the whole arduino program. I have an arduino uno. Is there a way to send via serial an array, that way I can have all the variables stored in c# and then send it to the arduino via serial and that will cut down on the size of data I need to store on the arduino?

voiceactivatedtv.pde (10.6 KB)

Size is indeed your issue. The UNO has 2K of RAM. Your sketch has 35 arrays, each 35 long of two byte unsigned integers. That's 2450 right there. You could indeed send the strings from the PC, or it's likely that you could come up with a way of storing the string data you need that doesn't consume so much memory.

Thank you so much for your help. I will try and figure out how to send my data over serial.