-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInfrared_sensor_array.ino
71 lines (53 loc) · 2.82 KB
/
Infrared_sensor_array.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
Motor Control Shield_2_IR
This sketch uses a special shield designed by embeddedmarket.com / Technido which drives 2 DC motors and can read 4 IR sensors for Line following robot.
This sketch tests the IR sensors. The shield connects to 4 sensor boards, each board having an IR emitter (clear LED) and a IR detector or
phototransistor (dark device). The clear device or IR emitters are powered by 5V and usually show a forward drop of about 1.2V in forward direction.
The detector or receiver converts IR energy falling on it into current passing through a 1 M ohms resistor. Higher IR energy means more current
through 1 Mega ohm resistor. If there is no energy, there is no current and voltage across 1 M resistor is cloase to 0V.
The voltage across resistor detector voltage is compared with a threshold voltage set by potentiometer. If detector voltage exceeds
threshold (higher IR energy or white h line) then comparator output is logic 0 and
LED wired on output will become ON. The comparator output is also wired to one Arduino digital pin.
Circuit:
D10 - Comparator output due to sensor wired to connector JP22 and pot R11
D11 - Comparator output due to sensor wired to connector JP20 and pot R7
D12 - Comparator output due to sensor wired to connector JP23 and pot R9
D13 - Comparator output due to sensor wired to connector JP24 and pot R12
Originaly written by P W Dandekar in June 2013, modified on 01 October 2015.
*/
#define IR1 10
#define IR2 11
#define IR3 12
#define IR4 13
void setup() {
// set up 4 IR pins as inputs.
pinMode(IR1, INPUT);
pinMode(IR2, INPUT);
pinMode(IR3, INPUT);
pinMode(IR4, INPUT);
Serial.begin(9600);//
Serial.println("IR sensor test program begins.....");// sent starting message to serial monitor.
delay (2000);// wait for 2 seconds.
}
void loop() {
int s1,s2,s3,s4;// define vars to hold sensor status --- 0 = more IR energy and LED off , 1 = dark or less IR energy and LED on
// Read status of all 4 sensors in 4 variables.
s1 = digitalRead(IR1);
s2 = digitalRead(IR2);
s3 = digitalRead(IR3);
s4 = digitalRead(IR4);
// Send this data to serial port for viewing...
// If there is no reflecting surface in front of the sensors then there will be less or no energy falling on detector
// and the comparator output will be 1 and its LED will be off.
Serial.print("Sensor on JP22 = ");
Serial.print(s1);
Serial.print(" Sensor on JP20 = ");
Serial.print(s2);
Serial.print(" Sensor on JP23 = ");
Serial.print(s3);
Serial.print(" Sensor on JP24 = ");
Serial.println(s4);
// Put a white surface like a paper or visiting card in front of sensors. This increases sensor current, comparator output becomes 0
// and the LED becomes ON.
delay(1000);// wait here for 1 second
}// end of main