Book Image

Arduino Essentials

Book Image

Arduino Essentials

Overview of this book

Table of Contents (17 chapters)
Arduino Essentials
Credits
About the Author
About the Reviewer
www.PacktPub.com
Preface
Index

The greenhouse controller code


Since the code of this project is perhaps a little longer than the previous examples, I will present it first by sections without comments and include the complete code for reference at the end of this chapter.

Libraries and constant definitions

We begin our code by including the servo library that we will use to deal with the servomotor that will operate the retractable roof. We define constants that will be used all along the code as follows:

#include <Servo.h>

#define redLedPin 13
#define yellowLedPin 12
#define greenLedPin 11
#define relayPin 8
#define motorPin 6
#define buzzerPin 4
#define servoPin 3
#define buttonPin 2
#define potentiometerPin 2
#define thermistorPin 1
#define photocellPin 0
#define NOTE_A4 440
#define NOTE_A3 220
#define TEMPMIN 820
#define TEMPMAX 850
#define MEDIUMPOWER 128
#define FULLPOWER 255
#define BEGINWATERING 700
#define ENDWATERING 550
#define DAYLIGHT 400

Here is a breakdown of the 20 constants used in the preceding code...