This week's assignment idea is a system that contains lighting system and study timer system, so we can focus on studying and take breaks with appropriate intervals. Or just turn it into a lamp 🙃
Used to simulait electrical circuit
Avometer
Breadboard
Arduino Uno
IR sensor
Jumper wires
lamp
Relay Module
Crocodile wires
LCD screen
Circuit Design
Circuit wiring:
IR sensor connected to pin 13 (Input sensor for motion)
LDR sensor connected to pin A0 (Input sensor for light)
Lamp represented by an LED and a resistor connected to pin 7 (Light output component)
Buzzer connected to pin 6 (sound output component)
lamp switch connected to pin 9 (on/off input component)
mode switch connected to pin 12 (Slider input component)
LCD connected SDA and SCL to A4 and A5 respectively (text output component)
1) Initial definitions / includes for the code
2) Setup lines for pins, serial monitor and lcd. And printing the word "Mode: " initially
3) First part of main loop, creating the slider condition where if HIGH goes to automatic mode, else in Manual lamp mode
4) Printing the mode text and reading ir value
5) If the sensor reads someone there it starts the timer loop, first setting the "Study time: " text
6) First for loop counting the study time, but i added conditions to be constantly checking sensor and switch readings
7) taking the LDR reading embedded inside the loop to be in real-time and lighting the lamp on/off
8) printing the timer value at this second on LCD so its visible
9) changing text on LCD screen to start break round
10) again checking for switch and IR sensor reading so the loop does not interrupt the program
11) checking LDR reading as well in case sensor reading changes Mid-loop
12) Finally printing timer value on LCD, and resetting the timers with initial values to start again
13) In case IR does not read someone, a buzzer will keep flashing until I am back to study. And the LDR sensor is still being read in case light changes
14) Finally, if the mode is switched to lamp, it basically turns into a desk lamp with an on/off switch
Note: the empty string line is to clear the LCD screen
Connecting 5v and ground to breadboard
connecting buzzer and slider using M-F jumpers
connecting sensors to their pins
connecting the LCD in place
connecting Relay module in Lamp pin
connecting Lamp by crocodiles to the Relay and the source converter, where the source (-ve) goes to CM and the (+ve) goes to Lamp and Lamp -ve goes to NO
connecting lamp switch by crocodiles to jumpers
Lamp tower using cardboard cylinder
Base design
Fixing main components on base
Side holes for power sources
Fixing side and back to the base
Fixing sensors and lcd on front and onto the base
Fixing lamp tower, buzzer and lamp switch to the top and closing assembly
Final look
When I tested the final project, it didn't work, after checking the code I found it correct so I knew it was a hardware issue.
After 10 mins of checking the wires using an Avometer, the ground wire connecting the Arduino to breadboard was not working🙂
So, I simply changed the wire, and all went well.