2

I am trying to send RF signal from Digispark Attiny 85 (this one) and receive the signal with Arduino NANO V3.0 ATmega328 (this one). Transmitter and receiver are STX882 and SRX882 (these). Library used is RCSwitch.h.

The goal is to light up the external LED connected to NANO when I press the button connected to Attiny.

I am not skilled in Arduino stuff, but I have really tried to figure this one out on my own and find answers online. Sorry if this question does not belong here. Anyways, here is the problem:

// NiceRF 433MHz reciever SRX887
#include <RCSwitch.h>
RCSwitch reciever = RCSwitch();
void setup() {
 Serial.begin(9600);
 reciever.enableReceive(2);
 pinMode(7, OUTPUT);
}
void loop() {
 if (reciever.available()) {
 int size = reciever.getReceivedValue();
 if (size == 0) { 
 Serial.print("Unknown message"); //probably kinda useless line
 }
 else {
 digitalWrite(7, HIGH); // Turn on the LED
 delay(1000); // Wait for 1 second
 digitalWrite(7, LOW); // Turn off the LED
 delay(1000); // Wait for 1 second
 }
 // reset of module to be able to recieve next message
 reciever.resetAvailable();
 }
}

I understand the code like this: The Receiver will check if it receives anything and if so, it will light up pin 7 and therefore the LED connected to the pin 7 will be on.

Now for the Digispark Attiny 85 transmitter:

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void setup() {
 pinMode(1, OUTPUT);
 mySwitch.enableTransmit(2);
}
void loop() { 
 mySwitch.send("000110110001010100010001"); 
 digitalWrite(1, HIGH);
 delay(250); 
 digitalWrite(1, LOW);
 delay(250); 
}

I found this piece of code online and did not modify it. If I understand this correctly, it is not important, what the message is, but if it is sent at all. The receiver should light an LED up in every time it receives the signal.

I am confident that the wires are connected correctly.

Do you have any idea why this setup does not work?


Edit: As @jsotola suggested, I tried to make a circuit that will simply send HIGH signal to transmitter module, receive this signal at receiver module and if arduino board recognises that there is HIGH signal coming from receiver, it will send HIGH signal to the LED pin and LED would light up.

For this experiment, I switched Digispark for generic Arduino UNO ATmega clone to make things simpler. There is no library used in this example.

TRANSMITTER CODE:

const int TPin = 10;
void setup() {
 // Initialize the LED pin as an output
 pinMode(TPin, OUTPUT);
}
void loop() {
 // Turn on the LED
 digitalWrite(TPin, HIGH);
 delay(500); // Wait for 1 second
 // Turn off the LED
 digitalWrite(TPin, LOW);
 delay(500); // Wait for 1 second
}

RECEIVER CODE:

// Pin connected to the LED
const int ledPin = 7;
// Pin connected to input signal
const int inputPin = 2;
void setup() {
 // Initialize the LED pin as an output
 pinMode(ledPin, OUTPUT);
 // Initialize the input pin as an input
 pinMode(inputPin, INPUT);
}
void loop() {
 // Read the state of the input pin
 int inputState = digitalRead(inputPin);
 // Check if the input pin is HIGH
 if (inputState == HIGH) {
 // Turn on the LED
 digitalWrite(ledPin, HIGH);
 } else {
 // Turn off the LED
 digitalWrite(ledPin, LOW);
 }
}

TRANSMITTER SETUP:

Transmitter setup

(note that there is an antenna soldered to the transmitter module, but it is out of frame) The LED is simply for me to see when a signal is send to the transmitter. (Blinks in intervals as intended)

RECEIVER MODULE SETUP: Pins on receiver from left to right (form orange to green wire) are GND, CS, DATA, VCC. GND and CS are connected to the GND pin on Nano, VCC is connected to the 5V pin on Nano (this receiver works on 5V and does not require the usual ~3.3V). DATA is connected to the D2 pin on Nano.

Receiver module setup

The LED is simply connected to GND and pin D7 on Nano (out of frame) and does light up even if I touch the pin. LED stays off when D2 is grounded.

This setup does not work correctly and I have tried it for different Receivers/Transmitters (i have multiple of each). Once again thank you for all your suggestions. Does anyone have any idea what do I do wrong in here?

Thanks!

asked Jul 1, 2023 at 17:54
5
  • 1
    If you open the serial monitor what do you see? Is it printing "Unknown message"? Commented Jul 1, 2023 at 20:34
  • you have not said that you verified the LED ... start with that ... write simple code that blinks the LED Commented Jul 1, 2023 at 23:54
  • the two radio modules act as a wire ... set the output data pin high and the receiver data pin should follow ... write a simple sketch to "blink" the output every second ... write a simple sketch to light an LED when receive pin is high, turn off LED if the pin is low Commented Jul 2, 2023 at 2:01
  • Thank you all for help. @Delta_G when i open the correct (9600) serial monitor, I do not see anything. If I try to SerialPrint any other message paralel to the RF transmit code it does work and print the test message. Commented Jul 2, 2023 at 10:50
  • @jsotola I am sorry that I did not mention it before, but the LED is checked and works correctly. About your other comment: I have tried to make a new circuit, that will just "blink" every second as you have described. However, I does not work and reciever does not recognise any sent signal. I will post new code and photos in the original post. Commented Jul 2, 2023 at 10:53

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.