// Simulate(Uno) link sketch to Arduino board here
#define LED 5 // Pin for LED
#define READPIN A0 // Pin to be read.
#define THRESHOLD 512 // Arbitary value to be used in exercise.
int readVal; // stores value which is read from from A0
float Voltage;
float Temperature;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(LED, OUTPUT);
}
void loop() {
readVal = analogRead(READPIN); // Read a value from the analog pin
Serial.print("The value read from A0 is: ");
Serial.println(readVal); // Print it to the console
Voltage = map(readVal, 0, 1023, 0, 500) / 100.00;
Temperature = map(readVal, 0, 1023, 100, 500) / 10.0;
Serial.print("Voltage = ");
Serial.print(Voltage);
Serial.println(" V");
Serial.print("Temperature = ");
Serial.print(Temperature);
Serial.println(" C");
if (readVal > THRESHOLD){
digitalWrite (LED, HIGH);
Serial.println("Cooling Fan is On!");
} else if (readVal < THRESHOLD){
digitalWrite (LED, LOW);
}
delay(1000); // Allow the user time to read the output.
}