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

Arduino Mega 2560 Controlled Ultrasonic Sensor Array with Multi-Color LED Indicators

View and Edit Project In Cirkit DesignerImage of Arduino Mega 2560 Controlled Ultrasonic Sensor Array with Multi-Color LED Indicators

Circuit Documentation

Summary

The circuit in question is designed to interface an array of LEDs and multiple HC-SR04 Ultrasonic Sensors with an Arduino Mega 2560 microcontroller. The HC-SR04 sensors are used to measure distances via ultrasonic waves, and the LEDs serve as indicators. The Arduino Mega 2560 controls the sensors and LEDs, and it also handles serial communication to receive data and check its validity using a parity bit.

Component List

Microcontroller

Sensors

Indicators

Wiring Details

Arduino Mega 2560

HC-SR04 Ultrasonic Sensors

LEDs (Red, Green, Yellow)

Documented Code

File: sketch.ino

void setup() {
  Serial.begin(9600);  // Initialize Serial communication for receiver
}

void loop() {
  if (Serial.available() > 0) { // Check if data is received
    String receivedData = Serial.readStringUntil('\n'); // Read data
    receivedData.trim(); // Remove any unwanted trailing characters
    Serial.println("Received Data: " + receivedData);

    if (isValid(receivedData)) {
      Serial.println("Data is valid!");
    } else {
      Serial.println("Error detected in the received data!");
    }
  }
}

// Function to check the validity of received data using parity bit
bool isValid(String data) {
  int onesCount = 0;
  for (int i = 0; i < data.length() - 1; i++) { // Exclude the parity bit
    if (data[i] == '1') onesCount++;
  }
  char expectedParity = (onesCount % 2 == 0) ? '0' : '1'; // Calculate expected parity
  return data[data.length() - 1] == expectedParity; // Compare parity bit
}

File: documentation.txt

The second file, documentation.txt, does not contain any code. It is likely intended to be a placeholder for additional documentation or notes related to the project.