const int tmp36Pin = A0; // TMP36 sensor is connected to analog pin A0
const int ledPin = 7; // LED is connected to digital pin 7
const float thresholdTemp = 40.0; // Temperature threshold in Celsius
void setup() {
Serial.begin(9600); // Start serial communication
pinMode(ledPin, OUTPUT); // Set LED pin as OUTPUT
void loop() {
int reading = analogRead(tmp36Pin); // Read the analog value from TMP36
float voltage = reading * (5.0 / 1023.0); // Convert analog value to voltage
float temperatureC = (voltage - 0.5) * 100.0; // Convert voltage to Celsius
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.println(" °C"); // Print temperature in Celsius
// Check if the temperature exceeds the threshold
if (temperatureC > thresholdTemp) {
digitalWrite(ledPin, HIGH); // Turn ON LED
Serial.println("Warning: High Temperature! LED ON.");
} else {
digitalWrite(ledPin, LOW); // Turn OFF LED
delay(1000); // Wait for 1 second before reading again
const int sensorPin = A0; // TMP36 sensor is connected to analog pin A0
void setup() {
Serial.begin(9600); // Start serial communication at 9600 baud
void loop() {
int reading = analogRead(sensorPin); // Read the analog value from TMP36
// Convert the analog reading to voltage
float voltage = reading * (5.0 / 1023.0); // Use 3.3V if applicable
// Convert voltage to temperature in Celsius
float temperatureC = (voltage - 0.5) * 100.0;
// Convert Celsius to Fahrenheit
float temperatureF = (temperatureC * 9.0 / 5.0) + 32.0;
// Print temperature values
Serial.print("Temperature: ");
Serial.print(temperatureC);
Serial.print(" °C | "); // Display degree symbol
Serial.print(temperatureF);
Serial.println(" °F"); // Display Fahrenheit reading
delay(1000); // Wait for 1 second before reading again
const int ledPins[] = {2, 3, 4, 5}; // Define LED pins
const int numLeds = 4; // Number of LEDs
const int delayTime = 500; // Delay time in milliseconds
void setup() {
// Set each LED pin as OUTPUT
for (int i = 0; i < numLeds; i++) {
pinMode(ledPins[i], OUTPUT);
void loop() {
// Loop through each LED, turning one on at a time
for (int i = 0; i < numLeds; i++) {
digitalWrite(ledPins[i], HIGH); // Turn on the current LED
delay(delayTime); // Wait
digitalWrite(ledPins[i], LOW); // Turn off the current LED
const int ledPin = 13; // LED is connected to digital pin 13
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as OUTPUT
}
void loop() {
digitalWrite(ledPin, HIGH); // Turn ON the LED
delay(1000); // Wait for 1 second
digitalWrite(ledPin, LOW); // Turn OFF the LED
delay(1000); // Wait for 1 second
const int ledPin = 9; // LED connected to pin 9 with a 150Ω resistor
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
void loop() {
digitalWrite(ledPin, HIGH); // Turn ON the LED
delay(1000); // Wait for 1 second
digitalWrite(ledPin, LOW); // Turn OFF the LED
delay(1000); // Wait for 1 second
}
const int ledPin = 9; // LED connected to digital pin 9
void setup() {
pinMode(ledPin, OUTPUT); // Set the LED pin as OUTPUT
digitalWrite(ledPin, HIGH); // Turn ON the LED
void loop() {
// No need to include anything in the loop since the LED remains ON