Hi I am new to Arduino and currently trying to do a simple project. 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;
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();
}
}
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!