Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Measure Voltage of Pin for Temperature Sensor July 26 2018
- //Pin definitions
- int buttonPin = 6;
- int redLEDPin = 4;
- int greenLEDPin = 2;
- int relayPin = 13;
- //Global variables
- int buttonState = 0;
- void setup()
- {
- //setup serial reading for 9600 bits of data per second between the board and the computer console (this here)
- Serial.begin(9600);
- //Defining the ledpin as pin 8, and making the pin specified an output. Change 8 to any integer 0-13 for pins 1-13 on the arduino board
- pinMode(buttonPin, INPUT);
- pinMode(redLEDPin, OUTPUT);
- pinMode(greenLEDPin, OUTPUT);
- pinMode(relayPin, OUTPUT);
- }
- void loop(){
- buttonState = digitalRead(buttonPin);
- int tempAnalog = analogRead(A0);
- float voltage = tempAnalog * (5.0 / 1023.0);
- float temperature = (100 * voltage) - 50;
- int batAnalog = analogRead(A2);
- float vBat = batAnalog * (5.0 / 1023.0);
- int timeMeasurement = 0;
- int programStatus = 0;
- digitalWrite(relayPin, LOW);
- while(buttonState == 0) {
- sensorValue1 = analogRead(A0);
- voltage = sensorValue1 * (5.0 / 1023.0);
- temperature = (100 * voltage) - 50;
- sensorValue2 = analogRead(A2);
- vBat = sensorValue2 * (5.0 / 1023.0);
- Serial.println(temperature);
- Serial.println(vBat);
- buttonState = digitalRead(buttonPin);
- digitalWrite(redLEDPin, HIGH);
- delay(1000);
- }
- digitalWrite(redLEDPin, LOW);
- digitalWrite(greenLEDPin, HIGH);
- digitalWrite(relayPin, HIGH);
- Serial.println();
- Serial.println();
- delay(1000);
- Serial.print("TEMP.");
- Serial.print("\t");
- Serial.print("VOLTS");
- Serial.print("\t");
- Serial.print("TIME");
- Serial.println();
- sensorValue1 = analogRead(A0);
- voltage = sensorValue1 * (5.0 / 1023.0);
- temperature = (100 * voltage) - 50;
- sensorValue2 = analogRead(A2);
- vBat = sensorValue2 * (5.0 / 1023.0);
- Serial.print("Jack");
- Serial.println(vBat);
- while(vBat >= 3.1) {
- sensorValue1 = analogRead(A0);
- voltage = sensorValue1 * (5.0 / 1023.0);
- temperature = (100 * voltage) - 50;
- sensorValue2 = analogRead(A2);
- vBat = sensorValue2 * (5.0 / 1023.0);
- Serial.print(temperature);
- Serial.print("\t");
- Serial.print(vBat);
- Serial.print("\t");
- Serial.print(timeMeasurement);
- timeMeasurement++;
- Serial.println();
- delay(1000);
- }
- digitalWrite(relayPin, LOW);
- digitalWrite(greenLEDPin, HIGH);
- digitalWrite(redLEDPin, HIGH);
- Serial.println();
- Serial.print("-------- Program Finished --------");
- Serial.println();
- Serial.println();
- programStatus = 1;
- while(programStatus == 1) {
- delay(10000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement