assignment was to use a smart circuit using an Arduino UNO and read a signal from an input component (used the Mercury Tilt Switch Sensori ) to control an action component (i used servo motor) using TinkerCad's Code Blocks
The idea of the assignment is :
The Arduino sense any body near to it and take dissension to stop our run his outputs by using ultrasonic sensor as input.
From my electronics kit
breadboard
voltage source (9 & 12 volte from my own tools in home )"
red and green LED
yellow DC Motor
jumper wires
Arduino uno
220 ohm resistance
ultra sonic sensor
Arduino ide
I start on tinkercad step by step in order not to be confused...
I add Arduino, breadboard, Ultrasonic sensor, red LED and green led then I test them first, green LED stop and red LED work when Ultra sensor read distance below 20cm
I add yellow motor and make it move when ultrasonic sensor read distance more than 20cm
Coding steps:
when the ultrasonic sensor reads distance below 20cm the green LED stop and red LED light up .
when the ultrasonic didn't sensor reads distance below 20cm the green LED light up and yellow motor run by its h-bridge drive
video of the design
From my electronics kit
breadboard
voltage source (9 & 12 volte)"
red and green LED
yellow DC Motor
jumper wires
Arduino uno
220 ohm resistance
ultra sonic sensor
Step 1 :
I assemble all the components using Tinkercad to make sure of the connection method and I know the correct wire connection methods
step 2 :
We use IF-condition for programming based on "CODE BLOCKS"
step 3 :
We run the code on Arduino IDE and make sure that all thing work select the Arduino from tools and update the code to it
int var = 0;
int if2 = 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()
{
pinMode(A2, INPUT);
Serial.begin(9600);
pinMode(8, OUTPUT);
pinMode(10, OUTPUT);
pinMode(9, OUTPUT);
pinMode(A0, OUTPUT);
pinMode(A1, OUTPUT);
}
void loop()
{
if (analogRead(A2) == HIGH) {
var = 0.01723 * readUltrasonicDistance(11, 12);
Serial.println(var);
if (var <= 20) {
digitalWrite(8, LOW);
digitalWrite(10, HIGH);
analogWrite(9, 90);
digitalWrite(A0, LOW);
digitalWrite(A1, LOW);
} else {
digitalWrite(9, HIGH);
digitalWrite(8, HIGH);
digitalWrite(10, LOW);
analogWrite(9, 90);
digitalWrite(A0, HIGH);
digitalWrite(A1, LOW);
}
} else {
digitalWrite(8, HIGH);
digitalWrite(10, HIGH);
analogWrite(9, 90);
digitalWrite(A0, LOW);
digitalWrite(A1, HIGH);
}
delay(10); // Delay a little bit to improve simulation performance
}
describe of the design process
1- i used Tinkercad software to simulate the electric circuit components and make sure it work like my design and also help me to fix any problem easily
2- integrate all parts on components very easy and give my image about how it will be look in real
3- i used the push button in the circuit as loop cable replacement
wiring the components use the jumpers and integrate all parts like the one in tinkercad
2. Test all components individually, to make sure they work
3. upload the code to the Arduino from IDE and try the circuit and look for any problem and try to troubleshoot
The Arduino sense any body close to it by 20 cm to it and take dissension to stop the motor and turn off the green led and the red led will light up
i have problem with understand how the ultrasonic sensor work and Frida help me to understand that economical sensor provides 2cm to 400cm of non-contact measurement functionality with a ranging accuracy that can reach up to 3mm, so the body near than 2 cm not readable
Also some of my teammates face problems and I try to help them solving their issue.
problem with on & off switch didn't disconnect the circuit because i didn't write it in the code so i decided to move this step to the next week and it's code is very easy
void setup() {
pinMode(8, INPUT_PULLUP);
void loop() {
// put your main code here, to run repeatedly:
if (digitalRead (3) == HIGH) {
do the condition which i mention }
else { do nothing }
}
This project will benefit me because I have been trained to implement an idea from scratch and do it with the tools that I had in addition to learning how to connect electrical circuits and implement ideas. All these skills will help me in the final project
Saeed once said that in electrical circuits it is rare to work with you the first time, and I did not believe this, but after the experience, I really realized the truth of the matter because the circuit did not work with me from the first time and I encountered errors in the design 😂😂😂, So I learned a lesson that it is normal for the circuit not to work for you from the first time and it is normal for you to try again more than once
Title of Media