Go Down

Topic: Arduino locks when magnetic contact sensor is attached (Read 2505 times) previous topic - next topic


I have connected a honeywell magnetic door contact to pin 10 on the arduino with a pull up resistor configuration.  1k Resistor from 5v through contact sensor to gnd, with pin 10 connected between the resistor and sensor.  Using a multimeter, I can verify logic high and low when the magnet is pulled away and placed near the sensor.  Pin 10 is setup as an INPUT.  I have a simple if pin 10 is low then do this loop.  The problem is anytime the sensor is activated via the magnet the arduino locks up and needs to be reset. If I move the same input to pin 5 there is no problem, everything works as it should.

#define alarmCheck 5//<----- Works when pin 5 does not work when pin 10
#define DATAOUT 11 //MOSI
#define DATAIN  12 //MISO
#define SPICLOCK  13 //sck
#define RTC_CHIPSELECT 7 // chip select (ss/ce) for RTC, active high
#define txPin 4  //Software Serial port for LCD display
#define UDTI 2 //Update Time Interrupt
#define UMEI 3 //Update MEnu Interrupt
#define ENC_A 8 //Rotary Encoder Pin A
#define ENC_B 9 //Rotary Encoder Pin B

Is the way I defined the pins setting some setting on Pin 10 that I am unaware of?

Any ideas?


From the Arduino SPI reference page... you get an explanation of the issue.  It's due to the hardware SPI on the chip.

On the Arduino Duemilanove and other ATmega168 / 328-based boards, the SPI bus uses pins 10 (SS), 11 (MOSI), 12 (MISO), and 13 (SCK). On the Arduino Mega, this is 50 (MISO), 51 (MOSI), 52 (SCK), and 53 (SS). Note that even if you're not using the SS pin, it must remain set as an output;

So you can't use 10 as in INPUT pin.



Thank you for the quick response . . . makes sense in hind sight.  You probably saved me at least a few more hours of troubleshooting something I would not have been able to change.


Jul 12, 2011, 04:01 am Last Edit: Jul 12, 2011, 04:04 am by MarkT Reason: 1
The  ATmega SPI hardware only uses pin10 when configured as an SPI _slave_, it doesn't use it at all if an SPI master as is usually the case.  So perhaps you have SPI set up in slave mode and enabled?

[edit: actually even then it shouldn't lock up the processor, the problem could be something else like noise/spikes on that signal line]
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

Go Up