As a group project we are building a motion sensor that will detect cars around a blind corner. We built a nice doppler radar motion sensor using the instructions based by this website.
We attached the sensor to an arduino board and found code so that displays both the frequency and and the speed in mph in the serial port.
http://forum.arduino.cc/index.php?PHPSESSID=eavfq7iitgdpcmfomlaveiou41&topic=91793.0
Now we want to sent the data from one arduino uno to another uno via a 355MHz transmitter/receiver and display the data. I researched the transmitter and receiver and found info on how to code this but even though the codes compile, it doesn't transmit the data from one to other. I'm guessing the code I wrote is more for simple programs and I'm making too many assumptions in it I shouldn't be making. Bare with me as I am a beginner and I don't know completely on what I am doing. Can someone please look at the transmitter and receiver code and help me learn how to fix it. I will also place the code for just the sensor if you want to see how to data is coming out. Thanks in advance!
Transmitter Code
#include <VirtualWire.h>
const uint16_t TICK_CNT = 3;
static uint16_t freq = 0;
double sped = 0;
char HBSCharMsg[10];
void setup()
{
pinMode (13, OUTPUT);
Serial.begin(115200);
vw_setup(2000);
vw_set_tx_pin(12);
noInterrupts();
TCNT1 = 0;
TCCR1B |= _BV(CS12) |_BV(CS11) | _BV(CS10);
TCNT2 = TICK_CNT;
TIMSK2 = _BV(TOIE2);
TCCR2B |= _BV(CS22) |_BV(CS21) | _BV(CS20);
interrupts();
Serial.println("Ready...");
}
ISR(TIMER1_OVF_vect);
ISR(TIMER2_OVF_vect)
{
freq = TCNT1;
TCNT1 = 0;
TCNT2 = TICK_CNT;
}
void loop()
{
itoa(freq, HBSCharMsg, 1);
delay(1000);
digitalWrite(13, HIGH);
vw_send((uint8_t *) HBSCharMsg, strlen(HBSCharMsg));
vw_wait_tx();
digitalWrite(13, LOW);
delay(1000);
}
]
Receiver Code
#include <VirtualWire.h>
int ledPin = 13;
int HBSData;
char HBSCharMsg[10];
double sped = 0;
void setup()
{
Serial.begin(115200);
pinMode(ledPin, OUTPUT);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_rx_start();
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if(vw_get_message(buf, &buflen))
{
int i;
digitalWrite(13,true);
for(i = 0; i < buflen; i++)
{
HBSCharMsg[i] = char(buf[i]);
}
HBSCharMsg[buflen] = '\0';
HBSData = atoi(HBSCharMsg);
if (HBSData != 0) {
HBSData = HBSData * 62; // multiple the frequency * 4, 250ms*4 = 1 sec.
sped = HBSData * .03225; // multiplying freq * 0.03225 will give speed in mph, 31Hz = 1 mph.
Serial.print("Freq: ");
Serial.print(HBSData, DEC);
Serial.print(" Hz, Speed: ");
Serial.print(sped, 0);
Serial.println(" mph");
HBSData = 0;
}}}
Code for hb100 Sensor Output
const uint16_t TICK_CNT = 3; // 255-(16MHz/1024/62Hz)
static uint16_t freq = 0;
double sped = 0; //"speed" seems to be a reserved term
void setup() {
pinMode(13, OUTPUT);
digitalWrite(13, HIGH);
Serial.begin(115200);
noInterrupts(); // disable all interrupts while we configure
// init Timer1 - 16-bit timer/counter
TCNT1 = 0; // start count at zero.
TCCR1B |= _BV(CS12) | _BV(CS11) | _BV(CS10); // Increment T1 input on each positive edge
// using an external source, pg 139.
// init Timer2 - 8-bit timer/counter
TCNT2 = TICK_CNT; // preload Timer2 to interrupt every 250 ms
TIMSK2 = _BV(TOIE2); // enable the Timer2 overflow interrupt
TCCR2B |= _BV(CS22) |_BV(CS21) | _BV(CS20); // init clock prescaler to 1024, page 164.
interrupts(); // enable all interrupts
Serial.println("Ready...");
}
ISR(TIMER1_OVF_vect) {
// do nothing. this is just a dummy ISR in case it actually overflows.
Serial.println("Inside Timer1 Overflow Interrupt.");
}
ISR(TIMER2_OVF_vect) {
//Serial.print("TCNT1: ");
//Serial.println(TCNT1);
freq = TCNT1;
//Serial.println(freq);
TCNT1 = 0; //starts count at zero again
TCNT2 = TICK_CNT; //reloads Timer2 to interrupt every 250ms
}
void loop()
{
if (freq != 0)
{
freq = freq * 62; // multiple the frequency * 4, 250ms*4 = 1 sec.
sped = freq * .03225; // multiplying freq * 0.03225 will give speed in mph, 31Hz = 1 mph.
Serial.print("Freq: ");
Serial.print(freq, DEC);
Serial.print(" Hz, Speed: ");
Serial.print(sped, 0);
Serial.println(" mph");
freq = 0;
}
}