My assignment's idea for this week is a somehow close to my final project. It is basically a smart interactive lamp, but with an alarming sound to it.
I wanted to add another output, besides the led to try and since the assignment requires that anyway., so I added the Piezo buzzer.
1-Software :
TinkerCad
Arduino Coding
2-Tools& materials:
Arduino UNO
Microwave Sensor
LED
220 ohm Resistor
Potentiometer
Buzzer
breadboard
Female Jumpers
USB Cable
Cardboard
First, I planned my circuit on tinkercad:
First, I picked the components, and I used the PIR Sensor instead of the Microwave sensor as it doesn't exist on the tinkercad.
I connected the led to the resistor.
I connected the led's end to digital pin 10 and the resister to the ground.
I connected the PIR Sensor to (Digital Pin 2 - Voltage - Ground).
I added the buzzer to digital pin 7.
I connected the potentiometer to analog pin A0.
2 . Then, I worked on my code on arduino :
I defined my components and their pins using the int function.
In my ( Void Setup) section: I defined the (led & buzzer) as my 2 OUTPUTS, and the (pot & microwave sensor) as my 2 INPUTS. Also, I initiated the serial function.
In my (Void Loop) section: I defined the potentiometer value to be read from the pin A0, then I defined the brightness as the potentiometer value / 4. ( This is to introduce the usage of the potentiometer as the led's intensity control.
Then, I defined the microwave sensor to be read from pin 2, and I serial printed it.
I then added an If condition, stating that if it's indeed high (meaning, if the sensor is sensing someone moving around), Pin 7 (LED) would be set to the brightness value ( controlling it through the potentiometer) , and the alarm will go off.
If Digital Pin 8 doesn't read high, neither the led nor the buzzer will be switched on.
Finally, I tested the functionality of it by simulating the circuit as shown in the video.
3. I tested my connection on the arduino:
First, I connected the female jumpers to the breadboard following exactly what I did on tinkercad.
I connected the USB to the arduino, and I uploaded the code to it.
I hovered around the microwave sensor and it did sense my movement and the led and the buzzer got turned on.
I was able to adjust the led's intensity through the potentiometer.
4. I did the enclosure of the circuit:
I did a very simple design, what really mattered was that the sensor was accessible.
1- I had a problem writing the code, like the structure of it and everything. Ibrahim advised me to break it down to a couple of small actions and building it up slowly. So first, I did the potentiometer controlling the intensity of the led, then I went ahead and wrote that of the sensor-(led, buzzer) if statement. Finally, I merged them together.
2- We had a problem in our group activity in the lab regarding our code, and it didn't work. Ahmed debugged the code and it turned out that we wrote the sensor-reading function incorrectly. Instead of reading the pin, we literally stated to read the sensor, without giving a variable for the sensor read value input. So:
digitalRead (sensor) X
digitalRead (8) O
I was really afraid of week 7 as it included the actual coding part using text and not blocks, but now I am more confident of this part in my final project.
Coding !!
Building a simple smart home system consisting of a fan, lamp, humidity and temperature sensor using the relay module.