r/ArduinoProjects • • Dec 30 '23

Arduino code

I need help with a arduino code, i wanted to make a "Lie detektor" but it only makes the red led glow can some one help please.

// Include the necessary libraries
#include <LiquidCrystal.h>
// Define the pins used for the LCD, LED, and buzzer
const int lcd_rs = 12, lcd_en = 11, lcd_d4 = 5, lcd_d5 = 4, lcd_d6 = 3, lcd_d7 = 2;
const int red_led = 6;
const int green_led = 7;
const int buzzer = 8;
// Create an instance of the LCD
LiquidCrystal lcd(lcd_rs, lcd_en, lcd_d4, lcd_d5, lcd_d6, lcd_d7);
// Create a random number
int randomNumber = random(1, 2);
void setup() {
  // Initialize the LCD
lcd.begin(16, 2);

  // Initialize the pins
pinMode(red_led, OUTPUT);
pinMode(green_led, OUTPUT);
pinMode(buzzer, OUTPUT);
}
void loop() {
  // Check the random number
if (randomNumber == 1) {
// Turn on the red LED and buzzer
digitalWrite(red_led, HIGH);
digitalWrite(buzzer, HIGH);
delay(2000);
digitalWrite(buzzer, LOW);

// Display the message on the LCD
lcd.clear();
lcd.print("Du lugst");
  } else {
// Turn on the green LED
digitalWrite(green_led, HIGH);

// Display the message on the LCD
lcd.clear();
lcd.print("Du lugst nicht");
  }

delay(1000);
}    

1 Upvotes

8 comments sorted by

View all comments

1

u/[deleted] Dec 31 '23

I had some coding issues last week and I asked ChatGPT in Bing (they have the latest version). I explained the problem to it and gave my code. ChatGPT was surprisingly helpful and fast in helping me out, just a tip for if you run into coding issues further on in your learning.