Rx Code:
`#include#include <Servo.h>
Servo myServo;
void setup() {
Serial.begin(9600);
myServo.attach(9);
delay(5000);
myServo.write(0);
}
void loop() {
while(Serial.available()==0);
int d = Serial.read() - '0';
if(d>0)
{
int pos = map(d,0,9,0,180);
pos = constrain(pos,0,180);
myServo.write(pos);
Serial.println(d);
delay(50);
}
else
{};
}
Tx code:
Tx code:
int sensorValue = 0; // the sensor value
int sensorMin = 1023; // minimum sensor value
int sensorMax = 0; // maximum sensor value
int SensorMid = 0;
const int POWER_OF_TWO_TO_AVERAGE = 6;
void setup() {
pinMode(13,OUTPUT);
Serial.begin(9600);
while (millis() < 10000) {
digitalWrite(13,HIGH);
sensorValue = analogRead(A1);
if (sensorValue > sensorMax) {
sensorMax = sensorValue;
}
if (sensorValue < sensorMin) {
sensorMin = sensorValue;
}
}
SensorMid = (sensorMin + sensorMax )/2;
digitalWrite(13,LOW);
}
void loop() {
int val = map(analogRead(A1),SensorMid,sensorMax,0,9);
Serial.println(val);
delay(100);
}
`
I am building a robotic arm and I am facing some problems regrading to the servos stability with the flex, I am using the flex as the transmitter and the servo as the receiver, and when I press my finger my servo doesn't move properly.
Any suggestions?