#include <DHT.h>
#include <Servo.h>
//Constants
// DHT pin is used to connect with the temperature sensor
#define DHTPIN 1 // what pin we're connected to
#define DHTTYPE DHT11 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE); //// Initialize DHT sensor for normal 16mhz Arduino
//Variables
int chk;
float humidity; //Stores humidity value
float temperature; //Stores temperature value
// Servo motor use for fish feeder. It needs 5V to control so this didn't work
Servo servo1;
// Set the pins for different functions
int ledPin = 2;
int feederPin = 7;
int servo1Pin=3;
int servo1Angle=0;
/* Setup is run only once on reset or power up*/
void setup() {
// Enable the console for debugging
Serial.begin(9600);
// Set LED for 3.3V output mode
pinMode(ledPin, OUTPUT);
pinMode(feederPin, OUTPUT);
dht.begin();
// Attaching servo motor
servo1.attach(servo1Pin);
Serial.println(servo1.attached());
servo1.write(servo1Angle);
// Blink the LED 3 times and run the Servo
for (int i=0; i < 3; i++) {
//servo1Angle+=90;
digitalWrite(ledPin, HIGH);
//servo1.write(servo1Angle);
Serial.println(servo1.read());
delay(300);
digitalWrite(ledPin, LOW);
delay(300);
}
delay(1000);
digitalWrite(feederPin, LOW);
// Use the end of web address to determine LED state "H" means high
servo1Angle=0;
for (int i =0; i < 180; i++) { // goes from 180 degrees to 0 degrees
servo1Angle +=1;
servo1.write(servo1Angle); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
for (int i =0; i < 180; i++) { // goes from 180 degrees to 0 degrees
servo1Angle -=1;
servo1.write(servo1Angle); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
/* This is the loop function that runs in infinite loop */
void loop() {
delay(100);
}