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

Arduino UNO and ADXL345-Based Digital Car Indicator System

View and Edit Project In Cirkit DesignerImage of Arduino UNO and ADXL345-Based Digital Car Indicator System

Circuit Documentation

Summary

This circuit is designed to control a digital car indicator system using an ADXL345 accelerometer and an Arduino UNO. The system detects the tilt of the car and activates the corresponding LED indicators. If the car tilts to the right, the right indicator LED turns on. If the car tilts to the left, the left indicator LED turns on. If there is no significant tilt, both LEDs remain off.

Component List

  1. Arduino UNO

    • Description: A microcontroller board based on the ATmega328P.
    • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0, A1, A2, A3, A4, A5, SCL, SDA, AREF, D13, D12, D11, D10, D9, D8, D7, D6, D5, D4, D3, D2, D1, D0
  2. ADXL345

    • Description: A 3-axis accelerometer.
    • Pins: GND, VCC, CS, INT1, INT2, SDO, SDA, SCL
  3. Resistor (200 Ohms)

    • Description: A resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2
  4. LED: Two Pin (red)

    • Description: A red LED with two pins.
    • Pins: cathode, anode
  5. LED: Two Pin (red)

    • Description: A red LED with two pins.
    • Pins: cathode, anode
  6. Resistor (200 Ohms)

    • Description: A resistor with a resistance of 200 Ohms.
    • Pins: pin1, pin2

Wiring Details

Arduino UNO

ADXL345

Resistor (200 Ohms)

Resistor (200 Ohms)

LED: Two Pin (red)

LED: Two Pin (red)

Code Documentation

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>

/*
 * This Arduino sketch is designed to control a digital car indicator system
 * using an ADXL345 accelerometer. The system detects the tilt of the car and
 * activates the corresponding LED indicators. If the car tilts to the right,
 * the right indicator LED turns on. If the car tilts to the left, the left
 * indicator LED turns on. If there is no significant tilt, both LEDs remain off.
 */

// Create an ADXL345 accelerometer object
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);

void setup() {
  // Initialize serial communication
  Serial.begin(9600);
  
  // Initialize the accelerometer
  if (!accel.begin()) {
    Serial.println("No ADXL345 detected");
    while (1);
  }
  
  // Set the range to +/- 4G
  accel.setRange(ADXL345_RANGE_4_G);
  
  // Initialize the LED pins
  pinMode(2, OUTPUT); // Left Indicator
  pinMode(3, OUTPUT); // Right Indicator
}

void loop() {
  // Get the accelerometer event
  sensors_event_t event;
  accel.getEvent(&event);
  
  // Check the tilt of the car
  if (event.acceleration.y > 1.0) {
    // Tilted to the right
    digitalWrite(2, LOW);  // Turn off left indicator
    digitalWrite(3, HIGH); // Turn on right indicator
  } else if (event.acceleration.y < -1.0) {
    // Tilted to the left
    digitalWrite(2, HIGH); // Turn on left indicator
    digitalWrite(3, LOW);  // Turn off right indicator
  } else {
    // No significant tilt
    digitalWrite(2, LOW);  // Turn off left indicator
    digitalWrite(3, LOW);  // Turn off right indicator
  }
  
  // Small delay to avoid rapid switching
  delay(100);
}

This code initializes the ADXL345 accelerometer and sets up the LED pins. In the main loop, it reads the accelerometer data and determines the tilt of the car. Based on the tilt, it turns on the appropriate LED indicator.