#define IR_IN 8 // IR receive
Int Pulse_Width = 0; // store pulse width
Int ir_code = 0x00; // user code value
Char adrL_code = 0x00; // command code
Char adrH_code = 0x00; // command code anti-code
Void timer1_init (void) // timer initialization function
{
TCCR1A = 0X00;
TCCR1B = 0X05; // Give the timer clock source
TCCR1C = 0X00;
TCNT1 = 0X00;
TIMSK1 = 0X00; // Disable timer overflow interrupt
}
Void remote_deal (void) // Executes the decoding result function
{ //Data Display
Serial.println (ir_code, HEX); // hexadecimal display
Serial.println (adrL_code, HEX); // hexadecimal display
}
Char logic_value () // Determines logical values ??"0" and "1" sub-functions
{
TCNT1 = 0X00;
While (! (DigitalRead (IR_IN))); // low wait
Pulse_Width = TCNT1;
TCNT1 = 0;
If (Pulse_Width> = 7 && Pulse_Width <= 10) // low level 560us
{
While (digitalRead (IR_IN)); // is high waiting
Pulse_Width = TCNT1;
TCNT1 = 0;
If (Pulse_Width> = 7 && Pulse_Width <= 10) // then high level 560us
Return 0;
Else if (Pulse_Width> = 25 && Pulse_Width <= 27) // then high level 1.7ms
Return 1;
}
Return -1;
}
Void pulse_deal () // Receive address code and command code pulse function
{
Int i;
Int j
Ir_code = 0x00; // clear
AdrL_code = 0x00; // clear
AdrH_code = 0x00; // clear
// parse the user code value in the remote control code
For (i = 0; i <16; i ++)
{
If (logic_value () == 1) // is 1
Ir_code | = (1 << i); // save the key
}
// parse the command code in the remote control code
For (i = 0; i <8; i ++)
{
If (logic_value () == 1) // is 1
AdrL_code | = (1 << i); // save the key
}
// parse the code in the remote control code
For (j = 0; j <8; j ++)
{
If (logic_value () == 1) // is 1
AdrH_code | = (1 << j); // save the key
}
}
Void remote_decode (void) // Decode function
{
TCNT1 = 0X00;
While (digitalRead (IR_IN)) // is high waiting
{
If (TCNT1> = 1563) // When the high level lasts longer than 100ms, it means that there is no key press at this time
{
Ir_code = 0x00ff; // user code value
AdrL_code = 0x00; // key before the value of a byte
AdrH_code = 0x00; // key after a byte value
Return;
}
}
// If the high level lasts no more than 100ms
TCNT1 = 0X00;
While (! (DigitalRead (IR_IN))); // low wait
Pulse_Width = TCNT1;
TCNT1 = 0;
If (Pulse_Width> = 140 && Pulse_Width <= 141) // 9ms
{
While (digitalRead (IR_IN)); // is high waiting
Pulse_Width = TCNT1;
TCNT1 = 0;
If (Pulse_Width> = 68 && Pulse_Width <= 72) // 4.5ms
{
Pulse_deal ();
Return;
}
Else if (Pulse_Width> = 34 && Pulse_Width <= 36) // 2.25ms
{
While (! (DigitalRead (IR_IN))); // low wait
Pulse_Width = TCNT1;
TCNT1 = 0;
If (Pulse_Width> = 7 && Pulse_Width <= 10) // 560us
{
Return;
}
}
}
}
Void setup ()
{
Serial.begin (9600);
PinMode (IR_IN, INPUT); // set the infrared receive pin as input
Serial.flush ();
}
Void loop ()
{
Timer1_init (); // timer initialization
While (1)
{
Remote_decode (); // decode
Remote_deal (); // execute the decoding result
}
}
There is absolutely nothing in that code that could account for the regulator overheating. The only Arduino pin configured as an output is the serial TX pin, and that couldn't account for more than 50mA draw even if you'd shorted it, and only a few mA in normal operation.
Five possibilities exist (IMHO most probable first):
- You've hooked up the IR sensor wrong (e.g. reversed the supply pins) so its drawing excessive current from the 5V rail.
. - You've applied an excessive voltage to the DC in jack or Vin. Although the regulator can withstand up to 20V abs. max in and is nominally rated at 800mA, its thermal resistance to ambient with the amount of copper area on the official Uno board is something like 85 °C/W (They f--ked it up and didn't give it enough copper area, or enough vias to get the heat to the bottom). Tj_max is 150 °C. Assuming 60 °C 'ambient' near that part of the board, (not unreasonable if its in a case or the 5V rail is heavily loaded), that means its only good for about a watt before thermal shutdown, half that for reliable operation*. That puts an upper limit on the load current of 250mA @9V in or 140mA @12V in, which doesn't leave much for any shields etc. as the UNO draws about 50mA from the 5V rail. TLDR: At 12V in the regulator will over-heat if you draw more than about 30mA extra from the 5V or 3.3V rails.
. - You've blown the regulator (reverse bias) by powering it via the 5V pin and shorted the Vin pin to Gnd.
. - Sainsmart used a crappy clone regulator that has failed.
. - Sainsmart f--ked up the layout or the regulator decoupling caops and its oscillating under load.
* Opinions differ - See Arduino UNO regulator capacity? - Arduino ForumWhat to do?
Disconnect everything, power the board from USB and try the Arduino IDE examples 01. Basics: Blink sketch. If the LED doesn't blink its FUBARed. Then disconnect the USB, apply 12V (+/-1V) to the DC power jack, and check it still blinks without the regulator overheating. Then add a 150R resistor from +5V to Gnd to draw 33.3mA - the regulator should now be running warm but shouldn't overheat. Check the 5V rail. If its below 4.9V the regulator's probably bad.
Regulator replacement is possible if the UNO still runs from USB, if you can solder well enough and have a decent iron.
If it doesn't run from USB, its BER.
You can test the IR receiver (which is probably a TSOP38xx) or similar , without the Arduino by hooking it up to a 5.0V supply with a LED (cathode to out) + 1K series resistor between its output and +5V. The LED should be normally off and blink when it is receiving an IR signal. Its idle supply current shoud be <0.5mA. If the LED doesn't blink, or its drawing excessive current, you've blown it!