// Program for attiny3216 to read LM35 and display it on 4x20 LCD liquid crystal // created by Jans Hendry // Universitas Gadjah Mada, Indonesia // Kamakura Node, Japan // fab academy MIT - 2022 // the directives/predecessor #include #include // create lcd as an object // format: address, num of columns, num of rows LiquidCrystal_I2C lcd(0x27, 20, 4); #define vref 4000 // voltage ref according to vcc #define adcres 1024.0 // adc resolution #define mv 10 // 1oc = 10 mv #define tp_pin 4 // sensor pin void setup() { // start serial Serial.begin(9600); // setting up lcd.init(); // turn on backlight <- the variable resistor has been adjusted lcd.backlight(); // clear screen lcd.clear(); // static display defDisplay(); // delay delay(500); } void loop() { // read analogue data (lm35 temperature sensor); int sensdata = analogRead(tp_pin); // Serial.print("Sensor reading: "); // Serial.println(sensdata); // convert to celcius float vt = (sensdata / adcres) * vref; // voltage to be converted float suhu = (vt / mv); // celcius temperature // Serial.print("Voltage out: "); // Serial.println(vt); // Serial.print("Temperature (oC): "); // Serial.println(suhu); lcd.setCursor(12, 0); lcd.print(sensdata); // raw value lcd.setCursor(12, 1); lcd.print((int)suhu); // write temperature to LCD send_sign(suhu); // turn light indicator delay(1000); // take a break every 1 second } void defDisplay() { lcd.clear(); // clear display // static text lcd.setCursor(0, 0); lcd.print("Read-out "); lcd.setCursor(11, 0); lcd.print(":"); lcd.setCursor(0, 1); lcd.print("Temperature: "); lcd.setCursor(16, 1); lcd.print("oC"); lcd.setCursor(0, 2); lcd.print("Status"); lcd.setCursor(11, 2); lcd.print(":"); } int send_sign(float tmp) { // turn light lcd.setCursor(12, 2); if (tmp >= 35) { lcd.print("HOT"); } else if (tmp >= 30) { lcd.print("WARM"); } else { lcd.print("EASY"); } return 0; }