Cirkit Designer Logo
Cirkit Designer
Your all-in-one circuit design IDE
Home / 
Project Documentation

Arduino-Controlled Servo with EMG Sensor Activation

Image of Arduino-Controlled Servo with EMG Sensor Activation

Circuit Documentation

Summary of the Circuit

The circuit in question is designed to interface an EMG sensor with an Arduino UNO microcontroller to read muscle activity signals. The signal from the EMG sensor is used to control a servo motor based on a threshold value. Additionally, the circuit includes a pushbutton to ground and two 9V batteries to power the EMG sensor. The Arduino UNO is programmed to read the EMG sensor's output and control the servo motor accordingly. The code also includes functionality to adjust the threshold value using two buttons (not explicitly mentioned in the parts list but inferred from the code) and display the current threshold on an LCD, which is not included in the parts list but is referenced in the code.

Component List

EMG Sensor

  • Pins: +Vs, GND, -Vs, SIG
  • Description: A sensor that detects electrical activity in muscles.

Servo

  • Pins: gnd, vcc, pulse
  • Description: An actuator that can be precisely controlled in terms of how much it rotates.

Arduino UNO

  • Pins: UNUSED, IOREF, Reset, 3.3V, 5V, GND, Vin, A0-A5, SCL, SDA, AREF, D0-D13
  • Description: A microcontroller board based on the ATmega328P, widely used for building digital devices and interactive objects.

Pushbutton

  • Pins: Pin 1, Pin 2, Pin 3, Pin 4
  • Description: A simple switch mechanism for controlling some aspect of a machine or a process.

9V Batteries (x2)

  • Pins: +, -
  • Description: Standard 9V batteries used to provide power to the circuit.

Wiring Details

EMG Sensor

  • +Vs connected to + of a 9V battery.
  • GND connected to GND of Arduino UNO and - of a 9V battery.
  • -Vs connected to - of a 9V battery.
  • SIG connected to A0 of Arduino UNO.

Servo

  • gnd connected to GND of Arduino UNO.
  • vcc connected to 5V of Arduino UNO.
  • pulse connected to D3 of Arduino UNO.

Arduino UNO

  • GND connected to GND of EMG Sensor and Pin 2 of Pushbutton.
  • 5V connected to vcc of Servo.
  • A0 connected to SIG of EMG Sensor.
  • D2 connected to Pin 3 of Pushbutton.
  • D3 connected to pulse of Servo.

Pushbutton

  • Pin 2 connected to GND of Arduino UNO.
  • Pin 3 connected to D2 of Arduino UNO.

9V Batteries

  • + of one battery connected to +Vs of EMG Sensor.
  • - of the same battery connected to GND of EMG Sensor.
  • + of the other battery connected to GND of EMG Sensor.
  • - of the other battery connected to -Vs of EMG Sensor.

Documented Code

#include <Servo.h>
#include <Wire.h>  // Include the Wire library for I2C communication
#include <LiquidCrystal_I2C.h>  // Include the LiquidCrystal I2C library

#define THRESHOLD_MAX 1023  // Maximum threshold value
#define THRESHOLD_MIN 0     // Minimum threshold value

#define EMG_PIN 0           // Analog pin for muscle sensor
#define SERVO_PIN 3         // Digital PWM pin for servo

#define BUTTON_INC A1       // Analog pin for increasing threshold button
#define BUTTON_DEC A2       // Analog pin for decreasing threshold button

Servo SERVO_1;

// Set the LCD address to 0x27 for a 16x2 display
// You may need to change this address if your module has a different address
LiquidCrystal_I2C lcd(0x27, 16, 2);

int threshold = 250;  // Initial threshold value

void setup() {
  Serial.begin(115200);
  SERVO_1.attach(SERVO_PIN);
  
  // Initialize the LCD
  lcd.init();
  lcd.backlight();  // Turn on the backlight
  lcd.setCursor(0, 0);
  lcd.print("Threshold:");
  lcd.setCursor(0, 1);
  lcd.print(threshold);
}

void loop() {
  int value = analogRead(EMG_PIN);

  if (value > threshold) {
    SERVO_1.write(170);
  } else {
    SERVO_1.write(10);
  }

  Serial.println(value);

  // Check if the increase threshold button is pressed
  if (analogRead(BUTTON_INC) < 100) {
    threshold += 10;  // Increase threshold value by 10
    if (threshold > THRESHOLD_MAX) {
      threshold = THRESHOLD_MAX;
    }
    updateLCD();  // Update LCD display with new threshold value
    delay(200);  // Debounce delay
  }

  // Check if the decrease threshold button is pressed
  if (analogRead(BUTTON_DEC) < 100) {
    threshold -= 10;  // Decrease threshold value by 10
    if (threshold < THRESHOLD_MIN) {
      threshold = THRESHOLD_MIN;
    }
    updateLCD();  // Update LCD display with new threshold value
    delay(200);  // Debounce delay
  }
}

void updateLCD() {
  lcd.setCursor(10, 1);
  lcd.print("   ");  // Clear previous threshold value
  lcd.setCursor(10, 1);
  lcd.print(threshold);
}

Note: The code includes references to an LCD and buttons for increasing and decreasing the threshold, which are not listed in the provided parts list. These components should be added to the circuit and connected appropriately to the Arduino UNO for the code to function as intended.