Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Arduino Sun Tracker
- Demonstrates analog input by reading analog sensors on analog pin 0 to 3 and
- turning on and off a PWM signal on digital pin 10 and 11.
- The amount of time the PWM signal will be switched on depends on
- the value obtained by delay() function.
- * Note: because most Arduinos have a built-in LED attached
- to pin 13 on the board, the LED is optional.
- Created by Colin
- Modified 29.03.2014
- This code is for public use.
- */
- int sensorPin = A0; // select the input pins for the analog sensors
- int sensorPin1 = A1;
- int sensorPin2 = A2;
- int sensorPin3 = A3;
- //int rainsensor = A4;
- int joyPinx = A5; // connecetd to VRx
- int joyPiny = A6; // connecetd to VRy
- float vrx = 0; // variable to store the value from VRx
- float vry = 0; // variable to store the value from VRy
- //const int limitew = 2; // the number of the EW limit switch pin
- //const int limitew1 = 3;
- //const int limitns = 6; // the number of the NS limit switch pin
- //const int limitns1 = 7;
- // const int arrestorns = 4; // output Pin for arrestor solenoid
- // const int arrestorew = 5; // output Pin for arrestor solenoid
- // const int swew = 0; // Manual movement switches
- // const int swew1 = 1;
- // const int swns = 8;
- // const int swns1 = 9;
- int output = 10; // select the PWM pin for the Allegro Stepper Driver
- int output1 = 11;
- int outdir = 12; // select the pin for the direction
- int outdir1 = 13;
- float sensorValue = 0; // variable to store the value coming from the sensor
- float sensorValue1 = 0;
- float sensorValue2 = 0;
- float sensorValue3 = 0;
- //float rainvalue = 0;
- //int limitsw = 0; // variable to store the value coming from the inputs
- //int limitsw1 = 0;
- //int limitsw2 = 0;
- //int limitsw3 = 0;
- //int buttonew = 0;
- //int buttonew1 = 0;
- //int buttonns = 0;
- //int buttonns1 = 0;
- // int lockns = 0;
- // int lockew = 0;
- void setup() {
- // initialize serial communication at 9600 bits per second:
- Serial.begin(9600);
- // declare the INPUTS:
- // pinMode(limitew, INPUT);
- // pinMode(limitew1, INPUT);
- // pinMode(limitns, INPUT);
- // pinMode(limitns1, INPUT);
- // pinMode(swew, INPUT);
- // pinMode(swew1, INPUT);
- // pinMode(swns, INPUT);
- // pinMode(swns1, INPUT);
- // declare the output PIN as an OUTPUT:
- pinMode(output, OUTPUT);
- pinMode(output1, OUTPUT);
- pinMode(outdir, OUTPUT);
- pinMode(outdir1, OUTPUT);
- //pinMode(arrestorns, OUTPUT);
- //pinMode(arrestorew, OUTPUT);
- }
- void loop() {
- // read the analog values from the sensors:
- sensorValue = analogRead(sensorPin) *(5.0 / 1023.0); // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
- sensorValue1 = analogRead(sensorPin1)*(5.0 / 1023.0);
- sensorValue2 = analogRead(sensorPin2)*(5.0 / 1023.0);
- sensorValue3 = analogRead(sensorPin3)*(5.0 / 1023.0);
- // rainvalue = analogRead(rainsensor)*(5.0 / 1023.0);
- vrx = analogRead(joyPinx)*(5.0 / 1023.0);
- vry = analogRead(joyPiny)*(5.0 / 1023.0);
- // limitsw = digitalRead(limitew); // Read signal from input Pins and write to variable
- // limitsw1 = digitalRead(limitew1);
- // limitsw2 = digitalRead(limitns);
- // limitsw3 = digitalRead(limitns1);
- // buttonew = digitalRead(swew);
- // buttonew1 = digitalRead(swew1);
- // buttonns = digitalRead(swns);
- // buttonns1 = digitalRead(swns1);
- //lockns = digitalRead(arrestorns);
- //lockew = digitalRead(arrestorew);
- //Calculating average values from light sensors. Result used for day night detection
- float avns = (sensorValue + sensorValue1) / 2; // average value NS
- float avew = (sensorValue2 + sensorValue3) / 2; // average value EW
- Serial.println("Voltage LDR");
- Serial.println(sensorValue);
- Serial.println(sensorValue1);
- Serial.println(sensorValue2);
- Serial.println(sensorValue3);
- /* Serial.println("Is it raining?");
- Serial.println(rainvalue);
- Serial.println("Value of limitswitches");
- Serial.println(limitsw);
- Serial.println("Value of limitsw1");
- Serial.println(limitsw1);
- Serial.println("Value of limitsw2");
- Serial.println(limitsw2);
- Serial.println("Value of limitsw3");
- Serial.println(limitsw3);
- Serial.println("Value of Output1");
- Serial.println(output);
- Serial.println("Value of Ouput2");
- Serial.println(output1);*/
- Serial.println("Average NS");
- Serial.println(avns);
- Serial.println("Average EW");
- Serial.println(avew);
- /*if ((avew < 0.3) && (humidityValue > 4.0) && (!buttonew || !buttonew1 || !buttonns || !buttonns1) && (!limitsw && !limit2))
- {
- digitalWrite(arrestorns, HIGH);
- digitalWrite(arrestorew, HIGH);
- }
- */
- /*if ((avew < 0.3) && (humidityValue > 4.0) && (limitsw && limit2))
- {
- digitalWrite(arrestorns, LOW);
- digitalWrite(arrestorew, LOW);
- }
- */
- /*if ((avew > 0.3) && (humidityValue < 4.0) && limitsw && limit2)
- {
- digitalWrite(arrestorns, HIGH);
- digitalWrite(arrestorew, HIGH);
- }
- */
- /*if ((avew > 0.3) && (humidityValue < 4.0) && !limitsw && !limit2)
- {
- digitalWrite(arrestorns, LOW);
- digitalWrite(arrestorew, LOW);
- }
- */
- if /*(((*/((sensorValue > (sensorValue1 + 0.01 )) && (avew > 0.8)) /*&& (rainvalue < 4.0) && !limitsw) || (vrx<2 && !limitsw)) || (((avew < 0.8) || (rainvalue > 4.0)) && !limitsw)) && (!vrx>3 || !vry<2 || !vry>3))*/
- {
- digitalWrite(outdir, LOW);
- analogWrite(output, 128);
- delay(20);
- analogWrite(output, LOW);
- //digitalWrite(outdir, LOW);
- }
- else if /*((*/((sensorValue < (sensorValue1 - 0.01)) && (avew > 0.8)) /*&& (rainvalue < 4.0) && !limitsw1) || (vrx>3 && !limitsw1)) && (!vrx<2 || !vry<2 || !vry>2))*/
- {
- digitalWrite(outdir, HIGH);
- analogWrite(output, 128);
- delay(20);
- analogWrite(output, LOW);
- //digitalWrite(outdir, HIGH);
- }
- if /*(((*/((sensorValue2 > (sensorValue3 + 0.01)) && (avew > 0.8))/* && (rainvalue < 4.0) && !limitsw2) || (vry<2 && !limitsw2)) || (((avew < 0.8) || (rainvalue > 4.0)) && !limitsw2)) && (!vrx<2 || !vrx>3 || !vry>3))*/
- {
- digitalWrite(outdir1, LOW);
- analogWrite(output1, 128);
- delay(20);
- analogWrite(output1, LOW);
- //digitalWrite(outdir1, LOW);
- }
- else if /*((*/((sensorValue2 < (sensorValue3 - 0.01)) && (avew > 0.8))/* && (rainvalue < 4.0) && !limitsw3) || (vry>3 && !limitsw3)) && (!vrx<2 || !vrx>3 || !vry<2))*/
- {
- digitalWrite(outdir1, HIGH);
- analogWrite(output1, 128);
- delay(20);
- analogWrite(output1, LOW);
- //digitalWrite(outdir1, HIGH);
- }
- delay(500);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement