// Program for attiny3216 to ambient light sensor 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); // sensor pin const int tp_pin = 4; 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() { int sensdata = analogRead(tp_pin); // read analogue data // Serial.print("Sensor reading: "); // Serial.println(sensdata); lcd.setCursor(12, 0); lcd.print(sensdata); // raw value // calculate light intensity float lint = sensdata * 0.0976; lcd.setCursor(12, 1); lcd.print(lint); // calculate illuminance, convert them to ADC float vout = (sensdata / 1024.0) * 5; float amm = vout / 10000.0; float mamm = amm * 1000000.0; float illu = mamm * 2.0; lcd.setCursor(12, 2); lcd.print((int)illu); 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("Intensity"); lcd.setCursor(11, 1); lcd.print(":"); lcd.setCursor(19, 1); lcd.print("%"); lcd.setCursor(0, 2); lcd.print("Illuminance"); lcd.setCursor(11, 2); lcd.print(":"); lcd.setCursor(17, 2); lcd.print("lux"); }