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

Int Int Float Float Void Setup Pinmode Serial Begin

This code uses an analog input pin to read the value from a temperature sensor connected to an Arduino. It turns an LED on and off for a duration corresponding to the sensor reading in each loop iteration. The reading is also printed to the serial monitor along with the calculated temperature in Celsius.

Uploaded by

Aditya Jabar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views1 page

Int Int Float Float Void Setup Pinmode Serial Begin

This code uses an analog input pin to read the value from a temperature sensor connected to an Arduino. It turns an LED on and off for a duration corresponding to the sensor reading in each loop iteration. The reading is also printed to the serial monitor along with the calculated temperature in Celsius.

Uploaded by

Aditya Jabar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

/*

* AnalogInput
* by DojoDave <http://www.0j0.org>
*
* Modified for Graduate Student Workshop
* by David Rogerson - Physics Electronics Resource Center, University of Toro
nto
*
* Turns on and off a light emitting diode(LED) connected to digital
* pin 10. The amount of time the LED will be on and off depends on
* the value obtained by analogRead(). In this instance we are using a LM35
* temperature sensor
*
*/
int tempPin = 0;
int ledPin = 10;
float val = 0;
float temp = 0;

//
//
//
//

select the input pin for the analog input


select the pin for the LED
variable to store the value coming from the sensor
holds the calculated celsius value for display

void setup() {
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
}

// declare the led pin as an OUTPUT

void loop() {
val = analogRead(tempPin);
digitalWrite(ledPin, HIGH);
delay(val);
digitalWrite(ledPin, LOW);
delay(val);

// read the value from the sensor


//
//
//
//

turn
stop
turn
stop

the
the
the
the

led pin
program
led pin
program

on
for some time
off
for some time

/*
* Full scale temp (1023) is 40 degrees and bottom scale (0) is 10 degrees
* Celsius value is then the temp range (30) times the a/d value divided
* by the full scale a/d value plus 10 degrees (a/d zero value)
*/
temp = 30 * val / 1023 + 10; // Convert the reading to Celsius value
Serial.println( "A/D val & Temp in C");
Celsius value
Serial.println( val, 0 );
Serial.println( temp, 1 );
decimal pt
Serial.println("");
}

// Print the reading and the


// Print the a/d val as an integer
// print the celsius value to 1

You might also like