Advertisement
microrobotics

RXC6 RF Receiver 433 MHZ - 4 Channel

May 10th, 2023
1,544
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. This is a simple example of how to use the RXC6 4-Channel RF Receiver with an Arduino. This script will read the data from the four channels and print the status of each channel to the Serial monitor.
  3.  
  4. This script reads the states of the four data pins whenever the VT pin goes high, indicating that a signal has been received. It then prints the status of each channel (either ON or OFF) to the Serial monitor whenever the state of a channel changes. This is done for all modes (Momentary, Latching, and Toggle).
  5.  
  6. Please remember to adjust the pins according to your setup and the specific requirements of your project. Also, note that the interpretation of the signals may vary depending on the specific transmitter you're using.
  7. */
  8.  
  9. // RXC6 4-Channel RF Receiver Example
  10. // Pin connections:
  11. // - ANT (1) to 32cm spiral antenna
  12. // - GND (2) to Arduino GND
  13. // - VT (5) to Arduino Pin 2 (or any other digital input pin)
  14. // - Data D0 (6) to Arduino Pin 3
  15. // - Data D1 (7) to Arduino Pin 4
  16. // - Data D2 (8) to Arduino Pin 5
  17. // - Data D3 (9) to Arduino Pin 6
  18.  
  19. const int vtPin = 2;
  20. const int dataPins[] = {3, 4, 5, 6};
  21. const int numChannels = sizeof(dataPins) / sizeof(dataPins[0]);
  22. bool channelStates[numChannels];
  23.  
  24. void setup() {
  25.   Serial.begin(9600);
  26.  
  27.   pinMode(vtPin, INPUT);
  28.  
  29.   for (int i = 0; i < numChannels; i++) {
  30.     pinMode(dataPins[i], INPUT);
  31.     channelStates[i] = false;
  32.   }
  33. }
  34.  
  35. void loop() {
  36.   if (digitalRead(vtPin) == HIGH) { // If a signal is received
  37.     for (int i = 0; i < numChannels; i++) {
  38.       bool newState = digitalRead(dataPins[i]);
  39.  
  40.       if (newState != channelStates[i]) {
  41.         channelStates[i] = newState;
  42.  
  43.         Serial.print("Channel ");
  44.         Serial.print(i);
  45.         Serial.print(": ");
  46.         Serial.println(newState ? "ON" : "OFF");
  47.       }
  48.     }
  49.   }
  50.  
  51.   delay(100); // Delay to avoid flooding the serial port
  52. }
  53.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement