0% found this document useful (0 votes)
16 views

Tugas Pak Rendyy

This document describes code for reading temperature data from an analog pin and displaying the average on an LCD screen. The code initializes an LCD screen using specific Arduino pins, takes 10 temperature samples over 1 second, calculates the average, and displays it on the LCD in Fahrenheit.

Uploaded by

Surya
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)
16 views

Tugas Pak Rendyy

This document describes code for reading temperature data from an analog pin and displaying the average on an LCD screen. The code initializes an LCD screen using specific Arduino pins, takes 10 temperature samples over 1 second, calculates the average, and displays it on the LCD in Fahrenheit.

Uploaded by

Surya
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/ 2

// Arduino pins used for LCD

LiquidCrystal lcd(8,9,4,5,6,7);

Void setup() {

Lcd.begin(16, 2);

Void loop() {

Float temperature = 0.0; // stores the calculated temperature

Int sample; // counts through ADC samples

Float ten_samples = 0.0; // stores sum of 10 samples

For (sample = 0; sample < 10; sample++) {

// convert A0 value to temperature

Temperature = ((float)analogRead(A0) * 5.0 / 1024.0) – 0.5;

Temperature = temperature / 0.01;

// sample every 0.1 seconds

Delay(100);

// sum of all samples

Ten_samples = ten_samples + temperature;

// get the average value of 10 temperatures

Temperature = ten_samples / 10.0;

// display the temperature on the LCD

Lcd.setCursor(0, 0);

Lcd.print(“Temperature:”);

Lcd.setCursor (0,1);
Lcd.print (temperature);

Lcd.print((char)223);

Lcd.print(“ F “);

Ten_samples = 0.0;

You might also like