BRLAB DOCS
HomeTutorialsHardware
IoT Relays with Particle and Blynk
IoT Relays with Particle and Blynk
  • Introduction
  • Getting Started
    • What You Will Need
    • Claim Your Particle Device
    • Setup Your Blynk Account
  • Creating the Web Dashboard
    • Template
    • Data Streams
    • Widgets
    • Widget Settings
    • Finished Web Dashboard
  • Creating the Mobile App
    • Blynk.App
    • Widgets
    • Widget Settings
  • The App Code
    • Particle Web IDE
    • Blynk Library
    • Writing The Code
      • Comment Header
      • Define Blynk Objects
      • Define Global Variables
      • Void Setup()
      • Void Loop()
      • BLYNK_WRITE()
    • Application Code
    • Control The World Around You
  • Resources
    • Blynk Documentation
    • Particle Documentation
Powered by GitBook
On this page
  1. The App Code
  2. Writing The Code

Define Global Variables

Now we need to define some global variables that the application will use to define things such as, digital outputs, relay states, relay pin array, and a character array that will hold the authentication token to connect to the Blynk cloud.

// Global Variables
char auth[] = BLYNK_AUTH_TOKEN; // defines the character array auth
const int relayPins[] = {5, 6, 7, 8}; //defines the relay pins in an array as constant intgers
const int relay1 = 5; // variable for controlling digital I/O pin 5 on the Argon
const int relay2 = 6; // variable for controlling digital I/O pin 6 on the Argon
const int relay3 = 7; // variable for controlling digital I/O pin 7 on the Argon
const int relay4 = 8; // variable for controlling digital I/O pin 8 on the Argon
volatile int relayState1 = LOW; // volatile variable for reading the current state of the relay, also setting it to LOW 
volatile int relayState2 = LOW;
volatile int relayState3 = LOW;
volatile int relayState4 = LOW;

We need to be able to control each relay with a digital I/O pin from the device thus we define a variable that is of the constant integer type and set it equal to the I/O pin that is going to be used to send the signal to the circuit that will energize the relay coil.

A constant integer means that the variable can not be redefined later in the code.

PreviousDefine Blynk ObjectsNextVoid Setup()

Last updated 2 years ago