Super beginner. I'm just trying to get a test going to see if my RF24s are communicating using a push button and led. I am using two arduino UNOs and have several RF24s to swap out. I have the Transmitter with a push button with 5vs before it and with a jumper after the button to pin 2 for reading, and then an led and 220ohm resistor to ground. The Receiver is just an led connected to pin 5 then followed by another 220ohm resistor to ground.
Or send send the state of the button instead of only sending when the button is pushed. Right now you are only sending ones if anything.
Try this code. Replaces the transmitter loop() function. It reads the button every 50 milliseconds and transmits the state (0 or 1). The LED on the receiver should now follow the transmitted button state. Get rid of the delay in the receive loop().
ok so I got the led blinking with groundFungus' code, but it is not even and very dim. Should I add a capacitor or anything to even out the voltage? I will also try taking out the & and see if that changes something. Thank you guys for your help.
I suggest that you lose the LED and 220R from the button pin and just put a 10K resistor from the button pin to ground. If you want an LED to follow the button state, put it on its own pin.
The way that you have it, the button pin floats when the switch is open. A floating pin's state is indeterminate (random).
With the timer, the transmitter would sent 20 times a second. Without the timer the transmitter is trying to send, perhaps, thousands of times a second. Too much.
The LED on the receiver should follow the state of the switch on the transmitter.
I made some changes to your code so that I could test on my Unos with rf24 radios. So the CE and CSN pins are changed. You will need to change those pin numbers back to your setup. I gave all the pins meaningful names. I changed the switch on the transmitter to active low (which is best practice, nowadays). So the switch is connected to ground and an input set to INPUT_PULLUP to use the internal pullup. No external resistor needed. The input reads LOW when the switch pressed. The LED on the receiver turns on when the transmitter switch is closed and turns off when the transmitter switch is open.
Ok. When I press and hold it, it will blink once and then it won't for about 5 seconds and it might do it a couple times real fast or be really really dim and flicker before shutting all the way off and repeating. Could this be a power issue with the RF24s or Arduinos?
The code that I posted last, works fine on my setup.
I don't know. I have no way of knowing how your rf24s are powered.
The simple rf24 tutorial discusses the problems and solutions with powering the radios.
The tutorial is what I used to learn about those radios. It may be good for you to try the example codes. I know that they work with properly set up radios.
I definitely will look into it. I saw your code and have been putting it in and now I can't get the led to turn off. I must have something miswired. I will check the pinout again. Thank you again for taking time to help me figure this out, especially late at night. I am done for now, but will continue tomorrow. Thanks again. I did learn a lot.