Book Image

Intel Galileo Blueprints

By : Marco Schwartz
Book Image

Intel Galileo Blueprints

By: Marco Schwartz

Overview of this book

Table of Contents (19 chapters)
Intel Galileo Blueprints
About the Author
About the Reviewers
Free Chapter
Setting Up the Galileo Board and the Development Environment

Using the relay controller

Now that we have assembled the relay controller, we will build the Arduino sketch to make the circuit do as we like. We will create the sketch in such a way that it will be able to control the relay through the push button. To do so, you will need to follow the code given in these steps:

  1. First, we will declare the relay and the button pins. The relay is pin 7, while the button is pin 8. To do this, follow the code:

    int relayPin = 7;
    int buttonPin = 8;
  2. Next, we will create variables for the button states:

    int buttonState;
    int lastButtonState = LOW;   
    int previousButtonState = LOW;
  3. To debounce the button and achieve a stable state for the relay, we will add the following code. We will declare a default last debounce time and debounce delay:

    long lastDebounceTime = 0;
    long debounceDelay = 50;
  4. Then, we will create a variable for the state of the relay:

    int relayState = LOW;

    Inside the setup() function of the sketch, we will set the pins for the relay and the button. The button...