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

Arduino UNO-Based Flex and Accelerometer Controlled Dual Servo System

View and Edit Project In Cirkit DesignerImage of Arduino UNO-Based Flex and Accelerometer Controlled Dual Servo System

Circuit Documentation

Summary

This circuit involves an Arduino UNO microcontroller interfacing with a variety of sensors and actuators. The components include a flex sensor, a triple-axis accelerometer, and two micro servos. The Arduino reads data from the sensors and controls the servos based on the sensor inputs. The flex sensor and accelerometer provide analog inputs to the Arduino, which then maps these inputs to control the angles of the servos.

Component List

Arduino UNO

Basic Flex Resistor

Micro Servo 9G (Servo 1)

Micro Servo 9G (Servo 2)

Triple Axis Accelerometer (ADXL335)

Resistor

Wiring Details

Arduino UNO

Basic Flex Resistor

Micro Servo 9G (Servo 1)

Micro Servo 9G (Servo 2)

Triple Axis Accelerometer (ADXL335)

Resistor

Code Documentation

#include <Servo.h>

Servo myServo1;
Servo myServo2;

const int flexPin = A3; // Flex sensor connected to A3
const int servoPin1 = 9; // Servo 1 connected to digital pin 9
const int servoPin2 = 10; // Servo 2 connected to digital pin 10
const int xAxisPin = A0; // Accelerometer X-axis connected to A0

void setup() {
  Serial.begin(9600); // Start the serial communication at 9600 baud rate
  myServo1.attach(servoPin1); // Attach servo 1 to pin 9
  myServo2.attach(servoPin2); // Attach servo 2 to pin 10
}

void loop() {
  // Read flex sensor value
  int flexValue = analogRead(flexPin);
  Serial.print("Flex Value: "); // Print flex sensor value
  Serial.println(flexValue);

  // Map flex sensor value to servo angle (0-180 degrees)
  int servoAngle1 = map(flexValue, 0, 1023, 0, 180);
  myServo1.write(servoAngle1); // Move servo 1 based on flex sensor

  // Read accelerometer X-axis value
  int xAxisValue = analogRead(xAxisPin);
  Serial.print("X-Axis Value: "); // Print accelerometer X-axis value
  Serial.println(xAxisValue);

  // Map accelerometer X-axis value to servo angle (0-180 degrees)
  int servoAngle2 = map(xAxisValue, 0, 1023, 0, 180);
  myServo2.write(servoAngle2); // Move servo 2 based on X-axis input

  delay(15); // Short delay for stability
}

This code initializes two servos and reads values from a flex sensor and an accelerometer. The flex sensor value is mapped to control the angle of the first servo, and the X-axis value of the accelerometer is mapped to control the angle of the second servo. The values are also printed to the serial monitor for debugging purposes.