Differences

This shows you the differences between two versions of the page.

Link to this comparison view

pm:prj2023:tmiu:smart_dustbin [2023/05/28 22:29]
mircea.pieleanu [Software Design]
pm:prj2023:tmiu:smart_dustbin [2023/05/28 22:36] (current)
mircea.pieleanu [Nume proiect]
Line 1: Line 1:
-====== ​Nume proiect ​======+====== ​Smart Dustbin======
 ===== Introducere ===== ===== Introducere =====
  
Line 29: Line 29:
 <note tip> <note tip>
 Am folosit o biblioteca <​Servo.h> ​ Am folosit o biblioteca <​Servo.h> ​
-#include <​Servo.h> ​  //​servo library +   Servo servo; ​     
-//Servo servo; ​     +   ​int trigPin = 5;     
-int trigPin = 5;     +   ​int echoPin = 6;    
-int echoPin = 6;    +   ​int servoPin = 7; 
-int servoPin = 7; +   ​int led= 10; 
-int led= 10; +   ​long duration, dist, average; ​   
-long duration, dist, average; ​   +   ​long aver[3]; ​  //array for average 
-long aver[3];  +   ​void setup() {       
- +
- +
-void setup() {       +
     Serial.begin(9600);​     Serial.begin(9600);​
     servo.attach(servoPin);  ​     servo.attach(servoPin);  ​
Line 47: Line 44:
     delay(100);     delay(100);
     servo.detach(); ​     servo.detach(); ​
-}  +   }  
- +   ​void measure() {   
-void measure() {   +    digitalWrite(10,​HIGH);​ 
- ​digitalWrite(10,​HIGH);​ +    digitalWrite(trigPin,​ LOW); 
-digitalWrite(trigPin,​ LOW); +    delayMicroseconds(5);​ 
-delayMicroseconds(5);​ +    digitalWrite(trigPin,​ HIGH); 
-digitalWrite(trigPin,​ HIGH); +    delayMicroseconds(15);​ 
-delayMicroseconds(15);​ +    digitalWrite(trigPin,​ LOW); 
-digitalWrite(trigPin,​ LOW); +    pinMode(echoPin,​ INPUT); 
-pinMode(echoPin,​ INPUT); +    duration = pulseIn(echoPin,​ HIGH); 
-duration = pulseIn(echoPin,​ HIGH); +    dist = (duration/​2) / 29.1;     
-dist = (duration/​2) / 29.1;     +   ​
-+   ​void loop() {  
-void loop() {  +     ​for (int i=0;​i<​=2;​i++) {    
-  for (int i=0;​i<​=2;​i++) {    +      measure(); ​               
-    measure(); ​               +      aver[i]=dist; ​            
-   ​aver[i]=dist; ​            +      delay(10); ​            
-    delay(10); ​            +
   }   }
- dist=(aver[0]+aver[1]+aver[2])/​3; ​    +   dist=(aver[0]+aver[1]+aver[2])/​3; ​    
- +  if ( dist<50 ) { 
-if ( dist<50 ) { +   ​//Putem schimba distanta dupa cum vrem 
-//Putem schimba distanta dupa cum vrem +   ​servo.attach(servoPin);​ 
- ​servo.attach(servoPin);​ +   ​delay(1); 
-  delay(1); +   ​servo.write(0); ​  
- ​servo.write(0); ​  +   ​delay(3000); ​       
- ​delay(3000); ​       +   ​servo.write(150); ​    
- ​servo.write(150); ​    +   ​delay(1000);​ 
- ​delay(1000);​ +   ​servo.detach(); ​      
- ​servo.detach(); ​      +   ​
-+   ​Serial.print(dist);​ 
-Serial.print(dist);​ +   ​}
-}//+
 </​note>​ </​note>​
  
pm/prj2023/tmiu/smart_dustbin.1685302148.txt.gz · Last modified: 2023/05/28 22:29 by mircea.pieleanu
CC Attribution-Share Alike 3.0 Unported
www.chimeric.de Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0