Components and supplies
Arduino Mega 2560
Resistor 47.5k ohm
Resistor 10k ohm
SparkFun Soil Moisture Sensor (with Screw Terminals)
Power MOSFET N-Channel
Temperature Sensor
Standard LCD - 16x2 White on Blue
Tools and machines
Mastech MS8217 Autorange Digital Multimeter
Soldering iron (generic)
Hot glue gun (generic)
Project description
Code
code
c_cpp
1// Include Libraries 2#include "Arduino.h" 3#include "DS18B20.h" 4#include "LiquidCrystal_PCF8574.h" 5#include "SoilMoisture.h" 6#include "Pump.h" 7 8 9// Pin Definitions 10#define DS18B20_PIN_DQ 3 11#define SOILMOISTURE5V_PIN_SIG A10 12#define WATERPUMP_PIN_COIL1 2 13 14 15 16// Global variables and defines 17// There are several different versions of the LCD I2C adapter, each might have a different address. 18// Try the given addresses by Un/commenting the following rows until LCD works follow the serial monitor prints. 19// To find your LCD address go to: http://playground.arduino.cc/Main/I2cScanner and run example. 20#define LCD_ADDRESS 0x3F 21//#define LCD_ADDRESS 0x27 22 23// Define LCD characteristics 24#define LCD_ROWS 4 25#define LCD_COLUMNS 20 26#define SCROLL_DELAY 150 27#define BACKLIGHT 255 28// object initialization 29DS18B20 ds18b20(DS18B20_PIN_DQ); 30LiquidCrystal_PCF8574 lcd20x4; 31SoilMoisture soilMoisture5v(SOILMOISTURE5V_PIN_SIG); 32Pump waterpump(WATERPUMP_PIN_COIL1); 33 34 35 36// define vars for testing menu 37const int timeout = 10000; //define timeout of 10 sec 38char menuOption = 0; 39long time0; 40 41// Setup the essentials for your circuit to work. It runs first every time your circuit is powered with electricity. 42void setup() 43{ 44 // Setup Serial which is useful for debugging 45 // Use the Serial Monitor to view printed messages 46 Serial.begin(9600); 47 while (!Serial) ; // wait for serial port to connect. Needed for native USB 48 Serial.println("start"); 49 50 // initialize the lcd 51 lcd20x4.begin(LCD_COLUMNS, LCD_ROWS, LCD_ADDRESS, BACKLIGHT); 52 menuOption = menu(); 53 54} 55 56// Main logic of your circuit. It defines the interaction between the components you selected. After setup, it runs over and over again, in an eternal loop. 57void loop() 58{ 59 60 61 if(menuOption == '1') { 62 // DS18B20 1-Wire Temperature Sensor - Test Code 63 // Read DS18B20 temp sensor value in degrees celsius. for degrees fahrenheit use ds18b20.ReadTempF() 64 float ds18b20TempC = ds18b20.readTempC(); 65 Serial.print(F("Temp: ")); Serial.print(ds18b20TempC); Serial.println(F(" [C]")); 66 67 } 68 else if(menuOption == '2') { 69 // LCD Display 20x4 I2C - Test Code 70 // The LCD Screen will display the text of your choice. 71 lcd20x4.clear(); // Clear LCD screen. 72 lcd20x4.selectLine(2); // Set cursor at the begining of line 2 73 lcd20x4.print(" Circuito.io "); // Print print String to LCD on first line 74 lcd20x4.selectLine(3); // Set cursor at the begining of line 3 75 lcd20x4.print(" Rocks! "); // Print print String to LCD on second line 76 delay(1000); 77 78 } 79 else if(menuOption == '3') { 80 // Soil Moisture Sensor - Test Code 81 int soilMoisture5vVal = soilMoisture5v.read(); 82 Serial.print(F("Val: ")); Serial.println(soilMoisture5vVal); 83 84 } 85 else if(menuOption == '4') { 86 // Submersible Pool Water Pump 240L/H - Test Code 87 // The water pump will turn on and off for 2000ms (4 sec) 88 waterpump.on(); // 1. turns on 89 delay(2000); // 2. waits 500 milliseconds (0.5 sec). 90 waterpump.off();// 3. turns off 91 delay(2000); // 4. waits 500 milliseconds (0.5 sec). 92 93 } 94 95 96 97 if (millis() - time0 > timeout) 98 { 99 menuOption = menu(); 100 } 101 102} 103 104 105 106// Menu function for selecting the components to be tested 107// Follow serial monitor for instrcutions 108char menu() 109{ 110 111 Serial.println(F("\ 112Which component would you like to test?")); 113 Serial.println(F("(1) DS18B20 1-Wire Temperature Sensor")); 114 Serial.println(F("(2) LCD Display 20x4 I2C")); 115 Serial.println(F("(3) Soil Moisture Sensor")); 116 Serial.println(F("(4) Submersible Pool Water Pump 240L/H")); 117 Serial.println(F("(menu) send anything else or press on board reset button\ 118")); 119 while (!Serial.available()); 120 121 // Read data from serial monitor if received 122 while (Serial.available()) 123 { 124 char c = Serial.read(); 125 if (isAlphaNumeric(c)) 126 { 127 if(c == '1') 128 Serial.println(F("Now Testing DS18B20 1-Wire Temperature Sensor")); 129 else if(c == '2') 130 Serial.println(F("Now Testing LCD Display 20x4 I2C")); 131 else if(c == '3') 132 Serial.println(F("Now Testing Soil Moisture Sensor")); 133 else if(c == '4') 134 Serial.println(F("Now Testing Submersible Pool Water Pump 240L/H")); 135 else 136 { 137 Serial.println(F("illegal input!")); 138 return 0; 139 } 140 time0 = millis(); 141 return c; 142 } 143 } 144 } 145 146/******************************************************* 147 148* Circuito.io is an automatic generator of schematics and code for off 149* the shelf hardware combinations. 150 151* Copyright (C) 2016 Roboplan Technologies Ltd. 152 153* This program is free software: you can redistribute it and/or modify 154* it under the terms of the GNU General Public License as published by 155* the Free Software Foundation, either version 3 of the License, or 156* (at your option) any later version. 157 158* This program is distributed in the hope that it will be useful, 159* but WITHOUT ANY WARRANTY; without even the implied warranty of 160* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 161* GNU General Public License for more details. 162 163* You should have received a copy of the GNU General Public License 164* along with this program. If not, see <http://www.gnu.org/licenses/>. 165 166* In addition, and without limitation, to the disclaimers of warranties 167* stated above and in the GNU General Public License version 3 (or any 168* later version), Roboplan Technologies Ltd. ("Roboplan") offers this 169* program subject to the following warranty disclaimers and by using 170* this program you acknowledge and agree to the following: 171* THIS PROGRAM IS PROVIDED ON AN "AS IS" AND "AS AVAILABLE" BASIS, AND 172* WITHOUT WARRANTIES OF ANY KIND EITHER EXPRESS OR IMPLIED. ROBOPLAN 173* HEREBY DISCLAIMS ALL WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT 174* NOT LIMITED TO IMPLIED WARRANTIES OF MERCHANTABILITY, TITLE, FITNESS 175* FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND THOSE ARISING BY 176* STATUTE OR FROM A COURSE OF DEALING OR USAGE OF TRADE. 177* YOUR RELIANCE ON, OR USE OF THIS PROGRAM IS AT YOUR SOLE RISK. 178* ROBOPLAN DOES NOT GUARANTEE THAT THE PROGRAM WILL BE FREE OF, OR NOT 179* SUSCEPTIBLE TO, BUGS, SECURITY BREACHES, OR VIRUSES. ROBOPLAN DOES 180* NOT WARRANT THAT YOUR USE OF THE PROGRAM, INCLUDING PURSUANT TO 181* SCHEMATICS, INSTRUCTIONS OR RECOMMENDATIONS OF ROBOPLAN, WILL BE SAFE 182* FOR PERSONAL USE OR FOR PRODUCTION OR COMMERCIAL USE, WILL NOT 183* VIOLATE ANY THIRD PARTY RIGHTS, WILL PROVIDE THE INTENDED OR DESIRED 184* RESULTS, OR OPERATE AS YOU INTENDED OR AS MAY BE INDICATED BY ROBOPLAN. 185* YOU HEREBY WAIVE, AGREE NOT TO ASSERT AGAINST, AND RELEASE ROBOPLAN, 186* ITS LICENSORS AND AFFILIATES FROM, ANY CLAIMS IN CONNECTION WITH ANY OF 187* THE ABOVE. 188********************************************************/
Comments
Only logged in users can leave comments
Niko123
0 Followers
•0 Projects
Table of contents
Intro
9
0