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.
#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.