Hey guys, I am working on a (what I think is difficult) project. Basically I want to have a few reed switches become wireless using arduino and have heard of the ESP wifi Module.
What the end result should be is that when the door closes, it also closes another circuit remotely.
I have looked up and found a wireless relay on ebay, bought one to see how it works because it basically emulates the function I need, but I can only get it to work with one relay at a time (4 relays total on the one I bought). If additional switches are closed on the transmitter, the receiver trips out and does not do anything (behaves as if no switches are closed)
If you are having trouble understanding I may be able to do some fancy artwork to explain better.
I already have the arduino uno, and will buy some of the ESP modules as they’re likely to be required for this.
Thank you for the reply, what I have now is basically that. However it does not work as you may expect it with more than 1 sensor connected to it. The reed switches hooked up to the transmitter are Normally open, meaning when there is no magnet present it’s an open circuit, thus when a magnet is present the circuit is closed and the transmitter is on. If you do that and have more than 1 circuit closed, then the receiver on the other end does not respond as you’d expect and behaves as if no circuits are closed until it’s back to receiving 1 transmission.
What I am thinking to do now, is trying to learn the nrf24l01, but I have no programming experience so I’d be playing it all by ear.
Another thing I thought of, is having the reed switches hooked up to an arduino and having the open/closed states translate to a high and low state. The arduino can then close the circuit on the transmitter for a second, receiver gets the signal and closes/latches and when the circuit opens vice versa. Does anyone have any direction on that? I have an arduino mega, so I should be able to hook up quite a few sensors that way (4 pins per sensor, 2 in 2 out)
I would use an Arduino to read the switches, convert all the switch states into a message of one or more bytes, and transmit that message using VirtualWire and inexpensive 434 MHz modules to another Arduino.
Projects similar to yours have been discussed many times on the Arduino forum.
I have figured out a way to do this but am unsure of how to code the arduino to do what I want. I have attached a picture to show the circuit diagram and a few words. If you can’t read my beautiful (read:not) handwriting I have typed it out below. Again thank you so much for the help provided so far. It has really helped and i am excited to have this first project done!
Text in photo: “Code needed for if the switch is closed then write the transistor pin high for 1-2 seconds then revert to low, once the switch opens after being closed, write the transistor pin high for 1-2 seconds, then revert to low.”
I have looked into the blinkwithoutdelay sample code but I can’t figure out how to make it just turn on for a short period. I will need to do this program with 2 circuits at the same time, however it is highly unlikely there will be a state change at the same time on either of the input switches.
I got it working the way I wanted to, I used this code:
const int buttonPin = 3; //Set button pin to pin 3
const int ledPin = 2; //set Led pin (Circuit closer) to pin 2
volatile int buttonState = 0; //Make the button state value volatile so it doesnt get removed during compilation.
void setup() {
pinMode(ledPin, OUTPUT); //Set led pin as output
pinMode(buttonPin, INPUT); //Set Button Pin as input
attachInterrupt(1, pin_ISR, CHANGE); //Set interrupts for Pin 3, and interrupt on an event change
}
void loop() {
digitalWrite(ledPin, LOW); //Write Circuit Low, to shut it off
delay(1500);
}
void pin_ISR() {
buttonState = digitalRead(buttonPin); //read button state
digitalWrite(ledPin, HIGH); //Write the pin high on state change
}
It is clunky, but it works the way I wanted it to for sure. Does anyone have any recommendation to make the code more reliably trigger the circuit on?
Buttons bounce. When you press them, the contacts actually bounce, opening and closing multiple times. Do a search on “Ganssle debouncing” for a lot more info and some sample debouncing code.
I haven’t had an issue with bouncing, the issue more or less lies in the random nature of the loop shutting the circuit off and the interrupt turning it on upon a state change. After having tested it last night a few times though, it does not seem like much of an issue at all as the transmitter responds quite quickly to the commands sent to it.
Mike perhaps you may be able to tell me how to get that exact code, working on 2 or more circuits. I tried just doubling everything and while it does work, one input causes 2 outputs which can’t happen.
I tried this setup over about a week or so and it works great but is very susceptible to interference and is therefore an unreliable setup that can’t be used.
I have received a couple of arduino nanos which I have wired up to a few nrf24l01 modules. I am able to get one relay working using some code I found online: https://www.dropbox.com/s/mt9ibesh4viws … l.zip?dl=0
when used, this code is supposed to have 3 button inputs on one arduino that transmit over to another arduino that receives the inputs and drives pins high as a result.
When I tried it, it makes all 3 pins drive high, if any pin on the input arduino is driven high. Weird.
Does anyone know how to correct these codes so that
One input=one output
You can have multiple inputs controlling multiple outputs at once?