I've built "Light house" example from "Itty Bitty City" microduino kit.
Here is the code which initialises an IR receiver and decodes signals of remote control:
void setup() {
Serial.begin(9600);
irrecv.enableIRIn();//Initialize the Infrared Receiver and begin receiving data.
Serial.println("**************START************");
}
void loop() {
if (irrecv.decode(&results))
{
Serial.print("Recv Code:");
Serial.println(results.value);
recvParse(results.value);
//irrecv.enableIRIn();
irrecv.resume(); //Receive next value.
}
The problem is that no matter which button I pressed on remote control, the decoded value is always "0"
Why is this happening?
The code that you posted will not compile. It is incomplete. Always post the entire program.
The recvParse(results.value) function is missing from your code as well as the #include for the library and the constructors and is missing a } to close the loop() function.
#include <IRremote.h>
const byte IR_RECEIVE_PIN = 4; // ******* note the recv pin
IRrecv irrecv(IR_RECEIVE_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn();//Initialize the Infrared Receiver and begin receiving data.
Serial.println("**************START************");
}
void loop()
{
if (irrecv.decode(&results))
{
Serial.print("Recv Code:");
Serial.println(results.value);
//recvParse(results.value);
//irrecv.enableIRIn();
irrecv.resume(); //Receive next value.
}
}
This code works for my remote.
Have you made sure that your remote is in fact transmitting? Most cell phone cameras are sensitive to IR light. You should see a blue glow in the camera when the IR LED transmits.
Are you sure of the decoder wiring?
Have you tried any of the examples that come with the IRremote library?
#define DEBUG 1 //Serial monitor debugging ON/OFF.
#define PIN_RECV 4 //Infrared Receiver pin.
#define PIN_LED 12 //ColorLED pin.
#define LED_NUM 2
//=================================DO IT YOURSELF: CHANGE THE CODE BELOW!========================================//
//Example: Change "#define BRIGHT_MAX 128" to "#define BRIGHT_MAX 180". //
// That means the LED will now shine brighter than before. //
// //
//IMPORTANT: Remember to upload the code into the mBattery again after changing the values! //
//===============================================================================================================//
#define BRIGHT_MAX 64 //Max LED brightness. Max brightness is 255. Minimum brightness is 0.
Have you made sure that your remote is in fact transmitting?
Yes, I'm sure. I run it under debug and it printed "0" in console whatever button I pressed on remote control. Also the LED blinked every time I pressed a button on remote control. I've tried wiring on different pins, but it didn't help
Have you tried any of the examples that come with the IRremote library?
SmartCar (Examples -> mCookie_IBC -> _08_SmartCar) has the same problem, it can not be controlled with remote.
BTW, it turned out that one of the weels isn't flat enough, so the car can't move straight