6.Annex

 

we were folding the flowers.

we don’t know how to realize that the flower will activated by the different amount of time the time users stay.

the final work

int TRIG_PIN = 9;

int ECHO_PIN = 10;

long duration;

int distance;

int greenled = 6;

int whiteled = 5;

int redled = 11;

int brightness = 0;

int fadeAmount = 5;

long startTime = 0;

int tempPin = A0;

int temperature;

#include <Servo.h>

Servo myservo;

int pos = 0;

void setup() {

Serial.begin(9600);

pinMode(TRIG_PIN, OUTPUT);

pinMode(ECHO_PIN, INPUT);

pinMode(greenled, OUTPUT);

pinMode(whiteled, OUTPUT);

pinMode(redled, OUTPUT);

myservo.attach(3);

}

void state1() {

for (pos = 0; pos <= 180; pos += 1) {

myservo.write(pos);

delay(15);

}

for (pos = 180; pos >= 0; pos -= 1) {

myservo.write(pos);

delay(15);

}

/*

This was adapted from a tutorial found here:

https://docs.arduino.cc/learn/electronics/servo-motors

*/

}

void loop() {
brightness = brightness + fadeAmount;
if (brightness <= 0 || brightness >= 255) {
fadeAmount = -fadeAmount;
}
/*
This was adapted from a tutorial found here:
https://docs.arduino.cc/built-in-examples/basics/Fade
*/
digitalWrite(TRIG_PIN, LOW);
delayMicroseconds(2);
digitalWrite(TRIG_PIN, HIGH);
delayMicroseconds(10);
digitalWrite(TRIG_PIN, LOW);
duration = pulseIn(ECHO_PIN, HIGH);
distance = duration * 0.034 / 2;
/*
This was adapted from a tutorial found here:

Ultrasonic Sensor HC-SR04 and Arduino – Complete Guide


*/
temperature = analogRead(tempPin);

Serial.println(temperature);
if (distance <= 90) {
analogWrite(greenled, brightness);
delay(10);
}
if (distance <= 70) {
analogWrite(redled, brightness);
delay(10);
}
if (distance <= 50) {
analogWrite(whiteled, brightness);
delay(10);
}
if (distance > 90) {
digitalWrite(greenled, LOW);
digitalWrite(whiteled, LOW);
digitalWrite(redled, LOW);
}
if (temperature >= 57) {
state1();
}
}

Leave a Reply

Your email address will not be published. Required fields are marked *