Advertisement
Guest User

Team Innotronics

a guest
Jan 13th, 2018
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 4.87 KB | None | 0 0
  1. #include <Servo.h>
  2. #include <LiquidCrystal_I2C.h>
  3.  
  4. LiquidCrystal_I2C lcd(0x3F, 20, 4);
  5. Servo myservo;
  6. //TMP36 Pin Variables
  7. int sensorPin = A0; //the analog pin the TMP36's Vout (sense) pin is connected to
  8.                         //the resolution is 10 mV / degree centigrade with a
  9.                         //500 mV offset to allow for negative temperatures
  10. int reading;
  11. float voltage;
  12. float temperatureC;
  13. float temperatureF;
  14. int fsrADC;
  15.  float fsrV;
  16.  float fsrR;
  17.  float fsrG;
  18.  String data;
  19. /*
  20.  * setup() - this function runs once when you turn your Arduino on
  21.  * We initialize the serial connection with the computer
  22.  */
  23. const int FSR_PIN = A1; // Pin connected to FSR/resistor divider
  24.  
  25. // Measure the voltage at 5V and resistance of your 3.3k resistor, and enter
  26. // their value's below:
  27. const float VCC = 4.98; // Measured voltage of Ardunio 5V line
  28. const float R_DIV = 3230.0; // Measured resistance of 3.3k resistor
  29. float force;
  30.  int potpin = A5;  // analog pin used to connect the potentiometer
  31. int val;
  32. void setup()
  33. {
  34.   Serial.begin(9600);  //Start the serial connection with the computer
  35.                        //to view the result open the serial monitor
  36.   lcd.begin();
  37.   lcd.backlight();
  38.   //lcd.print("Done Initializing");
  39.    myservo.attach(10);
  40.   myservo.write(70);  // set servo to mid-point
  41.   pinMode(2, OUTPUT);
  42.  
  43. }
  44.  
  45. void loop()                     // run over and over again
  46. {
  47.   //lcd.clear();
  48.   myservo.write(0);
  49.   if(Serial.available() > 0) {     // Send data only when you receive data:
  50.  
  51.       data = Serial.read();
  52.       //lcd.print(data);
  53.      
  54.       if(data == "49"){
  55.         //lcd.print("*********");
  56.         myservo.write(180);
  57.         delay(15);
  58.       }
  59.       else if(data == "48") {
  60.         myservo.write(0);
  61.         delay(15);
  62.       }
  63.      
  64.      else if(data == "50") {
  65.         digitalWrite(2,HIGH);
  66.       }
  67.      
  68.       else if(data == "51") {
  69.         digitalWrite(2,LOW);
  70.       }
  71.      
  72.       //Serial.println(data);
  73. }
  74.   short photo_sens = analogRead(A2);
  75.  //getting the voltage reading from the temperature sensor
  76.  reading = analogRead(sensorPin);  
  77.  
  78.  // converting that reading to voltage, for 3.3v arduino use 3.3
  79.  voltage = reading * 5.0;
  80.  voltage /= 1024.0;
  81.  
  82.  // print out the voltage
  83.  //Serial.print(voltage); Serial.println(" volts");
  84.  
  85.  // now print out the temperature
  86.  temperatureC = (voltage - 0.5) * 100 ;  //converting from 10 mv per degree wit 500 mV offset
  87.                                                //to degrees ((voltage - 500mV) times 100)
  88.  //Serial.print(temperatureC); Serial.println(" degrees C");
  89.  
  90.  // now convert to Fahrenheit
  91.  temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
  92.  //Serial.print(temperatureF); Serial.println(" degrees F");
  93.  
  94.   fsrADC = analogRead(FSR_PIN);
  95.   // If the FSR has no pressure, the resistance will be
  96.   // near infinite. So the voltage should be near 0.
  97.   if (fsrADC != 0) // If the analog reading is non-zero
  98.   {
  99.     // Use ADC reading to calculate voltage:
  100.     fsrV = fsrADC * VCC / 1023.0;
  101.     // Use voltage and static resistor value to
  102.     // calculate FSR resistance:
  103.     fsrR = R_DIV * (VCC / fsrV - 1.0);
  104.     //Serial.println("Resistance: " + String(fsrR) + " ohms");
  105.     // Guesstimate force based on slopes in figure 3 of
  106.     // FSR datasheet:
  107.     fsrG = 1.0 / fsrR; // Calculate conductance
  108.     // Break parabolic curve down into two linear slopes:
  109.     if (fsrR <= 600)
  110.       force = (fsrG - 0.00075) / 0.00000032639;
  111.     else
  112.       force =  fsrG / 0.000000642857;
  113.    // Serial.println("Force: " + String(force) + " g");
  114.   //  Serial.println();
  115.  
  116.   }
  117.   else
  118.   {
  119.     // No pressure detected
  120.   }
  121.  
  122.  
  123.   int forceInt = force;
  124.   int forceOn = 0;
  125.   int tempOn = 0;
  126.   int photoOn = 0;
  127.   //String outputPhoto = "P" + String(photo_sens) + "R";
  128.   //String outputTemp = "T" + String(temperatureF,0) + "R";
  129.   //String outputForce = "F" + String(forceInt) + "R";
  130.   //Serial.print(outputPhoto);
  131.   //Serial.print(outputTemp);
  132.   //Serial.print(outputForce);
  133.  
  134.   if (forceInt >= 250)
  135.     forceOn = 1;
  136.   else
  137.     forceOn = 0;
  138.  
  139.   if (temperatureF >= 85)
  140.     tempOn = 1;
  141.   else
  142.     tempOn = 0;
  143.  
  144.   if (photo_sens >= 30)
  145.     photoOn = 1;
  146.   else
  147.     photoOn = 0;  
  148.  
  149.   String output = String(forceOn) + String(tempOn) + String(photoOn);
  150.   if (output == "000"){
  151.     Serial.print("0");
  152.   }
  153.   else if (output == "001"){
  154.     Serial.print("1");
  155.   }
  156.   else if (output == "010"){
  157.     Serial.print("2");
  158.   }
  159.   else if (output == "011"){
  160.     Serial.print("3");
  161.   }
  162.   else if (output == "100"){
  163.     Serial.print("4");
  164.   }
  165.   else if (output == "101"){
  166.     Serial.print("5");
  167.   }
  168.   else if (output == "110"){
  169.     Serial.print("6");
  170.   }
  171.   else if (output == "111"){
  172.     Serial.print("7");
  173.   }
  174.  
  175.   lcd.clear();  
  176.   lcd.print("InnoHome            ");  
  177.   lcd.print("Temperature " + String(temperatureF,0) + " F");
  178.    
  179.   delay(200);  
  180.  
  181. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement