Summer Camp: Internet of Things.

 

Arduino Motion Sensor Guide

This page is a guide on how to set up the code and arduino board to make a motion sensor that wakes up a laptop. Once it is set up, if your laptop is asleep and you move close to it, your laptop should wake up.

  1. Open Arduino IDE and copy this into it. Go to tools, boards and select Arduino Micro or Arduino Pro.
  2. #include <Keyboard.h>
    int sensorPin = 10;
    int RXLED = 17;
    static bool sensor_previous_state = false;
    void setup()
    {
       Serial.begin(9600);
       pinMode(sensorPin, INPUT);
       pinMode(RXLED, OUTPUT);
       digitalWrite(RXLED, HIGH);
       TXLED0;
       sensor_previous_state = digitalRead(sensorPin);
    }
    void loop()
    {
       bool sensor_current_state = digitalRead(sensorPin);
       if ( sensor_previous_state == false
        && sensor_current_state == true) {
        digitalWrite(RXLED, LOW);
        USBDevice.wakeupHost();
        Keyboard.press( KEY_CAPS_LOCK );
        Keyboard.release( KEY_CAPS_LOCK );
        delay(50);
        Keyboard.press( KEY_CAPS_LOCK );
        Keyboard.release( KEY_CAPS_LOCK );
        TXLED0;
        delay(1000);
       } else {
        digitalWrite(RXLED, HIGH);
        TXLED0;
       }
       Serial.println(sensor_current_state);
       delay(1000);
       sensor_previous_state = sensor_current_state;
    }
  3. Connect your Arduino Micro to your computer with a usb cable.
  4. In the Arduino IDE go to tools, port and select the port that shows up.
  5. Connect sensor to Arduino Micro using breadboard. Connect Ground on Arduino Micro to Ground on motion sensor. Connect RAW on Arduino Micro to VCC on motion sensor. Connect 10 on Arduino Micro to out on motion sensor.
  6. Go to Arduino IDE and press upload at the top.

Now you should have an Arduino board connected to your computer and connected to a motion sensor. And the code should be uploaded to the board. Now if the computer sleeps and you go near it, the computer will wake up.

Reference Links: Similar Guide

« Previous