Pages: [1]   Go Down
Author Topic: Arduino locks when magnetic contact sensor is attached  (Read 1498 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
#define ENC_PORT PINB

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

Any ideas?
Logged

Cumming, GA
Offline Offline
Edison Member
*
Karma: 20
Posts: 1658
Ultimate DIY: Arduino
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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

Quote:
Quote
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.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

pwillard,

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.
Logged

0
Offline Offline
Shannon Member
****
Karma: 215
Posts: 12467
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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]
« Last Edit: July 11, 2011, 09:04:50 pm by MarkT » Logged

[ I won't respond to messages, use the forum please ]

Pages: [1]   Go Up
Jump to: