Time to Buy Food!!

by cathy38477329 in Circuits > Arduino

204 Views, 0 Favorites, 0 Comments

Time to Buy Food!!

49D01433-5F94-4050-8BF2-7057137B6C58.jpeg
I can remind you to buy food

Why I Want to Do This

57CBFD64-1286-4B9F-BB78-38FB8A09D943.jpeg
E6B9741F-04CE-44D5-93E2-ED78E0AC67C7.jpeg
9411DEE1-1D9E-41C6-9FC5-A54A5AB92A8E.jpeg
My mother always forgets to buy orange so I make this to remind her.

What We Need

9E45D1E1-072F-4B92-A459-6EA6929EEF50.png
Arduino uno R3 1個

電路試驗版 1個

超音波距離感應器。1個

電阻 1個

燈泡 1個

線 (因人而異)

Bread Boards

2E930CA6-504C-4E39-AB96-D4F7178696B9.png
3526325F-38FC-4975-9423-1B1A83E2E64E.jpeg
9EF17CA7-3445-477C-B897-51E4F8FC7513.jpeg

Run a Program

D31FD4C9-4B90-4304-9BA4-29F6D292977A.png
https://create.arduino.cc/editor/JennyLin717/5ef4ca22-ae25-4c82-adf0-d0706d6711e3/preview


int UltrasonicSensorCM(int trigPin, int echoPin) //Ultrasonic Sensor Code Auto Generated Return CM max distance 200
{
long duration;
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(20);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
duration = duration / 59;
if ((duration < 2) || (duration > 200)) return false;
return duration;
}


void setup(){ // put your setup code here, to run once:
digitalWrite( 11 , LOW ); //set ultrasonic sensor trigPin

pinMode( 10 , OUTPUT); // sets the digital pin as output
}

void loop(){ // put your main code here, to run repeatedly:
if ( UltrasonicSensorCM( 11 , 12 ) <10) {
digitalWrite( 10 , LOW ); // sets the digital pin on/off
noTone(8); //stop generating the tone
}
if ( UltrasonicSensorCM( 11 , 12 ) >10) {
digitalWrite( 10 , HIGH ); // sets the digital pin on/off
tone(8, 440, 1000); //buzzer or speaker frequency
}
}

How to Work

https://youtu.be/pRDcsejsyQ8