7th Week - Journal
7th Week - Journal
Hey friends! here we are again, another tough week but an interesting one!
I wanted to focus on my final project so this week I made a little progress on the water level sensor I made in the past week. I added an LCD screen and a pushbutton to simulate part of my graduation project!
The idea is when the container is about to be empty, the buzzer made noise and the LCD displays the word "REFILL!". The pushbutton is used to clear the LCD screen -it's more like a reset button-
This one is used to upload write Arduino code and upload it to Arduino UNO.
I wanted so badly to try fritzing software since I saw lots of people using it and also there were components that I need in my circuit wiring but it's not available in Tinkercad so I took a shot!
Using two or more input and output components is a must in this assignment. Based on that, I added one input component which is a pushbutton besides the ultrasonic sensor I used the last week. While the additional output component is LCD screen.
1- The -ve terminal of the buzzer is connected to -ve side of the breadboard using a male-male jumper wire, while the +ve terminal is connected to digital pin 2.
2- The GND pin of the ultrasonic is connected to -ve terminal of the breadboard by using a female-male jumper wire, then a male-male wire is connected from -ve column of the breadboard to GND of Arduino. While the power pin is connected to+ve terminal of breadboard using a female-male jumper wire.
3- The trigger pin of ultrasonic is connected to pin 5 while echo is connected to 6 pin by using two female-male jumper wires.
4- LCD Wiring:
The Vcc pin is connected using male-female jumper wire with +ve terminal of breadboard.
GND pin is connected to -ve terminal of breadboard using a male-female jumper.
SDA & SCL pins are connected to A4 & A5 of Arduino using male-female jumper wires.
5- A terminal of pushbutton is connected to +ve of breadboard while the other terminal is connected to GND which is also connected to pin 3 of Arduino.
6- The +ve and -ve columns of breadboard are connected using male-male jumper wires to 5V pin and GND pin of Arduino respectively.
First Step: Build the Circuit.
I started by building the circuit as I designed in Fritzing but instead of attaching directly the pushbutton in the breadboard, I used female-male jumper wires to make them more flexible to move around.
I tried the circuit and it worked.
Here is the most exhausting part! Writing the code using Arduino C.
First, I downloaded the "Wire" library and "LiquidCrystal_I2C" library.
Second, I identify several variables which are echo and trigger pins of the ultrasonic sensor using the "long" tool. Then I clarify the pins that trigger and echo are attached to within Arduino using the "pinMode()" tool. Then, I Set the trigger pin to "HIGH" state for 10 microseconds using "delaymicroseconds". Then the echo pin reads and returns the sound wave travel time in microseconds.
I set the LCD address to 0x27 for a 16 chars and 2 line display.
Inside "void setup", I identified the pins of buzzer, and pushbutton using "pinMode()". The I initialized the LCD using "lcd.init()" and turned on the backlight using "lcd.backlight()".
Inside "void loop", I set an if condition. If ultrasonic read a distance more than 7 the buzzer will turn on and the LCD will display "REFILL!" word and inside this if condition I set another if condition which says if the pushbutton read low then clear or reset the LCD screen. If the ultrasonic didn't feel more than 7cm distance (else), the buzzer will stay off (LOW).
Second Step: Write the code.
After connecting the Arduino to your PC, check from the tools bar that you're connected to your Arduino. Then you can safely upload the code and test it.
Third Step: Test the Code.
Fourth Step: Build the Enclosure.
The main idea of the design is to fix the sensor so it looks down (to the surface of the water inside the container) and at the same time the LCD is clear to the user.
1- I measured the inside components (Arduino+breadboard) so I can know the dimensions I need for the base which was (12.5x10cm).
2- I outlined the base, sides, and back parts (11.5x13cm) and then cut it using the cutter.
3- The interface that includes LCD & pushbutton is made according to LCD dimensions which were (8x3.5cm). So I cut the cardboard (10x5cm), a little bit larger so I can add pushbutton.
4- Finally, I joint the parts using adhesive tape.
5- I made a place for USB of Arduino UNO and pushbutton as it appears in the adjacent picture.
6- Re-test the whole enclosure smart device which I made with my tears :(
There was no time to take any feedback. I made this assignment in less than 24 hours.
I got help again from my little sister in taking the previous videos so thanks againg sis :)
Okay, the code was literally isn't easy. First, the LCD code was hard a little bit since the last exercise I used LCD library that isn't the one that is attached to I2C so I had to google for other tutorials and I found this one which helped me a lot in coding this thing.
I actually tried to make the pushbutton a toggle but it didn't work. I used the code in this tutorial as my reference.
After I finished the enclosure, I found it a little bit shorter than I imagined. So the ultrasonic will definitely sense less than 12cm (the code I made was to sense more than 12 cm to turn on the buzzer) so I re-edit the code to be 7cm.
It turns out that Fritzing isn't free so after searching, I found this to download the software for free and it worked.
Also, there were components that were missed from fritzing to build my circuit so, after A LOT of searching, I found that you can download the missing parts from other projects and import them into your circuit. In my case, I needed the ultrasonic sensor (HC-SR04) & the I2C unit.
This absolutely made huge progress in my graduation project. I'm kinda relieved that this part of my project is done so if there were any problem in the future, I can easily know where it is and fixed so hope for the best :)
WOW, the journey is about to end :)
This week wasn't easy and we still need to practice more. But it was awesome doing the exercises of this week and make the circuit work as a magician. I enjoyed also the debugging :)
It was also my first week attending an extra session! I learned cool things from instructor Sherif (Thanks a lot) and I also was able to get to know my colleagues more so YEAH!
Note: It's not the final output.