I am trying to integrate solenoid lock, reed switch in my Arduino Code. The flow that I am trying to achieve is - first, the solenoid lock is set to LOW and then the program checks if reed switch is High or Low. Only if its High I want to proceed further. However, even when the reed switch is HIGH the program is not executing further. Here is my code below:
#include<HX711_ADC.h>
#include<math.h>
//pins for lock
int solenoidPin = 7;
//pins for reed switch
int reedSwitch = 2;
bool reedSwitchStatus;
//pin for led
int led_pin= 9;
void setup()
{
Serial.begin(38400);
pinMode(solenoidPin, OUTPUT);
pinMode(reedSwitch, INPUT);
doorUnlock();
}
void loop()
{}
void doorUnlock()
{
digitalWrite(solenoidPin, LOW);
delay(5000);
checkReedSwitchStatus();
}
void checkReedSwitchStatus()
{
reedSwitchStatus = digitalRead(reedSwitch);
if(reedSwitchStatus == 1)
{
Serial.println("Beginning Transaction");
beginTransaction();
}
if (reedSwitchStatus == 0)
{
Serial.println("Ending trasaction");
endTransaction();
}
}
void beginTransaction()
{
digitalWrite(led_pin, HIGH);
delay(500);
digitalWrite(led_pin, LOW);
delay(500);
}
My issue is the beginTransaction function is never executed. Serial monitor continuously prints 'Beginning Transaction'. Attached the screenshot of the serial monitor. Please suggest me what is the error in my code. Thanks in advance!
beginTransaction()
function is not executed. Please include the full code. Also: Do you have an external pullup or pulldown resistor for the reed switch? – chrisl Oct 7 at 7:56