I've got the following code which read a value from a 434Mhz receiver and outputs the value to the RS232 port. When a value is received the LED pulses. Every works fine but after around 15 - 20 hours or running it looks like it crashes as the LED no longer pulses (ie. It doesnt receive any data from the 434Mhz receiver)
After resetting the arduino everything starts working again. Any ideas where it could be going wrong?
//Receiver connected to digital pin 11
#include <VirtualWire.h>
float power = 0;
int redLedPin = 7; // (Pin13 in chip)
int numbers[1];
long count = 0;
void setup()
{
pinMode(redLedPin,OUTPUT);
blinkLed(redLedPin,3,250);
vw_setup(1200); // Bits per sec
vw_rx_start(); // Start the receiver PLL running
Serial.begin(9600);
Serial.println("Begin");
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)) // check to see if anything has been received
{
blinkLed(redLedPin,1,250);
//memcpy(buf, numbers, buflen);
for (int i = 0; i < 1; i++)
{
numbers[i] = word(buf[i*2+1],buf[i*2]);
power = numbers[i];
power = power / 100;
count++;
Serial.print(power,1);
Serial.print("kwh : count:");
Serial.print(count);
Serial.println("");
power = 0;
}
}
}
void blinkLed(int lPin, int nBlink, int msec) {
if (nBlink) {
for (int i = 0; i < nBlink; i++) {
digitalWrite(lPin, HIGH);
delay(msec);
digitalWrite(lPin, LOW);
delay(msec);
}
}
}