Title of Media
when I go to the dentist , I like the LED Sensor Light in the dental chair , when the doctor move his hand in front of light , the light switch on , so I want to use ultra sonic sensor and led and try this idea .
website : https://www.tinkercad.com/
Title of Media
Software: Arduino IDE
Title of Media
1 resistor 220 ohm
Arduino
Breadboard
Ultrasonic Sensor
Jumper Wires (Male - Male)
Led
Title of Media
Title of Media
First , I make the circuit on Tinker Cad , connect the ultrasonic sensor , led , resistor on breadboard , then connect the breadboard with Arduino with two Jumpers , one for ground and the other for 5V , connect the ultrasonic to the Arduino by four Jumpers , GND connect to the ground in breadboard , ECHO connect to pin 2 in Arduino , TRIG connect to pin 3 in Arduino
connect resistor to pin 7 in Arduino , put Jumper to connect the cathode of led to the ground on breadboard .
Title of Media
Then I make the code blocks in Tinker Cad , I add "Sensor value" block in Variables , form Input icon , choose "read ultrasonic distance on trigger pin " block , from output icons I choose "print to serial monitor " block to see the numbers of distance in Arduino , after that I put "if else" block form control icon , put sensor value block inside it , and choose block from Math icon to put the distance on it that will make the lamp on and off , put two blocks from output " set pin 7 to high else set pin 7 to low .
After I make the circut on Tinker cad ,
the link of circuit on tinker cad
I started to make the real circuit with components , connect the bread board with Arduino and led , ultrasonic exactly like the tinker cad circuit with same pins number and jumpers .
Title of Media
Then I take a copy of text on tinker cad , put it in Arduino IDE program , connect the Arduino to the computer and upload the code to it .
the code :
// C++ code
//
int SensorValue = 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(7, OUTPUT);
}
void loop()
{
SensorValue = 0.01723 * readUltrasonicDistance(3, 2);
Serial.println(SensorValue);
if (SensorValue >= 50) {
digitalWrite(7, HIGH);
} else {
digitalWrite(7, LOW);
}
delay(10); // Delay a little bit to improve simulation performance
}
Title of Media
When I upload the code to Arduino , it is not work , and appear massage , i can't understand it . so I ask help from Amani , she revise all the code then she discovered that I choose Arduino nano instead of Arduino uno , so we fix it and it uploaded successfully.
Title of Media
Title of Media
First Idea I made for this week was three led light , feel the temperature by LM35 sensor and similar to my final project, but I found the sensor has weird problem that the serial monitor appear negative degree of temperature numbers , so I try to solve the problem to avoid this numbers in final project , because of limited time , the instructors adviced me to work on another idea , I make ultrasonic Idea while we solve the problem with the final project .
Lear how to control an LED using a Digital Output Signal , and make it by myself.
Title of Media
Aya and me build smart waving Hand using Arduino , and it is really cool and funny .
Title of Media