#include #include Servo myservo; int pos = 0; SoftwareSerial mySerial(8, 9); // RX, TX void setup() { // Open serial communications and wait for port to open: myservo.attach(A5); //analog pin 0 Serial.begin(57600); while (!Serial) { ; // wait for serial port to connect. Needed for native USB port only } Serial.println("Welcome to Aquaruim Assistant"); // set the data rate for the SoftwareSerial port mySerial.begin(9600); // mySerial.println("Hello, world?"); pinMode(10, OUTPUT); pinMode(11, OUTPUT); } void loop() { // run over and over if (mySerial.available()) { String res = mySerial.readString(); if (res == "Feed") { Serial.println("Feeding ur fish NOW"); rotateServo(3); } else if (res == "ON") { Serial.println("Lights ON"); //realy 1 on digitalWrite(10, LOW); // turn the Relay on delay(1000); // wait for a second } else if (res == "OFF") { Serial.println("Lights OFF"); //realy 1 off digitalWrite(10, HIGH); // turn the Relay on delay(1000); // wait for a second } else if (res == "Dance") { Serial.println("Dancing Lights ON"); //realy 2 on digitalWrite(11, LOW); // turn the Relay on delay(1000); // wait for a second } else if (res == "NoDance") { Serial.println("Dancing lights OFF"); //realy 2 off digitalWrite(11, HIGH); // turn the Relay on delay(1000); // wait for a second } } if (Serial.available()) { mySerial.write(Serial.read()); } } void rotateServo(int rotations) { for (int i = 0; i < rotations; i++) { for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees // in steps of 1 degree myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees myservo.write(pos); // tell servo to go to position in variable 'pos' delay(15); // waits 15ms for the servo to reach the position } } }