Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //variables for temparature sensing and Motor________________________________________________________
- const int tSensor=A0;
- float tempC;
- float tempF;
- float output;
- int count=0;
- int controlPin = 9;
- int posDir = 8;
- int negDir = 7;
- //_____________________________________________________________________________________________________
- //_____________________Visitor COuting___________________________________________________________
- #define LDRpin A8 // pin where we connected the LDR and the resistor
- int LDRValue = 0; // result of reading the analog pin
- int LED = 40;
- int in = A1;
- int out = A2;
- float x;
- float y;
- int countLDR=0;
- //____________________________________________________________________________________________________
- //_________Vibration Sensor_____________________________________
- int led = 3;
- int vs =5; // vibration sensor
- //_____________________________________________________________
- //_____________________Visitor COuting___________________________________________________________
- void LEDS()
- {
- Serial.println("Light On");
- digitalWrite(LED,HIGH);
- }
- void NotLEDS()
- {
- digitalWrite(LED,LOW);
- }
- void checkLDR()
- {
- LDRValue = analogRead(LDRpin); // read the value from the LDR
- Serial.println("LDR Value:");
- Serial.println(LDRValue); // print the value to the serial port
- if(LDRValue<60)
- {
- LEDS();
- }
- else
- {
- NotLEDS();
- }
- }
- //___________________________________________
- void motor()
- {
- x=digitalRead(in);
- y=digitalRead(out);
- Serial.println(x);
- Serial.println(y);
- Serial.println("Total Members: ");
- Serial.println(countLDR);
- if(x==0)
- {
- countLDR=countLDR+1;
- delay(500);
- }
- else if(y==0)
- {
- countLDR=countLDR-1;
- delay(500);
- }
- delay(100);
- if(countLDR>0)
- {
- checkLDR();
- }
- else
- {
- Serial.println("Light Off");
- }
- }
- void temparature()
- {
- //Temparature measurement
- output=analogRead(tSensor);
- output=(output*500)/1023;
- tempC=output;
- tempF=(output*1.8)+32;
- Serial.print("Degree C =>");
- Serial.print(" ");
- Serial.print(tempC);
- Serial.print("\t");
- Serial.println();
- // delay(500);
- // output = 30;
- //Motor speed measurement
- Serial.print(output);
- Serial.print("\n");
- if(output<=30)
- {
- digitalWrite(posDir,HIGH);
- digitalWrite(negDir,LOW);
- analogWrite(controlPin,0);
- // delay(1000);
- }
- else if(output>30 && output<=50)
- {
- digitalWrite(posDir,HIGH);
- digitalWrite(negDir,LOW);
- analogWrite(controlPin,80);
- // delay(1000);
- }
- else if(output>60 && output<=200)
- {
- digitalWrite(posDir,HIGH);
- digitalWrite(negDir,LOW);
- analogWrite(controlPin,255);
- // delay(1000);
- }
- }
- void setup()
- {
- pinMode(in,INPUT);
- pinMode(out,INPUT);
- pinMode(tSensor,INPUT);
- pinMode(posDir,OUTPUT);
- pinMode(negDir,OUTPUT);
- pinMode(controlPin,OUTPUT);
- pinMode(led, OUTPUT);
- pinMode(vs, INPUT);
- Serial.begin(9600);
- }
- void loop()
- {
- temparature();
- motor();
- long measurement =vibration();
- // delay(50);
- Serial.println("Earthquake: ");
- Serial.println(measurement);
- if (measurement > 50)
- {
- digitalWrite(led, HIGH);
- }
- else
- {
- digitalWrite(led, LOW);
- }
- }
- long vibration(){
- long measurement=pulseIn (vs, HIGH); //wait for the pin to get HIGH and returns measurement
- // long measurement= digitalWrite(vs, HIGH);
- return measurement;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement