3 bit optical code scanner
Short description and operation:-
The scanner works on simple principle of physics that is, a black surface absorbs infrared radiation and white light reflects infrared radiation. The IR led and IR diode are close to one another. Then the IR led is turned on . If the reflected light from the surface is more. Then the resistance of diode in reverse bias falls, allowing more current to pass through it. Now if this current falls below a set threshold then it turns on the transistor. and the output goes high, indicating that a white surface is detected.
To make a 3 bit scanner we need three pairs of IR led and IR diode. Each of the pair will detect the color beneath it and convert it into '0' or '1'. The IR led's turn on and off sequentially from right to left scanning the 3 bit pattern. All the IR diodes are connected in parallel between the base-emmiter junction, This means that only one diode is active at a given instant in time. The 3 bit serial data is the output of transistor, further fed to input pin of arduino.
To understand how the scanning works watch this video https://youtu.be/QbJD7wbRYcU
Circuit diagram:-
3 bit optical code scanner |
led[i] = {12,11,10}; is array of 3 elements where integer 'i' is used to address the location from where we want the data. for eg- led[0] = 12 , led[1] = 11.
byte x = 0b00000000; is also a 8 bit array , in which the bit can be changed by at any bit position by bitWrite(x,n,1) ;
where 'x' is binary number , 'n' is location of bit . n=0 is the rightmost bit .
Arduino code:-
int dpin=9;
int dpinst=0;
int led[]={12,11,10};
byte x=0b10000000;
int i=0;
byte p;
void setup() {
pinMode(dpin,INPUT);
pinMode(10,OUTPUT);
pinMode(11,OUTPUT);
pinMode(12,OUTPUT);
pinMode(7,OUTPUT);
pinMode(6,OUTPUT);
pinMode(5,OUTPUT);
Serial.begin(9600);
}
void loop() {
for(i=0;i<=3;i++){ // change is made here , i<=2 is changed to i<=3
digitalWrite(led[i],HIGH);
dpinst=digitalRead(dpin);
bitWrite(x,i-1,dpinst); // writing i-1 shifts the 3 bits to right by one bit .
delay(100);
digitalWrite(led[i],LOW);
}
Serial.println(x,BIN);
digitalWrite(7,bitRead(x,2));
digitalWrite(6,bitRead(x,1));
digitalWrite(5,bitRead(x,0));
}
Conclusion:-
This code can easily modified to make a 8 bit scanner and the number of pins required by Arduino will remain same . All you need to do is add a shift register 74HC595 in the scanning circuit.
This 8 bit scanner can also be made using IC's. It requires Op-amp IC 741, shift registers IC's(74HC595 & 74HC164), ring counter IC's, dual timer IC 556. below given is the circuit:-
Although this circuit requires a lot of wiring. Its worth it, as it will teach you about popular IC's used in digital electronics.
If you found this blog useful and want to support me, then you can donate me. The money you give will be used to make more advance electronics projects and setting up better lab.

Comments
Post a Comment