REED SWITCH IN NON-CONTACT DETECTION
Tasks:
- Add a reed switch to the front of the barrier gate to detect the car.
- Connect the reed switch to the input pin A1 an GND.
{#fig:reed_sw}
- Write program as such that the gate barrier will open if car is detected. Some hints are showv in nex example code:
const int MOTOR_PIN_1 = 7;
const int MOTOR_PIN_2 = 6;
const int REED_SW_PIN = A1;
[-] void setup() {
pinMode(MOTOR_PIN_1, OUTPUT); //declaration of I/O pins
pinMode(MOTOR_PIN_2, OUTPUT);
pinMode(REED_SW_PIN, INPUT_PULLUP);
}
[-] void loop() {
bool car_is_detected = !digitalRead(REED_SW_PIN);
if (car_is_detected){
moveGateUp();
delay(3000);
moveGateDown();
}
}
[+] void stopTheGate(){
[+] void moveGateUp() {
[+] void moveGateDown() {
Questions:
- What is pull-up resistor?
- How can we turn on the internal pull-up resistor of the microcontroller?
Summary:
<++>
<++>
Issues:
<++>
<++>