Controlling the relay using a motion sensor
A simple way to detect motion is using a PIR sensor. This sensor measures infrared light radiation emitted by the objects in its range. By detecting changes in the amount of radiation, it can detect motion.
Note
Before starting to do the changes in the circuit, disconnect your AC plug from the wall socket.
Using the relay circuit from the previous step and having the AC plug disconnected from the socket, add the following connections:
Your PIR sensor should have three pins. Be sure to connect its VCC pin to the Galileo's 5 V pin, the GND pin to the Galileo's ground, and the OUT pin to the Galileo's pin 2. Whenever the sensor detects motion, we'll be able to read the value HIGH on the Galileo's pin 2. When the sensor stops detecting, we'll be able to read LOW.
Open the Arduino IDE, power on your Galileo (just the Galileo, not the lightbulb plug), and upload the following code...