PROJECT Nº 3: Anti-theft alarm

Create a program so that the Code&Drive makes a sound and turns its lights on when picking it up from a table or any other white surface, simulating an anti-theft alarm. On the contrary, when the line follower sensors detect the infrared light reflected on the white surface, the buzzer won´t make any sound and the LEDs will remain off.

DIFFICULTY LEVEL: Beginner.

DURATION OF THE EXERCISE:  30 min.

MATERIALS:

  • 1 Green LED
  • 1 Red LED
  • 1 Buzzer
  • 2 Line-follower Sensors
  • Computer

The Code&Drive will have to be built according to the instructions manual.

What is a line follower sensor?

A line follower sensor of infrared sensor is a device that emits infrared light and detects the amount of light reflected. It is capable of distinguishing black from white.

There are many types of infrared sensors. The TV control remote and the objects detection are some of them.

CONNECTIONS:

  1. Connect the LEDs to the digital pins “9” and “10”
  2. Connect the buzzer to the digital pin “8”
  3. Connect the line-followers to the digital pins “2” and “3”.

PROGRAMMING CODE

You can do this project using the Arduino, Bitbloq and other visual programming software by blocks compatible. Below you will find the necessary code.

Arduino Code

  1. Download and install the Arduino IDE program. It is available for Windows, Mac OS and Linux.
  2. Open the Arduino program and copy the following program in it:
    int PinSpeedMotorA = 5, PinSpeedMotorB = 6; // DIGITAL PIN DIGITAL FOR THE MOTORS SPEED
    int PinBW1 = 2, PinBW2 = 3, ValueBW1 = 0, ValueBW2 = 0;
    int PinLED1 = 9, PinLED2 = 10; // DIGITAL PINS LED1 AND LED2
    int PinBuzzer = 8; // BUZZER DIGITAL PIN
    
    void setup() {
      // put your setup code here, to run once:
      // DIGITAL PINT CONFIGURATION
      pinMode(PinSpeedMotorA, OUTPUT);
      pinMode(PinSpeedMotorB, OUTPUT);
      pinMode(PinBW1, INPUT);
      pinMode(PinBW2, INPUT);
      pinMode(PinLED1, OUTPUT);
      pinMode(PinLED2, OUTPUT);
      pinMode(PinBuzzer, OUTPUT);
      // MOTORS SPEED A 0
      analogWrite(PinSpeedMotorA, 0);
      analogWrite(PinSpeedMotorB, 0);
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      ValueBW1 = digitalRead(PinBW1); //READING OF THE BLACK AND WHITE SENSOR 1
      ValueBW2 = digitalRead(PinBW2); // READING OF THE BLACK AND WHITE SENSOR 2
      if ((ValueBW1==0)&&(ValueBW2==0)) // IF THE VALUE OF THE TWO BLACK AND WHITE SENSORS IS 0
      {
        digitalWrite(PinLED1,HIGH); //LED1 = ON
        digitalWrite(PinLED2,HIGH); //LED2 = ON
        tone(PinBuzzer, 600); // BUZZER TONE    
      }
      else // IF THE VALUE OF THE TWO BLACK AND WHITE SENSORS IS NOT 0
      {
        noTone(PinBuzzer); // BUZZER OFF
        digitalWrite(PinLED1,LOW); // LED1 = OFF
        digitalWrite(PinLED2,LOW); // LED2 = OFF
      }
    }
    
  3. Configure and upload the code, following the indications on the Code&Drive First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

Code for the visual programming software by blocks compatible

  1. Download and install the program.
  2. Open the software and copy the following code. Use the following image as a guide:
  3. Configure and upload the code, following the indications on the Code&Drive First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

Bitbloq code 

  1. Download Bitbloq and install the Web2board app.
  2. Open the software and copy the following code:
    • Hardware
    • Software
  3. Configure and upload the code, following the indications on the Code&Drive First Steps guide.
  4. Check that the BTL/USB switch on the Build&Code 4in1 board is set to USB, to upload the code correctly.

RESULT OF THE EXERCISE

When picking up the Code&Drive from the table or any white surface, the buzzer will make a sound and the LEDs will turn on, simulating an anti-theft alarm. When putting the Code&Drive on the table or white surface, the buzzer will stop the sound and the LEDs will turn off.

1 0

0