I'm working on a project that I have two sensors, two Arduinos (a YUN and an UNO), two LED's, and an RF transmitter/receiver
It's a pretty simple procedure: Activate a force sensor, send it via RF to the receiver and light up the corresponding LED. So my design looks like this -
Sensor 1 and Sensor 2 ---> Arduino YUN ---> RF Transmitter --> Wireless
---> RF Receiver ---> Arduino UNO ---> LED 1 and LED 2
So if Sensor 1 is activated LED 1 lights up and if Sensor 2 is activated LED 2 lights up.
So far I am able to send the signal and distinguish between each sensor by viewing the serial monitor. If I hit sensor 1, the Uno receives sensor 1's signal. Same with sensor 2. I'm just stuck on how to get the LED's to activate. I tried using buf =='1' code so whenever I send "1", it would read the buf for 1 then digitalWrite the led high. But that didn't work. Any advice would be much appreciated. Here's my code if you would like to look at it.
Transmitter:
```
* #include <VirtualWire.h>
int pin0 = 0;
int pin1 = 1;
void setup()
{
vw_set_ptt_inverted(true); // Required by the RF module
vw_setup(2000); // bps connection speed
Serial.begin (9600);
vw_set_tx_pin(3); // Arduino pin to connect the transmitter data pin
}
void loop()
{
int force = analogRead(pin0); // analog reading from the Force sense resistor
int force1 = analogRead(pin1); // analog reading from the Force1 sense resistor
const char *msg = "1";
const char *ms = "2";
if (force > 100) {
vw_send((uint8_t *)msg, strlen(msg));
vw_wait_tx(); // We wait to finish sending the message
delay(200); // We wait to send the message again
}
if (force1 > 100) {
vw_send((uint8_t *)ms, strlen(ms));
vw_wait_tx(); // We wait to finish sending the message
delay(200); // We wait to send the message again
}
}*
* *Receiver:* *
*#inlude <VirtualWire.h>
const int led = 3;
const int led1 = 4;
void setup()
{
Serial.begin(9600);
vw_set_ptt_inverted(true);
vw_setup(2000);
vw_set_rx_pin(2);
vw_rx_start();
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
}
void loop()
{
uint8_t buf[VW_MAX_MESSAGE_LEN];
uint8_t buflen = VW_MAX_MESSAGE_LEN;
if (vw_get_message(buf, &buflen)))
{
int i;
for (i = 0; i < buflen; i++)
{
Serial.print(buf[i]);
if(buf[i] == '1'){digitalWrite(3, HIGH);}
if(buf[i] == '2'){digitalWrite(4, HIGH);}
}
}
else
{
digitalWrite(3, LOW);
digitalWrite(4, LOW);
}
}*
```
Thank you for any help at all.