forked from pro-utkarshM/my_StudyLamp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
My_Lamp.ino
49 lines (41 loc) · 1.08 KB
/
My_Lamp.ino
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
#define IR_SENSOR 9
const int pin5V = 5; // Pin to output 5V
const int pinGND1 = 6; // Pin to output GND1
const int pinGND2 = 7; // Pin to output GND2
// Variable to store the current state
int state = 1;
void setup() {
Serial.begin(9600);
// Set the pin modes
pinMode(pin5V, OUTPUT);
pinMode(pinGND1, OUTPUT);
pinMode(pinGND2, OUTPUT);
pinMode(IR_SENSOR, INPUT);
// Initialize the output pins
digitalWrite(pin5V, LOW);
digitalWrite(pinGND1, LOW);
digitalWrite(pinGND2, LOW);
}
void loop() {
int IRSensorValue = digitalRead(IR_SENSOR);
Serial.println(IRSensorValue);
delay(2000);
if(IRSensorValue==LOW){
state = (state % 3) + 1;
}
if (state == 1) {
digitalWrite(pin5V, HIGH);
digitalWrite(pinGND1, LOW);
digitalWrite(pinGND2, LOW);
}
else if (state == 2) {
digitalWrite(pin5V, HIGH);
digitalWrite(pinGND1, LOW);
digitalWrite(pinGND2, HIGH);
}
else if (state == 3) {
digitalWrite(pin5V, HIGH);
digitalWrite(pinGND1, HIGH);
digitalWrite(pinGND2, LOW);
}
}