Advertisement
Guest User

ImrulHasan

a guest
Jan 23rd, 2020
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.42 KB | None | 0 0
  1. //variables for temparature sensing and Motor________________________________________________________
  2. const int tSensor=A0;
  3. float tempC;
  4. float tempF;
  5. float output;
  6. int count=0;
  7. int controlPin = 9;
  8. int posDir = 8;
  9. int negDir = 7;
  10. //_____________________________________________________________________________________________________
  11. //_____________________Visitor COuting___________________________________________________________
  12. #define LDRpin A8 // pin where we connected the LDR and the resistor
  13. int LDRValue = 0;     // result of reading the analog pin
  14. int LED = 40;
  15. int in = A1;
  16. int out = A2;
  17. float x;
  18. float y;
  19. int countLDR=0;
  20. //____________________________________________________________________________________________________
  21. //_________Vibration Sensor_____________________________________
  22. int led = 3;
  23. int vs =5; // vibration sensor
  24. //_____________________________________________________________
  25.  
  26. //_____________________Visitor COuting___________________________________________________________
  27. void LEDS()
  28. {
  29.   Serial.println("Light On");
  30.   digitalWrite(LED,HIGH);
  31. }
  32. void NotLEDS()
  33. {
  34.   digitalWrite(LED,LOW);
  35. }
  36. void checkLDR()
  37. {
  38.   LDRValue = analogRead(LDRpin); // read the value from the LDR
  39.   Serial.println("LDR Value:");
  40.   Serial.println(LDRValue);      // print the value to the serial port
  41.   if(LDRValue<60)
  42.   {
  43.     LEDS();
  44.   }
  45.   else
  46.   {
  47.     NotLEDS();
  48.   }
  49. }
  50. //___________________________________________
  51. void motor()
  52. {
  53.   x=digitalRead(in);
  54.   y=digitalRead(out);
  55.   Serial.println(x);
  56.   Serial.println(y);
  57.   Serial.println("Total Members: ");
  58.   Serial.println(countLDR);
  59.   if(x==0)
  60.   {
  61.     countLDR=countLDR+1;
  62.     delay(500);
  63.   }
  64.   else if(y==0)
  65.   {
  66.     countLDR=countLDR-1;
  67.     delay(500);
  68.   }
  69.   delay(100);
  70.  
  71.   if(countLDR>0)
  72.   {
  73.     checkLDR();
  74.   }
  75.   else
  76.   {
  77.     Serial.println("Light Off");
  78.   }
  79. }
  80. void temparature()
  81. {
  82.   //Temparature measurement
  83.   output=analogRead(tSensor);
  84.   output=(output*500)/1023;
  85.   tempC=output;
  86.   tempF=(output*1.8)+32;
  87.   Serial.print("Degree C =>");
  88.   Serial.print(" ");
  89.   Serial.print(tempC);
  90.   Serial.print("\t");
  91.   Serial.println();
  92. //  delay(500);
  93. //  output = 30;
  94.   //Motor speed measurement
  95.   Serial.print(output);
  96.   Serial.print("\n");
  97.   if(output<=30)
  98.   {
  99.     digitalWrite(posDir,HIGH);
  100.     digitalWrite(negDir,LOW);
  101.     analogWrite(controlPin,0);
  102. //    delay(1000);
  103.   }
  104.   else if(output>30 && output<=50)
  105.   {
  106.     digitalWrite(posDir,HIGH);
  107.     digitalWrite(negDir,LOW);
  108.     analogWrite(controlPin,80);
  109. //    delay(1000);
  110.   }
  111.   else if(output>60 && output<=200)
  112.   {
  113.     digitalWrite(posDir,HIGH);
  114.     digitalWrite(negDir,LOW);
  115.     analogWrite(controlPin,255);
  116. //    delay(1000);
  117.   }
  118. }
  119. void setup()
  120. {
  121.   pinMode(in,INPUT);
  122.   pinMode(out,INPUT);
  123.  
  124.   pinMode(tSensor,INPUT);  
  125.   pinMode(posDir,OUTPUT);
  126.   pinMode(negDir,OUTPUT);
  127.   pinMode(controlPin,OUTPUT);
  128.  
  129.   pinMode(led, OUTPUT);
  130.   pinMode(vs, INPUT);
  131.   Serial.begin(9600);
  132. }
  133. void loop()
  134. {
  135.   temparature();
  136.   motor();
  137.  
  138.  
  139.   long measurement =vibration();
  140. //  delay(50);
  141.   Serial.println("Earthquake: ");
  142.   Serial.println(measurement);
  143.   if (measurement > 50)
  144.   {
  145.     digitalWrite(led, HIGH);
  146.   }
  147.   else
  148.   {
  149.     digitalWrite(led, LOW);
  150.   }
  151.  
  152. }
  153. long vibration(){
  154.   long measurement=pulseIn (vs, HIGH);  //wait for the pin to get HIGH and returns measurement
  155. //  long measurement= digitalWrite(vs, HIGH);
  156.   return measurement;
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement