Introduction: DIY Smart Lamp
Hello everyone!!
I have a lamp in my table. But sometimes when i finish my work i forgot to turn it off, or even when i much focused on my book and keep reading almost in the dark.
So i imegine: How cool would be if the lamp whach me and turn on for it self??
In this tutorial i will show you how i made my lamp more "inteligent" using arduino and other few components!
Step 1: Components and Tools
To make this project you will need:
- Arduino Uno (or any other)
- Ultrasonic sensor HC-SR04
- Photoresistor
- 10k ohm resistor
- Relay module
- some wires
- 2 AC female plug
- 1 AC male plug
Some tools, and of course: A lamp!
Step 2: Desing and Simulate the Circuit
Before start cutting the wires and gluing the componensts is important to draw your circuit and simulate it to see if there nothing missing.
To simulate this simple desing i used ThinkerCad. ThinkerCad is a online and free software that you can do 3D desing and program your arduino even if you don`t have one. Go in the link below to see the wiring and simulate the desing!
Step 3: Wiring
After run the simulation and see that the the dising works well, is time o wire the parts all together!
Start taking some measures! I cuted a 1m wire in a piece of 80 cm and other of 20cm. Later i realize that tha small piece was to short!
After cuting the wires and strip the ends, join the to pieces together and screw them on a AC male plug.
Screw the AC felame plugs on the other tips!
The lamp will be connecten in the end of the smaller wire, and the longer will be used to power the arduino in their secret compartment.
Step 4: Conect the Relay
After connect the AC plus, cut one way on the smaller wire to connect the relay. Cut, strip the ends and screw it on the relay module.
Here goes a tip: The relay has a "com" (comum) terminal, a NO (Normaly Open) and a NC (Normaly Close) terminal. On path of the wire must be connected in a "com" terminal, and the other path in a "NO" terminal. If yor lamp is behaving contrary to what you want, you can change it on the code, or change the position of the wires.
Carreful: the relays are in high voltage.
Make sure that they are unpluged before make any change.
Step 5: Wiring the Components
Lets prepare the connection between the arduino and the sensors!!
Get electronic components in my city isn't a easy task. So i dont like to solder direct on them. To keep my componensts clean and free to dissassembly and use in another project i soldered a pice of thin wires in a pin connector, and pluged on the ultrasonic sensor, the relay module and the photoresistor. For the arduino i used a breadboard. But if you use a Arduino UNO it will not be necessary.
Step 6: Placing the Sensor in Place
After prepare the AC wire and the Sensor connection is time to find a place to hide your circuit.
The realy i hided below my shelv.
The ulltrassonic sensor i glued below my monitor.
And the photoresistor i taped on the Wall.
Step 7: Connectiong the Sensor With Arduino on the Breadboard
Follow the diagram above to connect your sensors correctly.
Be carefull to not change any VCC with GND and cause a short circuit in your desing!
Step 8: Upload the Code
For this project you will need the "Ultrassonic.h" library. To download it, go to: https://github.com/filipeflop/Ultrasonic. Download and add it on Arduino IDE.
- If you never used Arduino before, or dont know to add a library, search on the internet about it. Instructables has awsome tutorials about it.
After that, download the "DIY_LAMP_CODE" here, open the Arduino IDE, compile and upload the code to your Arduino.
Attachments
Step 9: Try and Configure Your Code
After uplod the code, connect the lamp to the relay AC plug and power it! Your lamp is almost smart, now you must configure your code to your enviroment.
For that, open the Arduino serial and read the "distance" and "bright" value displayed. On the first lines of your code change the "MAX_DISTANCE" for grater value if you want to increse the sensive area, or for small value if you want to decrease the Area.
And change the "MAX_BRIGHT" if you want a lighter or darker enviroment.
When finished, unplug your arduino uno from the PC. Hide it and power it using a old cellphone charger.
Step 10: Connect Your Lamp and Be Happy!
Its done! Now, every time that is dark and i sit in my chair the light turn up automaticaly. And when i get up and go way it turn off.
Thank you for read untill here! this is my first Instructable and i hope that it have inspired you. This is a very simple project but requires a lot of skills, solder, programing, solving problems....
The relay module can be used to turn on/off any high voltage AC device. So if you want to atomate a lamp, a radio or even a electric motor you can use this idea as a start point. And if you tried this desing, maybe as me you will realize that the ultrassonic sensor is not the best one for this (it has some isntabilities), maybe a IR sensor will be better, but it is for a next espisode.
If you have an idea to automate something, please leave on the comments. Thank you all!