Error: expected '}' at end of input exit status 1

hello i'm a newbie practicing programming on arduino,i can't solve my problem,it keep error: expected '}' at end of input
exit status 1

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x27, 16, 2);
const int sensor_gas = 12; // sensor gas Mq2 -> pin 12
const int buzzer = 11; // Buzzer -> pin 11
const int led_hijau = 10; // LED hijau -> pin 10
const int led_merah = 9; // LED merah -> pin 9

void setup()
{

lcd.init();
lcd.backlight();
lcd.clear();
pinMode (sensor_gas, INPUT); // sensor Mq-05 sebagai input
pinMode (buzzer, OUTPUT); // Buzzer sebagai Output
pinMode (led_hijau, OUTPUT); // LED hijau sebagai Output
pinMode (led_merah, OUTPUT); // LED merah sebagai Output

lcd.print(" TUGAS SISTEM SENSOR "); // menampilkan tugas akhir baris pertama di led
lcd.setCursor(0,1);
lcd.print(" SISTEM SENSOR ");// menampilkan Nama Prodi pada baris Kedua di LCD
lcd.setCursor(0,0);
delay(2000); // Lamanya waktu yang dibutuhkan
lcd.print(" KELOMPOK 2 "); // menampilkan nama pada baris pertama di LCD
lcd.setCursor(0,1);
lcd.print(" TUGAS UAS ");// menampilkan NIM pada baris Kedua di LCD
delay (3000); // Lamanya waktu yang dibutuhkan untuk menampilkan nama dan NIM

}

void loop()
{
int nilai = digitalRead(sensor_gas);
if (nilai == LOW)
{
digitalWrite(buzzer,HIGH); // buzzer akan berbunyi jika ada kebocoran gas
lcd.setCursor(0, 0);
lcd.print("Kondisi Ruangan: "); // Menampilkan Kondisi Ruang di LCD
lcd.setCursor(0, 1);
lcd.print("DANGER, Gas Leak"); // Jika ada kebocoran maka akan muncul di LCD
tone(buzzer, 1000,200); // frekuensi buzzer ketika berbunyi
digitalWrite(led_hijau,LOW);
digitalWrite(led_merah,HIGH); // LED merah akan menyala jika ada indikasi Gas bocor
}
if (nilai == HIGH)
{
digitalWrite(buzzer,LOW);
lcd.setCursor(0, 0);

Welcome to the forum

Please follow the advice given in the link below when posting code, in particular the section entitled 'Posting code and common code problems'

Use code tags (the < CODE/ > icon above the compose window) to make it easier to read and copy for examination

https://forum.arduino.cc/t/how-to-get-the-best-out-of-this-forum

In my experience the easiest way to tidy up the code and add the code tags is as follows
Start by tidying up your code by using Tools/Auto Format in the IDE to make it easier to read. Then use Edit/Copy for Forum and paste what was copied in a new reply. Code tags will have been added to the code to make it easy to read in the forum thus making it easier to provide help.

The last thing in a sketch must be the closing brace of the last function in the sketch. Your sketch does not have such a closing brace

This would be obvious if you used Auto Format in the IDE

Actually your sketch as posted is missing at least 2 closing braces. Didi you post your complete sketch ?

1 Like

Although you posted your code without following the forum rules, I was able to see that at the end of your code there are 2 missing closing curly braces. } } .

1 Like