Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

How to call function to read temp and read light . int lightPin = A1; // Analog input pin for light sensor int tempPin =

How to call function to read temp and read light .

int lightPin = A1; // Analog input pin for light sensor

int tempPin = A2; // Analog input pin for temperature sensor

void setup() {

Serial.begin(9600); // serial communication at 9600 bits per second

}

void loop() {

if (Serial.available()) {

String command = Serial.readStringUntil(' '); // Read the incoming command from serial monitor

if (command == "Read Temp") { // If the command is to read temperature

float temp = (5.0 * analogRead(tempPin) * 100.0) / 1024.0; // Calculate the temperature in Celsius

Serial.print("Temperature is: ");

Serial.print(temp);

Serial.println("C");

}

else if (command == "Read Light") { // If the command is to read light intensity

int lightValue = analogRead(lightPin); // Read the analog value from the photoresistor

Serial.print("Light intensity is: ");

Serial.println(lightValue);

}

else if (command == "Read all sensors") { // If the command is to read all sensors

float temp = (5.0 * analogRead(tempPin) * 100.0) / 1024.0; // Check if this correct

int lightValue = analogRead(lightPin); // Read the analog value from LDR

Serial.print("Temperature : ");

Serial.print(temp);

Serial.println("C");

Serial.print("Light intensity : ");

Serial.println(lightValue);

}

else { // If the command is not recognized

Serial.println("Invalid command.");

}

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

SQL Antipatterns Avoiding The Pitfalls Of Database Programming

Authors: Bill Karwin

1st Edition

1680508989, 978-1680508987

More Books

Students also viewed these Databases questions