I am currently working on a prosthetic hand and I need a normal brushed DC motor to be able to spin for a set amount of time at a set speed. I am using arduino uno and L293d H-bridge. The control of the motor is based on a signal acquired from an sEMG sensor. I am new to working with arduino and would appreciate some help.
When I run the code, I receive these error messages:
move_motor_for_set_time:49:3: error: 'oldState' does not name a type
oldState = EMGsig;
^~~~~~~~
move_motor_for_set_time:50:3: error: expected unqualified-id before 'if'
if (digitalRead(Pin1 == HIGH))
^~
move_motor_for_set_time:61:3: error: 'Serial' does not name a type
Serial.print(EMGsig);Serial.print(" EMG reading, with voltage: ");Serial.println(voltage);
^~~~~~
move_motor_for_set_time:61:24: error: 'Serial' does not name a type
Serial.print(EMGsig);Serial.print(" EMG reading, with voltage: ");Serial.println(voltage);
^~~~~~
move_motor_for_set_time:61:69: error: 'Serial' does not name a type
Serial.print(EMGsig);Serial.print(" EMG reading, with voltage: ");Serial.println(voltage);
^~~~~~
move_motor_for_set_time:63:3: error: 'motorSpeed' does not name a type
motorSpeed = analogRead(potPin) / 4;
^~~~~~~~~~
move_motor_for_set_time:65:1: error: expected declaration before '}' token
}
^
exit status 1
'oldState' does not name a type
const int Pin1 = 12; // connected to pin 7 on the H-bridge
const int Pin2 = 11; // connected to pin 2 on the H-bridge
const int enablePin = 3; // connected to pin 1 on the H-bridge
const int potPin = A0; // connected to the potentiometer's output
int motorSpeed = 0; // speed of the motor
int threshold = 90; // Move the motor when EMG signal is above this threshold. Remember it ranges 0–1023.
int oldState = 0;
unsigned long startTime;
void setup()
{
Serial.begin(9600);
pinMode(Pin1, OUTPUT);
pinMode(Pin2, OUTPUT);
pinMode(enablePin, OUTPUT);
//pinMode(motorPin, OUTPUT);
//pinMode(sensorPin, INPUT);
}
//
void loop()
{
//int sensorState = digitalRead(sensorPin);
int EMGsig = analogRead(A5);
float voltage = EMGsig * (5.0 / 1023.0);
if (EMGsig > threshold) //voltage must be tuned according to sEMG output
{
if (oldState > threshold)
{
Serial.println("Button Pushed");
digitalWrite(Pin1, HIGH);
digitalWrite(Pin2, LOW);
analogWrite(enablePin, motorSpeed);
} // turns the motor on
startTime = millis();
}
}
oldState = EMGsig;
if (digitalRead(Pin1 == HIGH))
{
if (millis() - startTime >= 5000UL)
{
Serial.println("Timer Expired");
digitalWrite(Pin1, LOW);
digitalWrite(Pin2, HIGH);
analogWrite(enablePin, 0);
}
}
Serial.print(EMGsig);Serial.print(" EMG reading, with voltage: ");Serial.println(voltage);
motorSpeed = analogRead(potPin) / 4;
}```