How it Works - YollyLau/ECE387-Individual-Final GitHub Wiki
Circuit Building
Above is how I build the circuit. For the infrared receiver part, there are three pins. One is connected to Vcc, the middle one is connected to GND and the thrid one is connected to Arduino pin 11.
The photo-resistor and the 10K Ohm resistor form a potential divider此处链接回照片. A wire is connected from positive pole of the photo-resistor to analog input 0 on the Arduino board. We know the Arduino's analog to digital converters (ADCs) can map input voltages between 0 and 5 volts into integer values between 0 and 1023. So by analog input 0, the voltage value on the photo-resistor as well as the parameter of anti-theft function code can be read from 0 to 1023.
For the buzzer, a wire is connected from its positive pole to Arduino pin 8. For the LED, a wire is connected from its positive pole to Arduino pin 13.
Flow Diagram
Explanation about the above diagram: At the beginning, define a flag bit and initialize it to be 0. Once the infrared receiver receives infrared code, determine if this infrared code matches the turn on/turn off code sent from the controller. If it does, then flip the flag bit. If not, keep receiving next infrared code and do the determination again. Next, determine if the flag bit is 0. No matter it is 0 or not, flip the flag bit and then determine if it is 1. If not, turn off the buzzer and LED and then go back to the beginning to receive the infrared code. If it is 1, read the voltage value on the photo-resistor by analog input 0 and put this value(parameter) into anti-theft function to work. When the value goes into the anti-theft function, determine if this value is less than 1023, which is the biggest value on photo-resistor when in the dark environment. If not, keep receiving the new value sent from the analog input 0. If it is, turn on the buzzer and let it sound as sinusoidal wave. In the same time, LED will blink in the same way. After that, the program will go back to the very beginning and tart over again.