-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathElentirmo_v0.1.ide
92 lines (80 loc) · 2.96 KB
/
Elentirmo_v0.1.ide
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//Servo Setup
//Connect servo to GND (black or brown wire), 5V (red wire) and the signal (white or orange wire) to Analog 0
#include <Servo.h>
Servo servo1;
int pos = 0; //variable to store servo position
static int open_angle = 90; //Determine the angle for your own setup through trial and error
static int close_angle = 0; //Determine the angle for your own setup through trial and error
//LED Setup
int ledYellow = 3; // Yellow LED connected to digital pin 3 for flat panel relay
int ledRed = 6; // Red LED connected to digital pin 6 for closing cover
int ledWhite = 12; // White LED connected to digital pin 12 for opening cover
//Relay Setup
#define CH1 10 // Connect Digital Pin 10 on Arduino to CH1 on Relay Module (may be labelled IN1)
#define CH2 9 // Connect Digital Pin 9 on Arduino to CH2 on Relay Module (may be labelled IN2)
#define CH3 8 // Connect Digital Pin 8 on Arduino to CH3 on Relay Module (may be labelled IN3)
#define CH4 7 // Connect Digital Pin 7 on Arduino to CH4 on Relay Module (may be labelled IN4)
void setup(){
// Open serial connection.
Serial.begin(9600);
//Define the LED outputs
pinMode(ledWhite, OUTPUT);
pinMode(ledRed, OUTPUT);
pinMode(ledYellow, OUTPUT);
//Setup all the Relay Pins
pinMode(CH1, OUTPUT);
pinMode(CH2, OUTPUT);
pinMode(CH3, OUTPUT);
pinMode(CH4, OUTPUT);
digitalWrite(CH1, HIGH); //Dectivate realy channel 1
digitalWrite(CH2, HIGH); //Dectivate realy channel 2
digitalWrite(CH3, HIGH); //Dectivate realy channel 3
digitalWrite(CH4, HIGH); //Dectivate realy channel 4
//Define the servo
servo1.attach(0); //analog pin 0
//2x LED Blink startup check
digitalWrite(ledRed, HIGH);
digitalWrite(ledWhite, HIGH);
digitalWrite(ledYellow, HIGH);
delay(500);
digitalWrite(ledRed, LOW);
digitalWrite(ledWhite, LOW);
digitalWrite(ledYellow, LOW);
delay(500);
digitalWrite(ledRed, HIGH);
digitalWrite(ledWhite, HIGH);
digitalWrite(ledYellow, HIGH);
delay(500);
digitalWrite(ledRed, LOW);
digitalWrite(ledWhite, LOW);
digitalWrite(ledYellow, LOW);
}
void loop(){
//Nothing in here as we’re only using the Arduino to listen to the serial port
}
void serialEvent()
{if (Serial.available()) {
char ser = Serial.read();
if(ser == 'O'){ //Detect an open dust cover command
digitalWrite(ledWhite, HIGH);
servo1.write(open_angle);
delay(1000);
digitalWrite(ledWhite, LOW);
}else if(ser == 'C'){ //Detect a close dust cover command
digitalWrite(ledRed, HIGH);
servo1.write(close_angle);
delay(1000);
digitalWrite(ledRed, LOW);
}else if(ser == 'F'){ //Detect a turn on flat panel via relay command
digitalWrite(ledYellow, HIGH);
digitalWrite(CH1, HIGH); //Activate realy channel 1
delay(3000);
digitalWrite(ledYellow, LOW);
}else if(ser == 'Q'){ //Detect a turn off flat panel via relay command
digitalWrite(ledYellow, HIGH);
digitalWrite(CH1, LOW); //Dectivate realy channel 1
delay(3000);
digitalWrite(ledYellow, LOW);
}
}
}