On Day 2, our task is to tinker our circuit on Tinkercad and simulate it.
The modes proposed based on the range of potentiometer :
1- Manual Mode:
The low range of potentiometer >> Manual Turn Off to Lamp
The high range of potentiometer >> Manual Turn On to Lamp
2- Automatic Mode:
The middle range of the potentiometer, the automatic mode will be on with the LDR sensor.
Smart Bob
Simulating the circuit.
Mini Mini Breadboard
Arduino Uno
LDR sensor module
Adaptor 9v
On/Off Switch
Relay Module 5v 1channel
Potentiometer
Halogen Bulb
Input:
Potentiometer, LDR sensor
Output:
Relay module which controls a DC Bulb
States:
1) Manual >> OFF
2) Manual >> ON
3) Automatic
Journey:
Power is ON through the Rocker switch
Relay is OFF
Check Potentiometer Reading
Condition 1: Potentiometer 0-1 minimum
Manual Mode to make the lamp OFF
Set Relay off thus Lamp off
Condition 2: Potentiometer 4-5 maximum
Manual Mode to make the lamp ON
Relay ON thus lamp is on
Condition 3: Potentiometer greater than 1 and less than 4
Automatic Mode
Start reading LDR signals (Analog)
Case of Low values, bright atmosphere
Relay off this lamp is off
Case of High values, dark atmosphere
Relay on thus lamp is on
Algorithm Drafting
The first steps include:
The 9v 2A power supply (function generator).
Slide Switch to control powering the circuit (open/close) as a simulation for ON/OFF switch.
Mini Breadboard.
Connecting the main power rails giving the 9v an orange color Positive & Negative
Insert Arduino Uno and connect common GND and 5v as shown.
Potentiometer || Arduino connections
Pin 1 >> GND
Pin 2 >> A0
Pin 3 >> 5v
LDR Sensor || Arduino connections
GND >> GND
Out >> D4
VCC >> 5v
Note: choose PIR sensor on Tinkercad as the LDR sensor (to make a simulation)
Relay Connections "Tricky"
T1 >> 5v
T6 >> GND
T5 >> D5
T7 >> 9v
Bulb Connections
Pin1 >> GND
Pin2 >> T8 in Relay
The logic as shown consists of 3 if conditions and one else.
First condition is reading step 0 or step 1 from potentiometer which acts as OFF Manual Mode
Second condition is reading step 4 or step 5 from potentiometer which acts as ON Manual Mode
Third condition is reading in between steps 2 or 3 from potentiometer which lead to highlighting LDR readings
Case when LDR readings are 1, then environment is dark, thus the bulb will be On
Case when LDR readings are 0, then environment is bright, thus the bulb will be Off
Potentiometer || Arduino connections
first Pin 1 >> GND
middle Pin 2 >> A0
last Pin 3 >> 5v
Define the potentiometer as an integer variable pot
Using serial to show the value from the potentiometer
Store the values from the pot in integer variable val, then show this val.
To convert this large range of numbers to a small range
, use the map function
Showing values after map function
Relay Connections "First side"
VIN >> 5v
GND >> GND
IN >> D5
Bulb Connections
Pin1 >> + 9V
Pin2 >> NO in Relay
Relay Connections "Second side"
NO >> To bulb
Com >> - 9V
To power the Arduino
Get 2 jumpers from the adapter
+ 9V >> VIN
- 9V >> GND
The First condition is reading step 0 or step 1 from the potentiometer which acts as OFF Manual Mode
The Second condition is reading step 4 or step 5 from the potentiometer which acts as ON Manual Mode
Testing of Manual mode
LDR Sensor || Arduino connections
Out >> D4
GND >> GND
VCC >> 5v
Third condition is reading in between steps 2 or 3 from potentiometer which lead to highlighting LDR readings
Case when LDR readings are 0, then environment is bright, thus the bulb will be Off
Case when LDR readings are 1, then environment is dark, thus the bulb will be On
Testing of Automatic mode
Add the switch to the circuit
on side of the switch >> + 9V
the other side of the switch >> VIN
Testing of Manual & Automatic mode
Challenge here is avoiding feedback loop between the LDR sensor readings with changing states.
When LDR senses darkness, lamp is on, then LDR senses brightness coming from the lamp itself, lamp is off and so on
Here we decided to fix it on the hardware fixation.
The Lamp is mounted with an enclosure away or in opposite side away from the LDR sensor, so the lamp's light won't affect the LDR.
At first we were using IR sensor on tinker CAD for simulating LDR sensor >> but we got confused and used the IR that needs a remote.
1 Channel Relay on Tinker CAD was a bit challenging and the result of our searching were not accurate and even different from one source to another, but Sherif, the Lecturer, was very helpful in that point and gave us hints to wire it correctly.
IR sensor and remote
PIR sensor