Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
5 views1 page

Arduino Return Value Codes Single Column

The document contains two code snippets for Arduino programming. The first code calculates temperature in Celsius from an analog reading using a TMP36 sensor, while the second code adds two numbers to determine the delay time for blinking an LED. Both codes include setup and loop functions for execution on an Arduino board.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views1 page

Arduino Return Value Codes Single Column

The document contains two code snippets for Arduino programming. The first code calculates temperature in Celsius from an analog reading using a TMP36 sensor, while the second code adds two numbers to determine the delay time for blinking an LED. Both codes include setup and loop functions for execution on an Arduino board.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Code 1: Calculate Temperature in Celsius from Analog Reading

int readTemperature(int analogPin) {


int reading = analogRead(analogPin);
float voltage = reading * (5.0 / 1023.0); // Convert analog reading to voltage
int temperatureC = (voltage - 0.5) * 100; // Assuming TMP36 sensor
return temperatureC;
}

void setup() {
Serial.begin(9600);
}

void loop() {
int temp = readTemperature(A0); // Call the function and store return value
Serial.print("Temperature: ");
Serial.print(temp);
Serial.println(" C");
delay(1000);
}

Code 2: Add Two Numbers and Use Result to Blink LED


int addNumbers(int a, int b) {
return a + b; // Return the sum
}

void setup() {
pinMode(13, OUTPUT);
}

void loop() {
int delayTime = addNumbers(200, 300); // Get delay time from function
digitalWrite(13, HIGH);
delay(delayTime);
digitalWrite(13, LOW);
delay(delayTime);
}

You might also like