This week's assignment is to build and program a smart device using an Arduino UNO that perform a certain function and read signals from multiple input components to control multiple action components using text code
I decided to implement part from my final project idea, and used a Potentiometer (input) to control Servo motor motion (output), and a LDR sensor (input) to control DC lamp (output).
TinkerCad
I used Tinkercad to build and test the circuit connections and ensure everything was functional before installation.
Material used in Tinkercad
1 Breadboard
1 Arduino UNO
1 Servo motor
1 PIR sensor (Simulaties LDR Light Sensor)
1 Potentiometer
Materials for the device's enclosure
I used Cardboard, Glue gun, tape, cutter
Materials for electric circuit
1 Breadboard
1 Arduino UNO
1 Servo motor
1 LDR Sensor
Wires
1 potentiometer
9V adaptar
I used Tinkercad to build and test the circuit connections, ensuring everything was functional.
I connected the 5V from the Arduino to the positive rail on the breadboard.
Connect the GND from the Arduino to the negative rail on the breadboard
connect the servo motor's ground to the Arduino's GND and its power to the positive rail on the breadboard, with the signal pin connected to Digital Pin 9.
For the PIR sensor, I used the same connections as the servo, with the signal pin connected to Digital Pin 2 on the Arduino.
Connect the potentiometer's ground to the breadboard's GND and its power to the positive rail on the breadboard, with the signal pin connected to Analog Pin A0.
Connections
For the code, I used text-based coding. I followed the 'baby steps' method, working incrementally to ensure each part functioned correctly.
At first, I tested each component separately and then added them together.
For the servo motor and potentiometer, I used the code from examples. (example-> servo -> knob) and it worked nicely.
For the LDR, I tested it using a serial monitor.
Code
Knob example path
Building the circuit
I recreated the Tinkercad circuit using hardware components.
*steps:
connect the 5V from the Arduino to the positive rail on the breadboard
connect the GND from the Arduino to the negative rail on the breadboard
connect the servo motor's ground to the Arduino's GND and its power to the positive rail on the breadboard, with the signal pin connected to Digital Pin 9.
For the LDR sensor, I used the same connections as the servo, with the signal pin connected to Digital Pin 2 on the Arduino.
Connect the potentiometer's ground to the breadboard's GND and its power to the positive rail on the breadboard, with the signal pin connected to Analog Pin A0.
For the Relay, I followed the connection shown in the pic
Building the circuit
Relay connection to DC lamp
Testing the circuit
Testing the circuit
Device's enclosure
LDR on breadboard
I wanted to mount the LDR module outside the enclosure so that it could easily detect light, but I didn't have enough crocodile wires to connect it, so I left the top of the device open to allow it to detect light easily.