Submarine Project Using an Arduino
by 652410 in Circuits > Arduino
2411 Views, 9 Favorites, 0 Comments
Submarine Project Using an Arduino
This is a fun project that I decided to use and experiment, using arduino and tinkercad. In this project I made a component of a submarine that measures and detects distance as well as detecting motion. When this occurs an RGB led will turn on, it will turn red if the motion is detected and change to different colours when it is detecting distance. An LCD is displaying the data that those components are receiving. This is an idea that can help in a submarine, detect marine life in the ocean, by sensing its motion as well as seeing how far a sea creature could be. Now lets get started on this project.
Supplies
First lets look at the supplies needed for this project:
7. RGB led
Components and Why They Are Needed
These are all the important components and supplies you will need in order to make this project, we need the distance sensor in order to sense the distance which will cause the RGB to change colors from blue to yellow depending on distance (there are more colors this is an example) and the LCD to display the numbers in inches. The motion sensor to detect motion which will trigger the RGB led to turn red, and a message saying "motion detected" on the LCD. All of these will be connected to the breadboard and the Arduino will help run the project.
You will need to first bring these components either if you are trying this out with real components or with tinker cad.
Wiring the Components on Breadboard
First: Take the red wire connect it from 5V and connect it to any of the power holes it has a positive sign and a red line. Then take a black wire to connect it from GND(ground) to the ground hole it's the one with a negative sign and a black line. (Look at the picture for example)
This will help for the current to flow through the project and power the components in the project.
Second: Now take your RGB led in Tinkercad or in the actual physical component, and place it on your breadboard (how I have placed it in my images or really anywhere if you know what you're doing). Then connect one of your 330-ohm resistors to the cathode part of your RGB, it the left most middle leg (on my picture the one with the resistor), this is a common cathode RGB meaning that this component needs to be connected to the ground. This means you should the resistor to the ground whole. Then connect 3 different wires to three different pins PMW pins (it has a Tilda symbol on it), then bring these different pins to the other three legs of the RGB, these three legs stand for red, blue, and green (I have color-coded it on the picture, orange is the red one).
This step is so when the code (since it is connected to pins) has been set up the RGB will change in colors, depending on the frequencies of the red, green, and blue.
Third: We then take our motion sensor putting it on our breadboard, then connect a red power wire to the middle leg (power leg) of the motion sensor and a black ground wire to the right leg (ground wire). Now connect a wire to any pin (copy mine for now) on the Arduino then bring that wire, connecting it to the left leg of the motion sensor also known as a signal.
The power and ground wires are there to power the component and the pin being connected is so that it can input on the Arduino allowing the motion sensor to work when motion is detected.
Fourth: We should now connect the distance sensor to the breadboard, the very far left leg and far-right leg are known as a VCC (power pin) and GND (ground pin), connect a red power wire and a black ground wire to those pins (like my photo). Connect one Arduino pin to the middle left trig pin and then connect another Arduino pin to the middle right echo pin.
The power and ground wires there to power the distance sensor. The two Arduino pins that are connected to the distance sensor will allow it to work, the trig pin will send a signal and the echo will return the signal.
Fifth: For the final step of wiring the components we can take the LCD and just keep it beside the breadboard because it does not fit on the breadboard. Connect it exactly as I have connected the LCD display especially with the wires. Connect a red power and black ground wire to VCC and GND, you will also need to have these wires connected to LED anode and LED cathode. When connecting to the LED anode make sure you connect our 2nd 330-ohm resistor so that the LCD does not explode. Also, make sure to connect VD/contrast and RW (read/write) to GND, this will ensure that words or numbers will actually be displayed on the LCD. Then connect Arduino pins to register select, enable, and then the pins DB4-DB7.
This will ensure that the LCD will actually work, once it has been coded.
Coding
What this code does:
This code actually allows this circuit to work, it does what I want it to do, anytime the distance is changed from 0 inches to 100 inches, it is displayed on the LCD. As well the RGB light will change from blue to brown (0-100) when the distance is changed, it changes to all the colors I have set it to. When motion is detected by the motion sensor a message displaying "motion detected" will be displayed because of the lcd.print code. A red light will shine on the RGB led when motion is detected.
Some better Explanation:
the liquid crystal command is there to make sure that LCD and the Arduino are able to work with each other, as well when defining the pins make sure it is in order from register select to DB7. As well when you want to put your distance make sure the code says lcd.print(distance), this will ensure that when the distance sensor has a specific distance the LCD will display it in inches.
Some extra things to know:
Make sure, you make a void set color in your code, this will allow you to change the different colors of the RGB so you can make different colors other than red, blue, and green. When displaying changing the colors you will need to change the values from 0-255. 0 means 0 volts and 255 means 5 volts, when you put a full 255(meaning sending full 5V to the red pin) of red you will only get a red color on the RGB (same with any of the other RGB pins) if you have all the RGB pins set to 255 the light will be white. To make different colors you will need to mix and match with different numbers set the three RGB pins (for example if you set red = 81, blue = 17, green = 60 you'll make brown). To find the values to make the different colors click the embed sentence to get there.
Downloads
Demonstration
This is a quick demonstration of how the circuit works. You can make this project more fun and add more components, feel free to play around with the code and have fun with mixing this project with other components.