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

Arduino UNO Controlled Traffic Light System with Joystick Interface

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

Traffic Light Control System Documentation

Summary

This document describes a circuit designed to control a traffic light system using an Arduino UNO and a joystick module. The traffic light system consists of three LEDs (Green, Yellow, and Red) that are controlled by the position of the joystick. The joystick module provides analog input to the Arduino, which then drives the LEDs based on the joystick's position. The system is designed to respond to the following joystick movements:

Component List

Arduino UNO

Traffic Light

Joystick Module

Wiring Details

Arduino UNO

Traffic Light

Joystick Module

Documented Code

/*
 * This Arduino sketch controls a traffic light system using a joystick module.
 * The traffic light has three LEDs: Green, Yellow, and Red. The joystick
 * module is used to control the LEDs as follows:
 * - Move joystick up: Red LED turns on
 * - Move joystick left: Yellow LED turns on
 * - Move joystick right: Green LED turns on
 * - Move joystick down: All LEDs turn on
 */

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

void setup() {
  // Initialize the LED pins as outputs
  pinMode(greenLEDPin, OUTPUT);
  pinMode(yellowLEDPin, OUTPUT);
  pinMode(redLEDPin, OUTPUT);
  // Initialize the joystick pins
  pinMode(joystickVRXPin, INPUT);
  pinMode(joystickVRYPin, INPUT);
  pinMode(joystickSWPin, INPUT_PULLUP);
}

void loop() {
  int xValue = analogRead(joystickVRXPin);
  int yValue = analogRead(joystickVRYPin);

  // Check joystick position
  if (yValue < 300) { // Joystick moved up
    digitalWrite(redLEDPin, HIGH);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, LOW);
  } else if (xValue < 300) { // Joystick moved left
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, HIGH);
    digitalWrite(greenLEDPin, LOW);
  } else if (xValue > 700) { // Joystick moved right
    digitalWrite(redLEDPin, LOW);
    digitalWrite(yellowLEDPin, LOW);
    digitalWrite(greenLEDPin, HIGH);
  } else if (yValue > 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);
  }
  delay(100); // Small delay to avoid flickering
}

This code is designed to be uploaded to the Arduino UNO microcontroller. It initializes the pins connected to the joystick and traffic light LEDs, reads the joystick's analog values, and sets the LEDs accordingly. The delay(100) function call is used to prevent flickering of the LEDs by introducing a small delay in the loop.