Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <Servo.h>
- #include <LiquidCrystal_I2C.h>
- LiquidCrystal_I2C lcd(0x3F, 20, 4);
- Servo myservo;
- //TMP36 Pin Variables
- int sensorPin = A0; //the analog pin the TMP36's Vout (sense) pin is connected to
- //the resolution is 10 mV / degree centigrade with a
- //500 mV offset to allow for negative temperatures
- int reading;
- float voltage;
- float temperatureC;
- float temperatureF;
- int fsrADC;
- float fsrV;
- float fsrR;
- float fsrG;
- String data;
- /*
- * setup() - this function runs once when you turn your Arduino on
- * We initialize the serial connection with the computer
- */
- const int FSR_PIN = A1; // Pin connected to FSR/resistor divider
- // Measure the voltage at 5V and resistance of your 3.3k resistor, and enter
- // their value's below:
- const float VCC = 4.98; // Measured voltage of Ardunio 5V line
- const float R_DIV = 3230.0; // Measured resistance of 3.3k resistor
- float force;
- int potpin = A5; // analog pin used to connect the potentiometer
- int val;
- void setup()
- {
- Serial.begin(9600); //Start the serial connection with the computer
- //to view the result open the serial monitor
- lcd.begin();
- lcd.backlight();
- //lcd.print("Done Initializing");
- myservo.attach(10);
- myservo.write(70); // set servo to mid-point
- pinMode(2, OUTPUT);
- }
- void loop() // run over and over again
- {
- //lcd.clear();
- myservo.write(0);
- if(Serial.available() > 0) { // Send data only when you receive data:
- data = Serial.read();
- //lcd.print(data);
- if(data == "49"){
- //lcd.print("*********");
- myservo.write(180);
- delay(15);
- }
- else if(data == "48") {
- myservo.write(0);
- delay(15);
- }
- else if(data == "50") {
- digitalWrite(2,HIGH);
- }
- else if(data == "51") {
- digitalWrite(2,LOW);
- }
- //Serial.println(data);
- }
- short photo_sens = analogRead(A2);
- //getting the voltage reading from the temperature sensor
- reading = analogRead(sensorPin);
- // converting that reading to voltage, for 3.3v arduino use 3.3
- voltage = reading * 5.0;
- voltage /= 1024.0;
- // print out the voltage
- //Serial.print(voltage); Serial.println(" volts");
- // now print out the temperature
- temperatureC = (voltage - 0.5) * 100 ; //converting from 10 mv per degree wit 500 mV offset
- //to degrees ((voltage - 500mV) times 100)
- //Serial.print(temperatureC); Serial.println(" degrees C");
- // now convert to Fahrenheit
- temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
- //Serial.print(temperatureF); Serial.println(" degrees F");
- fsrADC = analogRead(FSR_PIN);
- // If the FSR has no pressure, the resistance will be
- // near infinite. So the voltage should be near 0.
- if (fsrADC != 0) // If the analog reading is non-zero
- {
- // Use ADC reading to calculate voltage:
- fsrV = fsrADC * VCC / 1023.0;
- // Use voltage and static resistor value to
- // calculate FSR resistance:
- fsrR = R_DIV * (VCC / fsrV - 1.0);
- //Serial.println("Resistance: " + String(fsrR) + " ohms");
- // Guesstimate force based on slopes in figure 3 of
- // FSR datasheet:
- fsrG = 1.0 / fsrR; // Calculate conductance
- // Break parabolic curve down into two linear slopes:
- if (fsrR <= 600)
- force = (fsrG - 0.00075) / 0.00000032639;
- else
- force = fsrG / 0.000000642857;
- // Serial.println("Force: " + String(force) + " g");
- // Serial.println();
- }
- else
- {
- // No pressure detected
- }
- int forceInt = force;
- int forceOn = 0;
- int tempOn = 0;
- int photoOn = 0;
- //String outputPhoto = "P" + String(photo_sens) + "R";
- //String outputTemp = "T" + String(temperatureF,0) + "R";
- //String outputForce = "F" + String(forceInt) + "R";
- //Serial.print(outputPhoto);
- //Serial.print(outputTemp);
- //Serial.print(outputForce);
- if (forceInt >= 250)
- forceOn = 1;
- else
- forceOn = 0;
- if (temperatureF >= 85)
- tempOn = 1;
- else
- tempOn = 0;
- if (photo_sens >= 30)
- photoOn = 1;
- else
- photoOn = 0;
- String output = String(forceOn) + String(tempOn) + String(photoOn);
- if (output == "000"){
- Serial.print("0");
- }
- else if (output == "001"){
- Serial.print("1");
- }
- else if (output == "010"){
- Serial.print("2");
- }
- else if (output == "011"){
- Serial.print("3");
- }
- else if (output == "100"){
- Serial.print("4");
- }
- else if (output == "101"){
- Serial.print("5");
- }
- else if (output == "110"){
- Serial.print("6");
- }
- else if (output == "111"){
- Serial.print("7");
- }
- lcd.clear();
- lcd.print("InnoHome ");
- lcd.print("Temperature " + String(temperatureF,0) + " F");
- delay(200);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement