does temperature affect reed switch operation?

Hey all, I have something weird going on with a project I built this summer and I’m wondering if it’s related to the seasons changing… I built an automatic chicken coop door that opens and closes based on light levels and uses reed switches to determine the door status (open or closed) and to tell the motor when to start and stop. Lately and with increasing frequency, I’ve found that the door is not stopping at the open position as if the reed switch is not triggering the motor to stop. I’m considering changing out the top switch with a door switch from a refrigerator, but before go to all that trouble I thought I’d check with the experts first in case it is something else… hopefully simpler that doesn’t require me to take everything apart :slight_smile:

I’ve noticed that the frequency of the issue is increasing lately and the temps are getting colder and days getting shorter as we head into winter so I thought maybe that might have something to do with it? Has anyone else ever heard of reed switches being affected by temperature?

Also, it only seems to happen at dawn, when the door opens to start the day… when I go to fix it, i just have to hold my hand over the photoresistor, dropping the door back down, remove my hand causing the door to raise back up and it stops where it’s supposed to every time. If I go out in the dark with a flashlight and go through the motions I get the same result, operates as expected every time… just that first stop in the morning that seems to be the problem… kind of like how your car never makes “that noise” when you have the mechanic standing there. :confused:

I thought maybe the switch components weren’t lined up well enough so I adjusted what I could and as far as I can tell they should be well within acceptable parameters, hence it working perfectly every time I’m standing out there fussing with it.

In case the issue is code related, I have attached a copy of the code I’m running and have commented out all the other parts to isolate the door operation… these are commented out on the Arduino board as well, many of these functions are still works in progress that I am stumbling through, but getting the door working flawlessly is priority number 1. I have also attached a diagram of the switch configuration in case that sheds any light… As far as the switches go, it’s pretty standard (I think), I have pull down resistors on both switches.

If the consensus is that I should replace the top switch with the fridge door switch and see if that resolves the issue, can anyone confirm that all I need to change in the code is the top switch values from 0 to 1 as the reed switch is normaly open and the fridge switch is normally closed?

Thanks so much for taking a look and your advice is always very much appreciated!

Cheers,
Joe

working_door_and_led.ino (21 KB)

reed swich diag.jpg

Are you sure they are reed switches, and not micro switches. Micro switches are unreliable. Reed switches (magnets on the door) are fully sealed, so are not affected by temp/moisture. Leo..

How are the connections to the reed switches made? Clamped, soldered, etc?

Paul

Alarm systems use reed switches on doors/windows for a reason. Leo..

See https://www.arduino.cc/en/Reference/PinMode and use INPUT_PULLUP.

What is the purpose of the resistors in series with the reed switches?

Hey all, thanks for the replies! I'm pretty sure they are reed switches, they are crimped to arduino pin connectors (I picked up a kit of headers and pins for my project)... then I soldered the resistors to a little piece of circuit board with the header connections... The resistors were recommended by others on this forum when I was asking questions during the design phase in order to prevent unintended activation of the switches from residual electricity in the circuit or something? In case you can't tell, I'm a beginner, this is my first project, and I am learning as I go with no background in electronics AT ALL :)

Would you suggest I bypass the resistors and see if there's any change? So far I've had no issues with the bottom switch, only the top one... I've also replaced it once already in case it was faulty with another reed switch (tested and worked 100% with tests before install).

Also, if I understand correctly, there are built in resistors on the mega that are activated so would these additional resistors be redundant?

Thanks, Joe

Especially with something like a chicken coop door that you are running into some sort of alignment issue. The door (typically a wood frame) is going to change shape etc. with temperature and humidity (to say nothing of the coop itself changing slightly with temp and humidity). I have used reed switches for a number of different projects and never had an issue with temperature causing problems (although never worked with them at -40F either). When you indicate the bottom works and the top has problems, that would be consistent with the door sagging or changing shape slightly (us older people can tell you - gravity always wins :o )

When circuit performance changes with temperature, the cause can be only one thing: cold solder joints. Using a HOT soldering iron remelt the solder on ALL the exposed connections and see if that corrects the problem.

Temperature sensitive circuits are debugged using heat guns and spray cans with liquid that quickly evaporates and cools the circuit. You have exactly the same symptoms!

Paul

Thanks guys, I don't think it's an alignment issue... the door is made of acrylic and the rails or channels are aluminum so besides the little bit of play that I left in on purpose to make sure it didn't bind up anywhere, it's pretty solid...

The only solder joints I have (on the switch circuits) are at the resistors... can anyone confirm if these resistors are correct or necessary?

Archibald: See https://www.arduino.cc/en/Reference/PinMode and use INPUT_PULLUP.

What is the purpose of the resistors in series with the reed switches?

so you're saying change from:

// top switch pinMode(topSwitchPin, INPUT); // set top switch pin as input digitalWrite(topSwitchPin, HIGH); // activate top switch resistor

to:

// top switch pinMode(topSwitchPin, INPUT_PULLUP); // set top switch pin as input digitalWrite(topSwitchPin, HIGH); // activate top switch resistor

and get rid of the resistors? because I have just enabled the internal resistors and no longer need external resistors?

Thanks, joe

Once again, how are the reed switches connected? Soldered or clamped?

Paul

Hey Paul, I can take a photo tonight when I get home if that helps...

jbaich: ... they are crimped to male Arduino pin connectors (I picked up a kit of headers and pins for my project)... then I soldered the resistors to a little piece of circuit board with the female header connections...

I'm not sure how else to describe it...

Thanks, joe

Crimped makes them suspect when weather is involved. I don't suppose you can get to the crimped part and give them a good squeeze with pliers. Probably too late to solder them, but you could try, if you can get needle nose pliers between the crimp and the glass enclosure so you can keep the heat from the glass.

Paul

jbaich: so you're saying change from:

// top switch pinMode(topSwitchPin, INPUT); // set top switch pin as input digitalWrite(topSwitchPin, HIGH); // activate top switch resistor

to:

// top switch pinMode(topSwitchPin, INPUT_PULLUP); // set top switch pin as input digitalWrite(topSwitchPin, HIGH); // activate top switch resistor

and get rid of the resistors? because I have just enabled the internal resistors and no longer need external resistors?

From what I understand from the information you have provided, when a reed switch is open the Arduino input is floating, in other words not connected to anything. If so it is surprising your set-up is working at all.

I note the Arduino tutorial on Digital Pins says:

Prior to Arduino 1.0.1, it was possible to configure the internal pull-ups in the following manner:

pinMode(pin, INPUT); // set pin to input digitalWrite(pin, HIGH); // turn on pullup resistors

Now the way to configure the internal pull-ups is simply: pinMode(topSwitchPin,INPUT_PULLUP);

Your resistors are in series with your reed switches; they are not pull-up resistors.

I’ve attached a little diagram of how the switch is assembled. (I don’t know how people have been able to embed images into this part of the message, but I’d love to know!)

If I understand what Archibald is saying, it’s that I can change the code to pinMode(topSwitchPin,INPUT_PULLUP), I no longer need " digitalWrite(topSwitchPin, HIGH);", and I can get rid of these external resistors entirely?

Thanks,
Joe

jbaich: If I understand what Archibald is saying, it's that I can change the code to pinMode(topSwitchPin,INPUT_PULLUP), I no longer need " digitalWrite(topSwitchPin, HIGH);", and I can get rid of these external resistors entirely?

Yes, you need a pull-up resistor between each Arduino input and +5V. You can activate the internal pull-up resistors within the Arduino integrated circuit or you can provide external resistors.

The code: digitalWrite(topSwitchPin, HIGH); is not necessary.

Archibald: From what I understand from the information you have provided, when a reed switch is open the Arduino input is floating, in other words not connected to anything. If so it is surprising your set-up is working at all.

I note the Arduino tutorial on Digital Pins says: ❝Prior to Arduino 1.0.1, it was possible to configure the internal pull-ups in the following manner:

pinMode(pin, INPUT); // set pin to input digitalWrite(pin, HIGH); // turn on pullup resistors

Now the way to configure the internal pull-ups is simply: pinMode(topSwitchPin,INPUT_PULLUP);

Your resistors are in series with your reed switches; they are not pull-up resistors.

So just to clarify, is the INPUT_PULLUP a recent edition that does the same thing as below?

pinMode(pin, INPUT); // set pin to input digitalWrite(pin, HIGH); // turn on pullup resistors

And if so, would just pulling out the external resistors, but leaving the older code as is be the same? I hesitate to drag the laptop out to the coop and potentially mess something up at this time of year... maybe in the spring, when I could just leave the door open while I figured out and fixed my mistakes if I really made a mess of things :)

jbaich:
So just to clarify, is the INPUT_PULLUP a recent edition that does the same thing as below?

pinMode(pin, INPUT); // set pin to input
digitalWrite(pin, HIGH); // turn on pullup resistors

And if so, would just pulling out the external resistors, but leaving the older code as is be the same? I hesitate to drag the laptop out to the coop and potentially mess something up at this time of year… maybe in the spring, when I could just leave the door open while I figured out and fixed my mistakes if I really made a mess of things :slight_smile:

My understanding of reading the Digital Pins tutorial is that:

pinMode(pin, INPUT); // set pin to input
digitalWrite(pin, HIGH); // turn on pullup resistors

only works with versions of Arduino software prior to version 1.0.1. Perhaps someone else could confirm whether that’s correct.

To save dragging your laptop out to the coop, would it be easier to add two external pull-up resistors, say about 10KΩ ?

Possibly, but I'm a little confused now about how to do that... pull up is on the Arduino side of the switch and pull down would be on the ground side? I would want them on the Arduino side, right?

Thanks, joe

Archibald: My understanding of reading the Digital Pins tutorial is that:

pinMode(pin, INPUT); // set pin to input digitalWrite(pin, HIGH); // turn on pullup resistors

only works with versions of Arduino software prior to version 1.0.1. Perhaps someone else could confirm whether that's correct.

No, it works on all ATmega based Arduinos, its how the hardware works. INPUT_PULLUP is a high level way to specify "turn on pullups" that can allow arduino code to be portable to other brands of microcontroller that support internal pullups in other ways.

You can look at the source for pinMode()/digitalWrite() etc to find these things out, its an open-source project which means you have the source code, so you can even change it if you like, or just read it, or you can look at it on github

As it seems the old way of activating pull-up resistors still works, I guess the problem is due to condensation on the Arduino.