Remote Control Light Switch Flicker
by CallMeSwal in Circuits > Raspberry Pi
4326 Views, 16 Favorites, 0 Comments
Remote Control Light Switch Flicker
![Robot that flicks light switch on and off](/proxy/?url=https://content.instructables.com/FL6/YMBM/I0TV5X91/FL6YMBMI0TV5X91.jpg&filename=Robot that flicks light switch on and off)
In this instructable we are going to be building a small robot, controlled wirelessly with an android phone, that flicks a light switch on and off.
The brains of the robot will be a Raspberry Pi. The Pi will be controlled by an android phone over an FTP server.
To use the android phone as a remote control we're going to be running python scripts on SL4A
Parts List
Parts
- 1 Raspberry Pi with raspbian installed
- 1 9v Battery Pack
- 1 Breadboard
- Wire
- Phone Charger
- 6v DC Motor and Motor Controller or Servo
- Lexxan or any material to make arm out of
Making the Arm
![Screenshot 2014-10-04 23.00.21.png](/proxy/?url=https://content.instructables.com/FA3/4VLJ/I0TV889P/FA34VLJI0TV889P.png&filename=Screenshot 2014-10-04 23.00.21.png)
![Screenshot 2014-10-04 23.00.33.png](/proxy/?url=https://content.instructables.com/FCE/R7SU/I0TV889R/FCER7SUI0TV889R.png&filename=Screenshot 2014-10-04 23.00.33.png)
![Screenshot 2014-10-04 23.00.39.png](/proxy/?url=https://content.instructables.com/FRL/3T0W/I0TV889S/FRL3T0WI0TV889S.png&filename=Screenshot 2014-10-04 23.00.39.png)
![2014-10-05 02.58.06.jpg](/proxy/?url=https://content.instructables.com/F4Z/TIS0/I0TV89FG/F4ZTIS0I0TV89FG.jpg&filename=2014-10-05 02.58.06.jpg)
First we need to make an arm which the motor can spin to make the light.
I made this piece out of lexxan.
It mates nicely with the GM8 motor.
The design of your arm is completely up to your creativity as long as its well secured to the motor.
Downloads
Wiring It Up
![2014-10-05 02.58.31.jpg](/proxy/?url=https://content.instructables.com/FMS/WCT5/I0TV89IL/FMSWCT5I0TV89IL.jpg&filename=2014-10-05 02.58.31.jpg)
![wiringSchematic.PNG](/proxy/?url=https://content.instructables.com/FQU/2GA7/I0TV8BB1/FQU2GA7I0TV8BB1.png&filename=wiringSchematic.PNG)
Mount the breadboard, battery pack, Raspberry Pi, and motor to a sheet of plastic or wood.
Wire up the motor, RPi, and battery like above.
Downloads
Programming the Pi
How is our phone going to communicate with the pi?
The pi will start an ftp server on boot.
The android phone will have an app that can write to a file on the ftp server.
The raspberry pi will read from this file and spin the motor based on the contents of the file.
To do this first boot up the pi
Copy the python program switchFlicker5.py into the /etc directory of the RPi
This program will read from a text file that our phone can write to. The program will then spin the motor based on the content of the file.
We now need a way for this program to run on boot.
We also need to start an ftp server on boot so the phone can communicate with the pi.
We do this by editing the RC.local file.
Open the file RC.local in Nano by:
- opening terminal
- CD to root
- CD to etc
- nano rc.local
now edit the RC.local file like this.
#!/bin/sh -e
sudo service proftpd status &
cd
sudo python switchFlicker5.py
_IP=$(hostname -I) || true
if[ "$_IP"]; then
printf "My IP address is $s\n" " S_IP"
fi
exit 0
Downloads
Setting Up the Phone
We now need a program on your phone that can write data to files on the raspberry pi's ftp server
We'll be doing this with SL4A.
Install SL4A from https://code.google.com/p/android-scripting/ on your android phone
Open the above file in a text editor and edit all the commented lines of code. (ip address, username, password, etc)
Add the file to your SL4A directory.
Test It Out
You're done!
Just power the pi, wait a minute for the pi to boot, and then run the python app.
The python app will ask you what you want to do. Say ON to turn the lights on, OFF to turn the lights off, and EXIT to stop.