Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Arduino Networking

You're reading from   Arduino Networking Connect your projects to the Web using the Arduino Ethernet library

Arrow left icon
Product type Paperback
Published in Aug 2014
Publisher
ISBN-13 9781783986866
Length 118 pages
Edition 1st Edition
Languages
Tools
Concepts
Arrow right icon
Author (1):
Arrow left icon
Marco Schwartz Marco Schwartz
Author Profile Icon Marco Schwartz
Marco Schwartz
Arrow right icon
View More author details
Toc

Testing the relay

We are now going to build a very simple sketch to test the hardware connections we just made. The sketch will simply switch the relay on and off every second.

The sketch starts by declaring the right pin for the relay:

const int relay_pin = 7;

Then, we set this pin as an output:

pinMode(relay_pin,OUTPUT);

Then, in the loop() function of the sketch, we set the relay to a HIGH state:

digitalWrite(relay_pin, HIGH);

We wait for 5 seconds:

delay(5000)

Then, we switch the relay pin to a LOW state again:

digitalWrite(relay_pin, LOW);

We then wait again for 5 seconds:

delay(5000);

Note

The code for this section can be found in the GitHub repository for this chapter at https://github.com/openhomeautomation/arduino-networking/tree/master/chapter4.

You can now upload the code to the Arduino board. You should hear the relay switching on and off every second. If you connect a lamp to the project, for example, you should also see it switching on and off every second.

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime