Controlling the relay
In this part, we are going to program the Arduino board to remotely control the relay and LED that are connected to the board by sending an SMS to the FONA shield. As most of the code is similar to the code that we saw in the previous section, I'll only detail the new elements of code here.
We need to define the pins on which the relay and the LED are connected:
#define RELAY_PIN 7 #define LED_PIN 8
Then, we'll define a set of variables for a counter for the relay/lock. This is needed because after we open a lock, for example, we will want it to close automatically after a given amount of time for the purpose of safety. Here, we use a delay of 5 seconds:
bool lock_state = false; int init_counter = 0; int lock_counter = 0; int lock_delay = 5000;
Then, we will define variables to count the number of SMS stored in the card:
int8_t smsnum = 0; int8_t smsnum_old = 0;
We will also set two "passwords" to activate or deactivate the relay. I used very simple passphrases here; however...