Nano with I2C LCD and 6 LEDs — Arduino Nano simulation

Arduino Nano project with a 16x2 I2C LCD (address 0x27) and six LEDs on pins 2-7, each with a 1k series resistor.

An interactive Arduino Nano circuit simulation you can run free in your browser on Velxio, by mashiyo272.

Components

Sketch code

#include <LiquidCrystal.h>

// LCD Pins: RS, E, D4, D5, D6, D7
LiquidCrystal lcd(8, 9, 10, 11, 12, 13);

// Traffic Light LEDs
const int R1 = 2;
const int Y1 = 3;
const int G1 = 4;

const int R2 = 5;
const int Y2 = 6;
const int G2 = 7;

void setup() {
  pinMode(R1, OUTPUT);
  pinMode(Y1, OUTPUT);
  pinMode(G1, OUTPUT);

  pinMode(R2, OUTPUT);
  pinMode(Y2, OUTPUT);
  pinMode(G2, OUTPUT);

  Serial.begin(9600);

  lcd.begin(16, 2);
  lcd.print("Traffic Light");
  lcd.setCursor(0, 1);
  lcd.print("System Ready");
  delay(2000);
  lcd.clear();
}

void loop() {

  // Road 1 Green
  digitalWrite(R1, LOW);
  digitalWrite(Y1, LOW);
  digitalWrite(G1, HIGH);

  digitalWrite(R2, HIGH);
  digitalWrite(Y2, LOW);
  digitalWrite(G2, LOW);

  Serial.println("Road 1 GREEN | Road 2 RED");

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Road1: GREEN");
  lcd.setCursor(0, 1);
  lcd.print("Road2: RED");
  delay(5000);

  // Road 1 Yellow
  digitalWrite(G1, LOW);
  digitalWrite(Y1, HIGH);

  Serial.println("Road 1 YELLOW | Road 2 RED");

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Road1:YELLOW");
  lcd.setCursor(0, 1);
  lcd.print("Road2: RED");
  delay(2000);

  // Road 2 Green
  digitalWrite(Y1, LOW);
  digitalWrite(R1, HIGH);

  digitalWrite(R2, LOW);
  digitalWrite(G2, HIGH);

  Serial.println("Road 1 RED | Road 2 GREEN");

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Road1: RED");
  lcd.setCursor(0, 1);
  lcd.print("Road2: GREEN");
  delay(5000);

  // Road 2 Yellow
  digitalWrite(G2, LOW);
  digitalWrite(Y2, HIGH);

  Serial.println("Road 1 RED | Road 2 YELLOW");

  lcd.clear();
  lcd.setCursor(0, 0);
  lcd.print("Road1: RED");
  lcd.setCursor(0, 1);
  lcd.print("Road2:YELLOW");
  delay(2000);

  digitalWrite(Y2, LOW);
}

More projects by mashiyo272