This week's assignment required us to create a circuit with two inputs (sensors) and two outputs, then write a text-based code (without using code blocks) and build an enclosure.
While researching, I found a flower-shaped lamp, which inspired me to add a light sensor. I also included an ultrasonic sensor just for fun—to display a sentence on the LCD.
For my project, I chose to use:
A light sensor to control a 9V lamp
An ultrasonic sensor to interact with an LCD display
Tinkercad: Used as a virtual software to build the circuit and test the code to avoid errors.
Breadboard: Used to place and connect various electronic components.
Arduino Uno: The microcontroller used to control the circuit.
Jumper Wires (Male-Male / Male-Female): Used to make electrical connections between components on the breadboard and other terminals.
9V Adapter: Regulates the voltage to 9V to protect the components.
Arduino Cable: Connects the Arduino to a PC for uploading code or powering the Arduino.
Arduino IDE: A software platform used for writing and uploading text-based code to the Arduino.
LCD: Displays messages based on sensor readings.
Relay Module: An electrically operated switch that allows control of high-power devices, such as a 9V lamp.
Cardboard: Used to create the enclosure for the circuit.
Glue Gun: Used to assemble and secure the enclosure.
Cutter: Used to cut the cardboard into the required shapes.
LDR (Light Sensor): Detects changes in light intensity.
Ultrasonic Sensor: Measures distance.
LCD: Displays a message when the ultrasonic sensor detects a specific distance.
Arduino Uno: Controls the entire circuit.
I used Tinkercad to test the circuit before building it physically, ensuring that no components would be damaged.
Steps:
Inserting Components:
I added the required components, including a breadboard, Arduino Uno, light sensor, 9V lamp, LCD, and ultrasonic sensor.
However, I faced an issue:
Tinkercad does not have a light sensor module or a relay module.
Wiring the Power Connections:
Connected VCC (5V) from the Arduino to the positive rail of the breadboard.
Connected GND from the Arduino to the negative rail of the breadboard.
Ultrasonic Sensor Wiring:
VCC → Positive rail
GND → Negative rail
Trigger Pin → Pin 3 on the Arduino
Echo Pin → Pin 4 on the Arduino
LCD Wiring (4 Pins):
VCC → Positive rail
GND → Negative rail
SDA → Pin A4 on the Arduino
SCL → Pin A5 on the Arduino
Light Sensor Wiring:
VCC → Positive rail
GND → Negative rail
Signal Pin → Pin A0 on the Arduino
Relay Module Issue:
Since Tinkercad does not have a relay module, I replaced the lamp with an LED for simulation purposes.
Breadboard and Component Setup:
Place the breadboard and components.
Connect the relay module:
VCC to 5V (positive)
GND to GND
Signal to digital pin 2 on the Arduino
Common ground to the same row as the adapter’s ground
Connect the lamp:
Attach the normally open (NO) terminal to one terminal of the lamp using a crocodile clip.
Connect the second terminal of the lamp to the positive rail of the adapter.
Connect the light sensor:
VCC to 5V on the Arduino
GND to GND on the Arduino
Signal to A0
Connect the ultrasonic sensor:
VCC to 5V on the Arduino
GND to GND on the Arduino
Trigger to pin 3
Echo to pin 4
Connect the LCD:
VCC to 5V on the Arduino
GND to GND on the Arduino
SDA to A4
SCL to A5
Connect the adapter to the breadboard and plug in the Arduino cable to upload the code.
Code Functionality:
The lamp should turn on when the light sensor reads a value greater than 940.
The LCD should display a specific message when the ultrasonic sensor detects a distance less than 20 cm.
If the distance is 20 cm or more, the LCD should display the measured distance.
Cardboard Enclosure:
Cut six sides to form a box.
Cut two holes—one for the ultrasonic sensor and one for the LCD.
Make a small hole for the light sensor and a designated space for the lamp.
Cut an opening at the back to pass the power cables.
Place the circuit inside and apply glue to all sides to assemble the box.
Attach a flower to the top for decoration.
0x27: The I2C address of the LCD.
20, 4: Specifies that the LCD has 20 columns and 4 rows.
The LDR sensor measures ambient light intensity. and connected to A0
The LED turns on or off based on the light sensor readings. led connected to digital pin 2
The ultrasonic sensor measures distance using the trigger connected to pin3 and echo connected to pin 4
in void setup i define each pin as input or output
lcd.init → Initializes the LCD.
lcd.backlight → Turns on the LCD backlight.
lcd.clear → Clears any previous display.
lcd.print("Welcome!") → Displays a welcome message for 2 seconds.
Serial.begin(9600): Starts serial communication
analogRead(LDRSensor): Reads the light sensor value (0-1023).
Serial.print(): Displays the sensor value in the Serial Monitor.
this condition called if condition
If the light sensor value is greater than 960, the LED turns on.
Otherwise, the LED turns off.
Print distance to Serial Monitor
Measure distance using the ultrasonic sensor
Title of Media
I didn't know the exact model of the LCD I had and wasn't sure about the correct code to make it work.
I asked one of my colleagues about the model and learned that it was an LCD I2C. Then, I searched for the appropriate library to use with it.
the Library called liquid crystal i2c
how i download the library
select tools / library and write liquid crystal i2c to search on it then download it
then go to examples and select liquid crystal i2c
Title of Media
Title of Media