Software
Arduino IDE
TinkerCad
Materials
Wires
Ultrasonic Sensor
BreadBoard
green LED
Resistor 330/220 Ohm
USB Cable
Arduino UNO
Designing (Tinker CAD)
1- install all materials we are going to use
Arduino Uno.
jumpers.
USB cable.
Green LED.
Resistor.
breadboard.
ultrasonic sensor.
2- Connect all components on the breadboard (Parallel).
3- start the STIMULATION .feature to make sure every component is working.
Coding by blocks in (Tinker CAD)
1- from variables create a new block named it with Ultrasonic_sensor, then i choosed set Ultrasonic_sensor to.
from input, we choose read the ultrasonic sensor on trigger pin & echo pin
2- from output I choose print to serial monitor to know if the code working well.
3- from control I choose if - else.
4- then I set from math 1 < 10 then I put from variables ultrasonic_ sensor.
5- from output I choose set pin to HIGH to put the pin I connect in the circuit that is responsible for LED.
6- then I set it to LOW to let the LED stop if the condition isn't occurred ultrasonic_ sensor didn't receive any movement
circuit after connecting it
1- Connect all components on the breadboard and Arduino Uno.
2- Make the block code on tinker cad.
3- Test the block code on tinker cad by starting the STIMULATION .
4- open blocks & text then Copy the text of the code I made on tinker cad, then paste it on Arduino IDE.
5- Uploading the code to the Arduino UNO.
// C++ code
//
int ultrasonic_sensor = 0;
long readUltrasonicDistance(int triggerPin, int echoPin)
{
pinMode(triggerPin, OUTPUT); // Clear the trigger
digitalWrite(triggerPin, LOW);
delayMicroseconds(2);
// Sets the trigger pin to HIGH state for 10 microseconds
digitalWrite(triggerPin, HIGH);
delayMicroseconds(10);
digitalWrite(triggerPin, LOW);
pinMode(echoPin, INPUT);
// Reads the echo pin, and returns the sound wave travel time in microseconds
return pulseIn(echoPin, HIGH);
}
void setup()
{
Serial.begin(9600);
pinMode(11, OUTPUT);
}
void loop()
{
ultrasonic_sensor = 0.01723 * readUltrasonicDistance(13, 12);
Serial.println("hello world");
if (ultrasonic_sensor < 10) {
digitalWrite(11, HIGH);
} else {
digitalWrite(11, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
I Learned how to design a circuit and code it with tinker cad to know how to design & code electrical circuits by using tinker cad, it is going to help me to design & code my final project.