design and build a wired &/or wireless network connecting at least two processors
I want to use these cheap RF transmitter and receiver to communicate between two circuit boards.
pin
I use the board for Input Device as a transmitter board. I have already added the RF connection part. For receiver, I use a board I made for Output device The plan is to make transmitter board send the capacitive value to turn on the LED on the receiver board.
First I tried programming without using a library following this tutorial but without success. Then I tried to use Virtual Wire Library following this tutorial and it works well.
Then I added the capacitive part to turn on the LED on the receiver board.
Here is code for Transmitter :
#include <VirtualWire.h> #include <CapacitiveSensor.h> CapacitiveSensor capSensor = CapacitiveSensor (4, 2); int threshold = 1000; char *controller; void setup() { pinMode(13, OUTPUT); vw_set_ptt_inverted(true); vw_set_tx_pin(12); vw_setup(4000);// speed of data transfer Kbps Serial.begin(9600); // debug only } void loop() { long capValue = capSensor.capacitiveSensor(30); // capacitive sensor Serial.println(capValue); if (capValue > threshold || capValue < 0) { controller = "1" ; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(13, 1); } else { controller = "0" ; vw_send((uint8_t *)controller, strlen(controller)); vw_wait_tx(); // Wait until the whole message is gone digitalWrite(13, 0); } }
Here is code for Receiver :
#include <VirtualWire.h> void setup() { vw_set_ptt_inverted(true); // Required for DR3100 vw_set_rx_pin(12); vw_setup(4000); // Bits per sec pinMode(13, OUTPUT); vw_rx_start(); // Start the receiver PLL running } void loop() { uint8_t buf[VW_MAX_MESSAGE_LEN]; uint8_t buflen = VW_MAX_MESSAGE_LEN; if (vw_get_message(buf, &buflen)) // Non-blocking { if(buf[0]=='1'){ digitalWrite(13,1); } if(buf[0]=='0'){ digitalWrite(13,0); } } }
Download files : transmitter (ino) receiver (ino) << previous | next >>