This journal will be used to document the construction of our lamp's circuit on Tinkercad, as well as the writing of its pseudocode and the code itself.
Our lamp has only one mode: automatic. Using an LDR sensor, the light will turn on when the surroundings are dark and off when the surroundings are lit up.
Note pad
we used it to write the pseudo code
TinkerCad
We used it to connect and simulate our circuit.
Arduino IDE
We used it to write the code.
Electronics Components
We decided on the components we're going to use, which are:
Arduino Uno
Relay module
halogen bulb
9V adaptor
LDR moule
Jumper wires
Small breadboard
DC connector
On/Off switch
Crocodile jumber wires
After we decided which components we wanted to use, we started to write the pseudocode, as shown on the left.
Then we started to simulate our circuit on TinerCad
Connect the positive terminal of the power source to the breadboard to form a 9-volt rail with yellow color wires.
Cut the negative terminal of the power source through the ON/OFF switch and then connect it to the breadboard to form a GND rail with black color.
Connect the 5V of the Arduino to the breadboard to form a 5V rail with a red color.
Connect the GND of the Arduino to the breadboard and Made a common ground
Power the Arduino through the Vin with the 9 volts.
LDR module connection on Tinkercad
Connected the LDR sensor to the GND and 5V of the Arduino and the digital signal to pin 3.
Note:
We used a photoresistor and a 10K ohm resistor in a voltage divider circuit to simulate the LDR module.
Relay connection on TinkerCad
Connect terminal 12 to the common ground.
Connect terminal 9 to pin 13 in the Arduino.
Lamp connection on TinkerCad
Connect one terminal of the lamp to the 9-volt rail directly.
Connect the other terminal of the lamp to the common ground as follows
Connect it to terminal 6 of the relay, then connect terminal 5 of the relay to the common ground.
Here is the simulation
Then we started to translate our pseudo code to code blocks on TinkerCad
Brought all the components and started to connect the circuit
At first, we wanted to determine the positive and negative terminals of the DC power connector because it has three terminals, so we connected the connector to the 9-volt adapter and started to measure the voltage across every two terminals using the Avometer until the volt showed up, so the terminal connected to the red probe of the Avometer is positive and the other is negative.
We had three black and one white terminated jumpers, so we connected the positive terminal of the connector to the white one and the negative to one of the black ones.
We connected the two black ones to the ON/OFF switch so that now we can cut the negative terminal with the ON/OFF switch.
Note
We had to slightly expand the metal terminal in order for it to fit on the ON/OFF switch terminals.
We soldered two wires to the lamp's terminals and connected the ends with male-ended jumpers to use it.
We connected the LDR with female-male jumpers as follows:
Vcc : Red
GND: Brown
D0: Orange
The Relay was linked to male-male jumpers as follows:
Vin : Yellow
GND: Blue
IN: Green
and female-male jumpers as follows :
NO : Red
CM: Orange
Powering the circuit
We added a female-female black jumper to connect the negative terminal (Connector + ON/OFF switch) because the terminated jumpers were all male ends.
We connect the white wire to the breadboard to form a positive 9-volt rail.
and the black wire to the breadboard to form the GND rail.
Connect the 5V of the Arduino to the breadboard to form a 5V rail with a red color.
Connect the GND of the Arduino to the breadboard
Power the Arduino through the Vin with the 9 volts with a white wire.
Made a common ground with grey wire
Connecting the LDR module with Arduino
Vcc : Red to the 5V rail
GND: Brown common ground to the
D0: Orange to pin 3
Connecting the Lamp with the Arduino
Connecting the Lamp with the Relay module
NO: Red to one terminal of the lamp
CM: Orange to RED male-male jumper
note:
Here we cut the positive terminal of the Lamp
Now we have a Red terminal and a blue one.
Connecting the Relay module with Arduino
Vin: Yellow to the 5v rail
GND: Blue to the common ground
IN: Green to pin 13
Connect the Red terminal to the 9-volt rail
connect the Blue terminal to the common ground
AAAAnd we are done.
we connected the Arduino with the USB cabel to the laptop to upload the code
We select blocks and code from the TinkerCad website.
We went to the Arduino IDE now that we had our code to burn on Arduino.
Here is the final result
The challenge we faced was that we had to deal with the relay, not the relay module. We asked Google and found this project.
TinkerCad Tutorial #2 Arduino Relay Activated Lamp - Blog - Arduino Projects - element14 Community
it helped us to get to know how to wire the relay properly
Another challenge we had is that after mounting the LDR on the lamp's body, it read LOW (it is dark outside) all the time, and we had to apply a direct light to it to make it sense the light.
So I changed the digital input to the analog input, connecting the A0 of the LDR sensor to the A0 of the Arduino, and changed the code after printing the readings of the sensor in the dark and in light and setting conditions accordingly.
Here the sensor readings in the light were from 700 to 805
and in the dark was above 1000