I am building a automatic watering system for a school project, and while adding two sketches together i ran into the "X does not name a type" error. I have now run into the problem that i have no experience in coding.
The first sketch is the automatic watering code that uses a soil moisture sensor, water level sensor, water pump and a LED.
#include "FastLED.h"
// These constants won't change. They're used to give names to the pins used:
const int ledPin = 2; // Digital output pin that the LED is attached to
const int pumpPin = 12; // Digital output pin that the water pump is attached to
const int waterLevelPin = A3; // Analoge pin water level sensor is connected to
const int moistureSensorPin = 7; // Digital input pin used to check the moisture level of the soil
// How many leds in your strip?
#define NUM_LEDS 6
#define DATA_PIN 5
//#define CLOCK_PIN 13
CRGB leds[NUM_LEDS];
// These are the values to edit - see the instructional video to find out what needs adjusting and why:
double checkInterval = 5; //time to wait before checking the soil moisture level - default it to an hour = 1800000
int waterLevelThreshold = 180; // threshold at which we flash the LED to warn you of a low water level in the pump tank - set this as per the video explains
int emptyReservoirTimer = 15; // how long the LED will flash to tell us the water tank needs topping up - default it to 900 = 30mins
int amountToPump = 300; // how long the pump should pump water for when the plant needs it
// Global temp values
int sensorWaterLevelValue = 0; // somewhere to store the value read from the waterlevel sensor
int moistureSensorValue = 0; //somewhere to store the value read from the soil moisture sensor
void setup() {
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
}
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
pinMode(pumpPin, OUTPUT);
pinMode(moistureSensorPin, INPUT);
//flash the LED five times to confirm power on and operation of code:
for (int i = 0; i <= 4; i++) {
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
delay(300);
}
delay(2000);
digitalWrite(ledPin, HIGH); // turn the LED on
}
void loop() {
// put your main code here, to run repeatedly:
sensorWaterLevelValue = analogRead(waterLevelPin); //read the value of the water level sensor
Serial.print("Water level sensor value: "); //print it to the serial monitor
Serial.println(sensorWaterLevelValue);
if (sensorWaterLevelValue < waterLevelThreshold) { //check if we need to alert you to a low water level in the tank
for (int i = 0; i <= emptyReservoirTimer; i++) {
digitalWrite(ledPin, LOW);
delay(1000);
digitalWrite(ledPin, HIGH);
delay(1000);
}
}
else {
digitalWrite(ledPin, HIGH);
delay(checkInterval); //wait before checking the soil moisture level
}
// check soil moisture level
moistureSensorValue = digitalRead(moistureSensorPin); //read the moisture sensor and save the value
Serial.print("Soil moisture sensor is currently: ");
Serial.print(moistureSensorValue);
Serial.println(" ('1' means soil is too dry and '0' means the soil is moist enough.)");
if (moistureSensorValue == 337) {
//pulse the pump
digitalWrite(pumpPin, HIGH);
Serial.println("pump on");
delay(amountToPump); //keep pumping water
digitalWrite(pumpPin, LOW);
Serial.println("pump off");
delay(800); //delay to allow the moisture in the soil to spread through to the sensor
}
}
and the second sketch is a code to run a RGB LED strip.
#include "FastLED.h"
// How many leds in your strip?
#define NUM_LEDS 6
#define DATA_PIN 5
//#define CLOCK_PIN 13
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
}
void loop() {
for(int i=0; i<NUM_LEDS; i++){
leds[i] = CHSV(160, 255, 128);
FastLED.show();
delay(400);
leds[i] = CHSV(100,255,100);
FastLED.show();
}
}
Sketch 2 is already partially inserted into sketch 1 but the "FastLED.addleds<ws2812, DATA_PIN, RGB>(leds, NUM_LEDS); line is where the compiler runs into the error 'Serial' does not name a type
I hope you can help.