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:
(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.
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!