Theme: - Smart Lamp and fan that makes life easier.
I had a problem that I need to move to turn on the light when it's dark or at night and also the fan when it gets hot, so I was inspired by smart lamps, and I adapted the idea to include a ultrasonic sensor that turns on the light and another one to activate the fan when the temperature rises.
This system makes the room brighter and cooler without requiring manual control as it works automatically.
Programs
Fritzing app
Arduino IDE
Material Kits
Breadboard
Jumper wires
Bulb
Arduino Uno
DHT sensor
Fan
Ultrasonic sensor
USB Electric Arduino cable
2 Channel Relays Module RM1v
DC Power Jack Adaptor/ Rosetta
Crocodile wires
5 & 9 adaptors
Glue gun
Cardboard
Razor knife
Searching
While exploring ideas to decorate the desk, I came across a desk organizer that can hold items like phones and pens. I decided to use this concept and modify it to create a smart version
Connecting Ultrasonic and write its code.
1- I downloaded fritzing app.
2- I used the breadboard, Arduino, ultrasonic and downloaded the other components then import them to be able to use them.
2- I connected the Echo pin to pin 2, the Trig pin to pin 3 on the Arduino and ground and VCC to breadboard.
3- I repeated the setup with the real kit by connecting the trig to pin 3 and the echo to pin 2.
3- I researched how to use the ultrasonic sensor and found that it requires a library, so I installed the NewPing library in the Arduino IDE.
4- From the Arduino IDE, I opened File → Examples → NewPing → NewPingExample, then edited the code to set Echo = 2 and Trig = 3 and added Serial.begin(9600);
6- Verify the code then download it on the Arduino.
7- I checked the sensor’s readings through the Serial Monitor by moving my hands forward and backwards.
Fritzing wiring
Connecting the bulb with the Relay Module and write the code
1- Open File → Examples → Control → If statement conditional.
2- Copy the if condition code and past it in the Void loop.
3- Edit the name of the Led to be Relay _Pin & distance to be 100cm
4- Define the Relay at the pre setup as Relay_Pin.
5- Write Relay _Pin mode as output in the Void set up.
6- Edit the if condition and the name of the Relay Pin in the void.
7- Verify the code then download it on the Arduino.
8- The code successfully operated both the sensor and the bulb.
Connecting the MDT sensor with Arduino.
1- Open File → Examples → DHT sensor Library → DHT tester.
2- Edit the DHTpin to be 8.
3- Edit type of the sensor to be 11 instead of 22.
4- Verify the code then download it on the Arduino.
5- Run the code while viewing the Serial Monitor and vary the heat to observe the increase in temperature.
Connecting the MDT sensor with Fan and Arduino.
1- Set Fan_pin to pin 9 in the initial setup.
2- Add a pinMode declaration to configure Fan_pin as an output.
3- Copy if condition as done in the distance so that when the temperature exceeds 30°C, the fan turns on.
4- Choose serial monitor and verify the code.
5- Upload the code to Arduino and test it and works as if conditions.
Actual wiring.
1- I connect the relay with same pins on Arduino In pin to 9 & VR to 5v then connecting it first to breadboard.
2- Connect the common pin of relay of with negative power supply.
3- No pin to the negative of the fan and GND to negative part in the rail.
4- Positive of the fan to the positive power supply.
5- Connect the DHT Data pin with pin 8 in Arduino then GND to the negative rail of bread board then VCC to positive rail that is connected to 5v in the Arduino.
6- Connect the common pin of relay of with negative power supply.
7- On to any of the sides of the bulb as it is bipolar.
8- Connect ultrasonic sensor to the Arduino and breadboard with the mentioned pins.
9- upload the code from Arduino and check working.
Downloading NewPing
Use Ultrasonic sensor
Check sensing the distance with ultrasonic
Testing the code for Ultrasonic sensor
If conditional statement
If conditional statement
Opening DHT sensor
Changing pins and type of DHT
Testing DHT sensor only
Connect the ultrasonic
Connect the DHT sensor.
Connect all components and test them with power supply.
Connect fan with DHT sensor
Wiring ultrasonic with bulb.
Wiring all componenst with ardunino.
Testing DHT with all code with distance and temperature
Testing code with real kit
Real Fan and DHT
Pre setup, Defining
Void setup
Void Loop
IF condition
Final outcome front face
Final outcome side face
1- Begin by cutting the base of the smart lamp and creating openings for the ultrasonic sensor, DHT sensor, and fan.
2- Shape the middle section of the lamp, which will hold the light bulb.
3- Cut the top part for the upper bulb and add holes to allow light to pass through.
4- Assemble all the parts together using glue, leaving the base open until the electrical connections are tested.
5- Test the connection again before closing the prototype.
6- Finally, close and secure the base.
7- Testing the smart lamp again and it works successfully.
My challenge was, the temperature wasn’t displaying correctly, so I consulted my colleagues, and they pointed out that I needed to use Serial.print as done with distance (ultrasonic sensor) in order for the temperature to appear.
Solution: -
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" °C");
1- The first issue I faced while uploading the code because it showed an error that Pincode was not declared. After reviewing the code, I realized that the letter P was capitalized instead of lowercase. Once I corrected it with writing it p, the code uploaded successfully. (shown below)
2- Second challenge was, the temperature wasn’t displaying correctly, so I consulted my colleagues, and they pointed out that I needed to use Serial.print in order for the temperature to appear.
Solution: -
Serial.print("Temperature: ");
Serial.print(t);
Serial.println(" °C");
3- I was not able to find relay module on tinker Cad and my colleague advised me to download fritzing app and import the components I need to be used in the connections.
Before
After
Before
Solution
After
The tasks I completed this week will greatly support my final project, especially in linking the DHT sensor and fan to the Arduino and writing the appropriate code for them, since they are an essential part of the laptop’s cooling system.
I really enjoyed successfully connecting the DHT sensor to the fan and seeing the fan activate when the temperature went above 30°C.
This week assignment is useful because my final solution involves connecting a fan to a temperature sensor to reduce high temperature and I might use multiple fans to improve heat reduction.