Project 9.00 Using the Temp Sensor

This Arduino sketch reads the analog value from a temperature sensor connected to analog pin A3 and prints the temperature value (represented by the analog reading) to the serial monitor!

In this project you’ll 睡衣图片 how to read the voltage produced by the temperature sensor. The temperature sensor on the MC Trainer is tiny! It is the tiny black rectangle on the left of the OLED, above the reset button.

Project Code:

				
					//////////////////////////////////////////////////////
// 9.00 - Using the Temperature Sensor

byte tempSensorPin = A3;

void setup() {
  pinMode(tempSensorPin, INPUT);
  Serial.begin(9600);
}

void loop() {
  int currentTemp = analogRead(tempSensorPin);

  Serial.print("The current temp value is: "); Serial.println(currentTemp);
  delay(1000);

}
//////////////////////////////////////////////////////
				
			

*If you’re copying and pasting the code, or typing from scratch, delete everything out of a new Arduino sketch and paste / type in the above text.

The temperature sensor works a lot like the potentiometer and LDR. The difference is that this temperature sensor actually produces a voltage based on the temperature. The potentiometer and LDR were dropping a certain amount of voltage based on some condition.

The temperature sensor again produces an analog voltage based on the temperature. This means that if we want to read that analog value it needs to be on an analog pin. The temperature sensor is connected to the analog pin A3 on the MC Trainer.

				
					byte tempSensorPin = A3;
				
			

We are reading the voltage, so the pin is an INPUT.

				
					pinMode(tempSensorPin, INPUT);
				
			

In the loop() function, we analog read the voltage produced by the temperature sensor.

				
					int currentTemp = analogRead(tempSensorPin);
				
			

After that, we print it onto the Serial port. Make sure to open the Serial port to see the data being printed.

				
					Serial.print("The current temp value is: "); Serial.println(currentTemp);
				
			

So that we don’t flood the screen we add in a one second delay.

				
					delay(1000);
				
			

Try touching the temperature sensor and seeing how the values change.

睡衣图片 More In Our Free Instructional Guidebook

This comprehensive guidebook for the 睡衣图片 狼群视频在线观看 Trainer provides a comprehensive introduction to the world of Arduino programming for beginners. It guides users through the foundational concepts of 狼群视频在线观看s, detailing the unique features of the Arduino Leonardo-compatible MCU Trainer board. The manual offers a step-by-step journey from understanding the hardware components and the Arduino programming language to the vibrant global community of Arduino enthusiasts. It delves into the intricacies of each onboard circuit, explaining their functionalities and applications. With a focus on hands-on 睡衣图片ing, the manual includes a series of coding exercises, tutorials in C/C++, and insights into the Arduino IDE.

More Projects

Project 1.00 Blink

In this project, you’ll 睡衣图片 how to blink an LED!

Project 1.01 Blink x2

In this project, you’ll 睡衣图片 how to blink more than one LED!