Scanning Radar Idea
This week assignment I have been asked to design a smart device supported with 2 inputs and 2 outputs so I decided to design a scanning movable radar to detect the moving object and return the distance through Ultrasonic sensor and represents data of moving object on I2C_LCD.
Inspiration
I have been inspired from some accidents occurred last year when a child fell in a deep well. I hoped to share my idea by designing a scanning radar to detect the distance of any moving child nearer to the site fo danger then visualize these data on an LCD.
Software tool:
Tinker cad online tool is pretty useful for designing the circuits where I can test the results easily, to avoid any mistakes before the actual test on the bred board.
Arduino IDE for Mac Os
coding and programming hardware components need an intermediate tool to adjust and to operate the code on the electronic circuits. Arduino IDE is doing this function
Hardware tools
Electronic tools
Arduino Uno + USB cable powered by 9 volt
Ultrasonic sensor powered by 5 v
Servo motor powered by 5 v
I2C LCD powered by 5 v
small breadboard
On/Off switch
Jumper wires
Materials for Enclosure
card board
Sticky tab
scissors
cutter
Software tools
Arduino IDE for Mac Os
step 1: Pseudocode
Thinking in the whole process by designing pseudocode for the project.
I wrote the code in form of steps to imagine the real action during the preparation process.
step 2 : Tinker cad circuit
Dragging all needed components.
connect all GND for all components (Ultrasonic sensor, servo motor LCD and Button) to the bread board at the -ve common terminal using black wirs.
connecting power from (Ultrasonic, servo and LCD) to the common +ve on bread board with red wires.
connecting the second terminal of the button to Arduino on digital pin.
Ultrasonic has 2 opposite pins
Trig pin which is out put that produces Ultra sonic waves on pin 8 and the second one is In put pin (echo pin) that receives the US waves and return it to the Arduino on pin 9.
I2C_LCD needs to be connected on 2 analog pins in addition to 1 GND and other one is +ve.
Finally Servo motor needs 1 digital pin.
Step 3 Arduino IDE code
1- Before Setup void we need to define some variables and labiraries for Servo and LCD.
Defining libraries for both LCD and Servo using #include + name of the libraries that have been installed.
2 variables are needed for the US sensor cons.integar for both pins (ing and echo).
2 variables for LCD one of them is long and given a name duration while the other is int. and given a name distance which are the values represented on the screen.
2 variable for the servo motor one is called myservo and the other one is called pos as an integer type and given an initial value = 0.
2- Void setup => in this section we need to define all outputs and inputs as well as the commands that needed to be run once at the startup of the code.
Set servo motor on pin 10
Set trigger pin of US on pin 8 while the echo one one 9.
Initialize the LCD.
start the serial communication at speed 9600.
3- Void loop => in this section we need to set the functions needed to be looped at certain time or at certain action.
I divided the loop into 3 sub-section
a- Ultrasonic code
Sets the trigPin 8 on HIGH state for 10 micro seconds
Reads the echoPin,measures & returns the sound wave travel time in microseconds
Speed of sound(at 20 degree C)=343 m/s =34300 cm/10^6 micro seconds =0.0343cm/microseconds.The sound wave was received at EchoPin after bouncing off the object, hence the sound wave travelled the distance twice and therefore the duration is divided by 2
Prints the distance in cm on the Serial Monitor
b- LCD Codes
Using built in functions to adjust settings of LCD such as set cursor, clear LCD and delay.
using lcd.print function to print data on lcd and by replacement the value inside the 2 brackets and using the (distance) variable ==> the values of Ultrasonic sensor reading should be printed on the lcd screen.
c- SERVO motor codes
Using for loop inside the void loop to detect the way of moving servo motor.
integrate the pos variable inside the for loop and determine the way of movement from 0 degree position to 180 degree then return back to the original position.
Reducing the delay time to be 15 milliseconds only.
Connection process
It is a simulation process to mimic all connections on tinker-cad.
Using the mini bread board and connect all GND wires from US-sensor, LCD, Servo and switch to the common one in the board then to the ground of Arduino.
connecting all 5 volt pins from all components to the board then to the 5 V of Arduino.
connect 2 pins of LCD (SDA & SCL) to analog pin of Arduino A4 and A5
connecting servo to digital pin 10 in Arduino.
connecting trig & echo pins of US- sensor to the digital pins 8 & 9.
Testing process
Double check that all components are connecting properly.
testing the code on serial monitor
Debugging all mistakes in the codes whatever syntax mistakes or logic mistakes.
upload the code on Arduino and run the components.
Mounting process
Using ruler and pencil to measure the needed parts to be cut to mount the components inside the enclosure.
Using cutter to cut the highlighted lines.
fixing the US -sensor at the top of servo to act as a real radar while the servo rotates in a half circle 180 the US reads distance in the surrounding environment.
Mount the LCD below the ultrasonic which is fixed on the top of the movable part of servo.
The LCD is suited for its position inside the enclosure, where the distance is obvious and notable.
Software challenge
1- LCD library installation
problem ==> after installation the library for LCD, it did not work at all.
solution ==> I surprised that I installed an old version for I2C LCD , I googled the type of LCD and by helping of get-hub site I downloaded the new update for LCD then it worked.
2- Coding mistakes
problem ==> I defined all variables inside void setup.
solution==> I redefined all variables and libraries before void setup.
Hardware challenges
problem ==> Fixing the Ultra sonic sensor on the servomotor without using hot glue gun.
Solution ==> I googled the problem and I found some nice ideas made up by card board to mount the US -sensor on the serrvo.
Visualizing data by LCD
I will implement I2C LCD as a main component in my final project to visualize the data in self watery plant.
Switching between 2 modes
It was a WoW moment on Saturday in lab session when we designed a smart home and using 2 different modes Manual and analog by selector / or sliding switch.