Cirkit Designer LogoCirkit DesignerYour all-in-one circuit design IDE Launch Cirkit Designer App

Arduino-Controlled Traffic Light System with Joystick Interface

View and Edit Project In Cirkit DesignerImage of Arduino-Controlled Traffic Light System with Joystick Interface

Traffic Light Control System Documentation

Summary

This document describes a traffic light control system that is operated using an Arduino UNO microcontroller and a joystick module. The system allows for the control of a traffic light with three LEDs (red, yellow, and green) through the manipulation of the joystick. The joystick's movements are mapped to specific traffic light states: moving the joystick up activates the red LED, left for the yellow LED, right for the green LED, and down for all LEDs. The system is designed for educational purposes to demonstrate basic digital input/output control with an Arduino.

Component List

Traffic Light

Arduino UNO

Joystick Module

Wiring Details

Traffic Light

Arduino UNO

Joystick Module

Documented Code

/*
 * This Arduino sketch controls a traffic light system using a joystick module.
 * - Moving the joystick up turns on the red LED.
 * - Moving the joystick left turns on the yellow LED.
 * - Moving the joystick right turns on the green LED.
 * - Moving the joystick down turns on all LEDs.
 */

const int redLEDPin = 2;
const int yellowLEDPin = 3;
const int greenLEDPin = 4;
const int joystickSWPin = 7;
const int joystickVRXPin = A0;
const int joystickVRYPin = A1;

void setup() {
  pinMode(redLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(greenLEDPin, OUTPUT);
  pinMode(joystickSWPin, INPUT);
  pinMode(joystickVRXPin, INPUT);
  pinMode(joystickVRYPin, INPUT);
}

void loop() {
  int vrxValue = analogRead(joystickVRXPin);
  int vryValue = analogRead(joystickVRYPin);

  if (vryValue < 300) { // Joystick moved up
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, LOW);
  } else if (vrxValue < 300) { // Joystick moved left
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(greenLEDPin, LOW);
  } else if (vrxValue > 700) { // Joystick moved right
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, HIGH);
  } else if (vryValue > 700) { // Joystick moved down
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(greenLEDPin, HIGH);
  } else { // Joystick in neutral position
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, LOW);
  }
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the traffic light LEDs and the joystick module as inputs or outputs in the setup() function. The loop() function continuously reads the joystick's position and updates the state of the traffic light LEDs accordingly.