Question
What needs to be changed in this code for it to work? const int relayPin = 13; // use this pin to drive the transistor
What needs to be changed in this code for it to work?
const int relayPin = 13; // use this pin to drive the transistor const int timeDelay = 500; // delay in ms for on and off phases const int temperaturePin = A0; //setup input analog pin for collecting temperature data
void setup() { pinMode(relayPin, OUTPUT); // set pin as an output Serial.begin(960); // set baud rate to 9600 }
void loop() { digitalWrite(relayPin, HIGH); // turn the relay on delay(timeDelay); // wait digitalWrite(relayPin, LOW); // turn the relay off delay(timeDelay); // wait float voltage, degreesC, degreesF; // declare 3 decimal number (floating) variables
voltage = getVoltage(temperaturePin); //measure the voltage
degreesC = (voltage - 0.5) * 100.0; // convert voltage to Celsius // This formula comes from the temperature sensor datasheet:
degreesF = degreesC * (9.0/5.0) + 32.0; // convert Celsius to Fahrenheit // This is the classic C to F conversion formula: // Use Serial.print() function to print variables or text (within quotes) Serial.print("voltage: "); // Prints word voltage Serial.print(voltage); // Prints voltage value Serial.print(" deg C: "); // Prints words deg C Serial.print(degreesC); // Prints Celsius value Serial.print(" deg F: "); // Prints words deg F Serial.println(degreesC); // Prints Fahrenheit value
// These statements will print lines of data like this: // "voltage: 0.73 deg C: 22.75 deg F: 72.96"
delay(timeDelay); // repeat after a delay }
float getVoltage(int pin) // statement to read the analog signal and convert to voltage {
return (analogRead(pin) * 0.004882814);
// This equation converts the 0 to 1023 value that analogRead() // returns, into a 0.0 to 5.0 value that is the true voltage // being read at that pin. }
N TMP .... 13 .. 15 .. 16 .. 17 .. 18 .. 19 . H. 192/E VASZI/VE -S- DIGITAL (PWM-) O (UNO TX ON RX ARDUINO POWER ANALOG INStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started