This week assignment is to build and Program a smart circuit using an Arduino UNO which reads a signal from an input component (Sensor, Switch, or variable resistor) to control an action component (Motor, Buzzer, LED...etc.) using Code Blocks.
Early Birds Alarm:
I get inspiration from the smart lamp that sense the light and work according to darkness but I wanted to try the buzzer instead of the lamp/led to work as an alarm when the sunrise and the light bright so it will be nice to the morning persons.
Reference _LDR with lamp_
Electronic Copmonents:
Arduino IDE
I started with simulating the circuit in Tinkercad to make sure of the connection.
- connect the buzzer with the breadboard and connect buzzer ground to the Arduino ground and positive to analog pin 3 so I can control the tone of the buzzer.
- connect the LDR sensor to the Arduino. ground to ground positive to 5v and the last leg to Arduino digital pin 12 .
- start simulation to make sure that buzzer are working.
- Now I have an input [LDR] and output [Buzzer] that I want to control by the code blocks on Tinkercad.
- put If condition to read the input of light from pin 12 and according to this set the analog pin 3 to range of different values to make the buzzer tone.
- Except that the buzzer/alarm is off.
For the code blocks I put if condition as fellow:
- read the LDR input from digital pin 12.
- if LDR detects the light then the digital pin value =1 so control the buzzer output on analog pin 3 with a range of different values to give me a specific tone with a second time interval between each value then set the pin to 0.
- except that (the LDR don’t detect the light so the digital pin read isn’t 1) set the output pin to 0 so the buzzer is off.
Real Simulating video
The LDR sensor was sensing in a wrong way I can’t understand so I found that the potentiometer needed to be adjusted to sense the light well.