Introduction: Arduino/Android Timer (with App!).Control Your Lights and Other Stuff
Hi! Here i am with another timer. With this project you can set if the timer will be "ON" or "OFF" for every hour of the day . You can set more than one event at day by using the android app. By combining Arduino and Android we can "skip" the complex circuitry, so we do not need lcd, buttons ,etc, . You only need to select which hour you want "ON" or "OFF" on your phone or tablet.
Programming is via bluetooth. Once you have programmed the timer, you can disconnect the phone. The system keeps the settings(unless you turn off the arduino) .If you connect again, the system will "map" the previous state of buttons.
This project is aimed to control lights, but you can use it in many other applications.
Things you will need:
-Arduino UNO
-RTC 1307 module
-HC-06 Bluetooth module
-5V relay module
-Plastic box
-12V adapter (suitable for arduino)
-Any Arduino prototype shield
-Android phone or tablet
-Soldering iron, solder wire
-Pin headers
-Wires
-AC plug and socket
Watch the video! Use it as a guide.
Step 1: The Shield
We need to make a compact circuit to hold the modules and save space. A prototype shield is a good choice.Follow the wiring guide and solder the pin headers and sockets . Be careful if your modules doesn't has the same pins arrangement.
Arduino to modules:
A4 to SDA RTC
A5 to SCL RTC
Pin-10 to bluetooth TX
Pin-11 to bluetooth RX
Pin.13 to Relay S
GND and VCC(5V) , respectively.
You can adapt the circuit according to your needs.
Mount the shield and connect the modules.
NOTE: The next steps need the shield and the modules connected. Upload and run the codes whith the shield mounted.
Step 2: Setting the Time(RTC)
Now we have to set the clock.Use the Adafruit code. Run the code "Set time RTC". This sketch take the Date and Time according the computer you're using (right when you compile the code) and uses that to program the RTC. If your computer time is not set right you should fix that first. Then you must press the Upload button to compile and then immediately upload.
Warning !: If you compile and then upload later, the clock will be off by that amount of time.
Then open up the Serial monitor window to show that the time has been set.
More info here (Using the real time clock ):
https://cdn-learn.adafruit.com/downloads/pdf/adafruit-data-logger-shield.pdf
Attachments
Step 3: Changing Bluetooth Baud Rate (optional)
Follow this guide to change the baud rate if you want ,but use my code(below) , adapted to this circuit. Do not change the pins or connections. Skip step 1 and 2. Start from step 3.
http://42bots.com/tutorials/hc-06-bluetooth-module...
Do not forget to change the baud rate here:
void setup() {
BT.begin(115200); // or 9600 if you don´t have changed baud rate
9600 is the default baud rate of HC-06 (normally). I really don´t know how much affect this, because i already had the baud rate at 115200 (of course that 115200 is faster than 9600).
Attachments
Step 4: App + Arduino Code
The app was made with MIT app inventor. This is my first app!.
The app sends a text when you click a button and arduino receives the text and sets the state of the button(HIGH or LOW). The buttons works as "toggle" , so you do not need to select between on and off (as many apps). Then, arduino sends another text to change the colour of the button. So, the colour of buttons are given by arduino and not by the app. This function allows you to disconnect android and when reconnect, the system will send the previous settings. The RTC controls the time. Switch funtion compare ,hour by hour, the state of button (HIGH or LOW) and turn on or off the relay.
For example: 0 hour
(App) Click 0 (red) > Send "a" >
(Arduino) Receive "a" > Change state_0 to HIGH > if state_0==HIGH > Send "aa" to App >
Switch Case 0: if state_0==HIGH > Relay ON
(App) Receive "aa" > Change colour to green
Click again:
(App) Click 0 (green) > Send "a" >
(Arduino) Receive "a" > Change state_0 to LOW > if state_0==LOW > Send "ab" to App >
Switch Case 0: if state_0==LOW > Relay OFF
(App) Receive "ab" > Change colour to red
Maybe the system is a little bit slow , but it is stable and you never lose a state.
You can see the app and modify what you want, or use it for another project
ai2.appinventor.mit.edu/?galleryId=6319497148628992
Step 5: The Box
WARNING: Be careful with the high voltage!
Use a suitable box for the components. Fix the modules and arduino board to the box , to avoid "floating"components inside the box. I have used some spacers.
You need to interrupt one line using the relay "COM" and "NO". See the schematic. The length of the cord depends on you application.
NOTE: i am using the RTC from the datalogger shield (it is the same). With the RTC 1307 module you can save space, or mount it on the prototype shield (i am using the rtc on other running project)
You can make the box according to your needs, following this guide.
Step 6: Using the Timer
Upload the code "Arduino Android Timer"
Turn on the bluetooth on your android device.Follow the steps as any other bluetooth device.The first state of buttons are grey(not connected). The HC-06 has a led that blinks when not connected , click on "Bluetooth" to stablish a connection. If the connection is made, the led will be on. Give a few seconds to "map" the state of buttons.
You can schedule more than one event per day ,for example: 0 to 3 ;8 to 13; 16 to 22, etc.
Plug your lamp. Now select which hour you want ON (green) or OFF (red), and that´s all ! . You can program your timer to your house lights are on when you get home in the afternoon.
Remember that the app it is just for programming. Once you did that, you can disconnect the phone or tablet, and the system will keep settings, untill you change the settings or turn off the arduino. If you connect again, arduino will send you the state of buttons.
The app was tested on android 4.2.2 and 5.1.
Like i have said, this project have many applications , that depends on you!