ü ü ü
#include <Arduino.h> #include <Servo.h> #include <SPLLib.h> #include <SoftwareSerial.h> Servo servoleft; Servo servoright; int sensorvalue1, sensorvalue2; // 각각앞쪽과뒤쪽의조도센서 int voltage, voltage2; int sensorpin = A0; // 습도센서 1 int sensorpin1 = A1; // 습도센서 2 int sensorvalue3 = 0; int sensorvalue4 = 0; int tempc; int temppin = A2; // 온도센서 void Motor1Write(int power); void serviceserial(); void Motor1Write(int power) // dc모터에서사용할출력전압범위설정 int v = abs(power); if (v > 255) v = 255; if (power >= 0) digitalwrite(4, LOW); else digitalwrite(4, HIGH); analogwrite(5, v); void Motor2Write(int power) int v = abs(power); if (v > 255) v = 255; if (power >= 0) digitalwrite(7, LOW); else digitalwrite(7, HIGH); analogwrite(6, v);
void setup() Serial.begin(115200); //BTSerial.begin(115200); servoleft.attach(3); servoright.attach(2); void loop() char a = Serial.read(); if (Serial.available()) if (a == 1) servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1300); servoright.writemicroseconds(1700); delay(600); servoleft.detach(); servoright.detach(); if (a == 'w') servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1300); servoright.writemicroseconds(1700); delay(600); servoleft.detach(); servoright.detach(); if (a == 5) servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1700); servoright.writemicroseconds(1300); delay(600); servoleft.detach();
servoright.detach(); if (a == 's') servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1700); servoright.writemicroseconds(1300); delay(600); servoleft.detach(); servoright.detach(); if (a == 2) servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1300); servoright.writemicroseconds(1300); delay(600); servoleft.detach(); servoright.detach(); if (a == 'a') servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1300); servoright.writemicroseconds(1300); delay(600); servoleft.detach(); servoright.detach(); if (a == 4) servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1700); servoright.writemicroseconds(1700); delay(600); servoleft.detach(); servoright.detach(); if (a == 'd')
servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1700); servoright.writemicroseconds(1700); delay(600); servoleft.detach(); servoright.detach(); if (a == 3) servoleft.detach(); servoright.detach(); if (a == 'x') servoleft.detach(); servoright.detach(); sensorvalue1 = analogread(a3); voltage = sensorvalue1 * (5.0 / 1023.0); sensorvalue2 = analogread(a4); voltage2 = sensorvalue2 * (5.0 / 1023.0); if(sensorvalue1 >= 700 && sensorvalue2 >= 700) sensorvalue1 = 101; sensorvalue2 = 101; if(sensorvalue1 < 50 && sensorvalue2 < 50) sensorvalue1 = 101; sensorvalue2 = 101; // 밝은곳에서플랜트를정지시킴 if(a == 1) // 여기서부터시작되는코드들은자동제어시스템을무시하고 sensorvalue1 = 101; // 사용자의원격제어를강제로활성화시키는구문. sensorvalue2 = 101; delay(1000);
if(a == 'w') // 사용자의입력이자동제어시스템을무시함. sensorvalue1 = 101; sensorvalue2 = 101; delay(1000); if(a == 2) sensorvalue1 = 101; sensorvalue2 = 101; delay(1000); if(a == 's') sensorvalue1 = 101; sensorvalue2 = 101; delay(1000); if(a == 3) sensorvalue1 = 101; sensorvalue2 = 101; delay(1000); if(a == 'a') sensorvalue1 = 101; sensorvalue2 = 101; delay(1000); if(a == 4) sensorvalue1 = 101; sensorvalue2 = 101; delay(1000); if(a == 's') sensorvalue1 = 101; sensorvalue2 = 101; delay(1000); if(sensorvalue1 > 700 sensorvalue2 < 100) servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1300); servoright.writemicroseconds(1700); delay(600);
else (300 < sensorvalue1 < 650); servoleft.detach(); servoright.detach(); if(sensorvalue2 > 700 sensorvalue1 < 100) servoleft.attach(3); servoright.attach(2); servoleft.writemicroseconds(1700); servoright.writemicroseconds(1300); delay(600); else ( 300 < sensorvalue2 < 650); servoleft.detach(); servoright.detach();
// sensor of soil sensorvalue3 = analogread(sensorpin); sensorvalue4 = analogread(sensorpin1); / 0 if(sensorvalue3 < 300 ) Motor1Write(255); delay(600); else(sensorvalue3 > 300); Motor1Write(0); tempc = analogread(temppin); tempc = (5.0 * tempc * 100.0)/1024.0;
byte s[] = 0, 0, 0, 0, 0; s[0] = sensorvalue1; s[1] = sensorvalue2; s[2] = sensorvalue3; s[3] = sensorvalue4; s[4] = tempc; if (Serial.available()) Serial.write(s, 5); Serial.println(Serial.write(s, 5)); delay(100); int main(void) init(); #if defined(usbcon) USB.attach(); #endif setup(); for (;;) loop(); if (serialeventrun) serialeventrun(); return 0;
#include <Servo.h> Servo horizontal; int servoh = 90; Servo vertical; int servov = 90; // LDR pin connections // name = analogpin; int ldrlt = 0; int ldrrt = 1; int ldrld = 2; int ldrrd = 3; void setup() Serial.begin(9600); // servo connections // name.attacht(pin); horizontal.attach(9); vertical.attach(10); void loop() int lt = analogread(ldrlt); int rt = analogread(ldrrt); int ld = analogread(ldrld); int rd = analogread(ldrrd); int dtime = analogread(4)/20; int tol = analogread(5)/4;
int avt = (lt + rt) / 2; int avd = (ld + rd) / 2; int avl = (lt + ld) / 2; ) int avr = (rt + rd) / 2; int dvert = avt - avd; int dhoriz = avl - avr; if (-1*tol > dvert dvert > tol) if (avt > avd) servov = ++servov; if (servov > 180) servov = 180; else if (avt < avd) servov= --servov; if (servov < 0) servov = 0; vertical.write(servov); if (-1*tol > dhoriz dhoriz > tol) if (avl > avr) servoh = --servoh; if (servoh < 0) servoh = 0; else if (avl < avr) servoh = ++servoh; if (servoh > 180) servoh = 180;
else if (avl == avr) horizontal.write(servoh); delay(dtime);
솔라트래커를 탑재한 다이나믹 플랜트 오른쪽이 더 밝을때의 사진 양쪽의 밝기가 같을때의 사진 왼쪽이 더 밝을때의 사진 - 34 -