I am wondering if you guys can help me write a code. I am building electronic Racquet string tensioner. Basically it is servo motor pulling string over load cell. I would press push button and motor would move in one direction. When it reaches certain tension motor should stop. Then I would press push button and motor would go back to starting point. Ideally after motor stop and for whatever reason tension start getting lose motor should continue till it reaches certain tension. I would like to be able to adjust point where motor stops (certain tension), with potentiometer. Also would be great to adjust motor speed with potentiometer. I got mechanical tensionmeter. Before stringing racquet I would play with potentiometer till I get tension I want on mechanical tensionmeter. That would be point where motor stops. I have purchased:
Arduino Nano
Can you please help me write this code since I dont have that much knowledge about programming arduino, or if you can point me in right direction. These Electronic tension heads are over $500 and this project would definitely help a lot of people. Thanks in advance
Write separate short programs while you learn about each item - moving the motor, reading a button, reading the load cell etc. When you know how to do each piece separately it will be time to join them together into a complete project.
I have decided to use wiper motor since it has a lot of torque. Instead of load cell i decided to controll torque using ACS712 5A hall sensor. Basically when motor exceeds certain value of amps arduino will tell motor to stop. Here is the code I wrote but didnt get chance to test it. can you please tell me if there is better way to work more accurate or better code than this. I am just a beginer with arduino and every help would be appreciated. thanks in advance. Here is the code:
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
int sensorValue1 = analogRead(A0);
int sensorValue2 = analogRead(A0);
int sensorValue3 = analogRead(A0);
int ledPin = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(13, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(ledPin, LOW);
float voltage = sensorValue * (5.0 / 1023.0);
delay(1);
float voltage1 = sensorValue1 * (5.0 / 1023.0);
delay(1);
float voltage2 = sensorValue2 * (5.0 / 1023.0);
delay(1);
float voltage3 = sensorValue3 * (5.0 / 1023.0);
delay(1);
float voltageavg = ((sensorValue + sensorValue1 + sensorValue2 + sensorValue3)/4);
// print out the value you read:
Serial.println(voltageavg);
if (voltageavg>1.9){
digitalWrite(ledPin,HIGH);
}
delay(1000);
}
Hi,
Using motor current to estimate torque is not a good idea, as gearbox and bearing friction will not necessarily be constant.
The youtube presentation by the looks of it, has the motor base hinged and spring mounted, the spring contracts as the tension increase and there would be a microswitch placed to trip the motor stop.
The side adjustment moves the switch for different travel/force of the motor base, hence string tension.
So it has no electronics as such.
A wiper motor would be a good idea, because of the torque and most are worm drive so will not run backwards under tension when power is removed.
UKHeliBob:
Use a for loop to run the repeated code 4 times, adding the new voltage reading to the total on each iteration.
I'm not sure that will work in this case. I think they are 4 separate readings.
bovegas:
Here is the code I wrote but didnt get chance to test it. can you please tell me if there is better way to work more accurate or better code than this
Test it first. Then you can tell us whether it achieves your goals or not.
Here is the code that seems to work, providing constant pull on strings at certain torque. I am not sure if this are 4 separate readings since I am beginner. Is there maybe better way to write this code? Also, I would like to add potentiometer to change threshold value. In this case threshold value is 2.90 set in this line:
if (voltageavg>2.9){
How can I implement potentiometer in order to change this value, since I would like to be able to change desired tension without hooking to computer
here is the code that seems to work:
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
int ledPin = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(ledPin, LOW);
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
delay(1);
int sensorValue1 = analogRead(A0);
float voltage1 = sensorValue1 * (5.0 / 1023.0);
delay(1);
int sensorValue2 = analogRead(A0);
float voltage2 = sensorValue2 * (5.0 / 1023.0);
delay(1);
int sensorValue3 = analogRead(A0);
float voltage3 = sensorValue3 * (5.0 / 1023.0);
delay(1);
float voltageavg = ((voltage + voltage1 + voltage2 + voltage3)/4);
// print out the value you read:
Serial.println(voltageavg);
if (voltageavg>2.9){
digitalWrite(ledPin,HIGH);
delay(1);
digitalWrite(ledPin,LOW);
}
delay(1);
}
Thank you so much for reply. I have edited posts like you advised. Wasn't sure at first how to do that. Can you please implement reply at #10 in my code since I am not sure how to do that. Thanks a lot in advance. Here is the code:
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
int ledPin = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(ledPin, LOW);
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
delay(1);
int sensorValue1 = analogRead(A0);
float voltage1 = sensorValue1 * (5.0 / 1023.0);
delay(1);
int sensorValue2 = analogRead(A0);
float voltage2 = sensorValue2 * (5.0 / 1023.0);
delay(1);
int sensorValue3 = analogRead(A0);
float voltage3 = sensorValue3 * (5.0 / 1023.0);
delay(1);
float voltageavg = ((voltage + voltage1 + voltage2 + voltage3)/4);
// print out the value you read:
Serial.println(voltageavg);
if (voltageavg>2.9){
digitalWrite(ledPin,HIGH);
delay(1);
digitalWrite(ledPin,LOW);
}
delay(1);
}
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
int ledPin = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
digitalWrite(ledPin, LOW);
// read the input on analog pin 0:
void loop()
{
float totalVoltage = 0.0;
for (int reading = 0; reading < 4; reading++)
{
totalVoltage += (analogRead(0) * (5.0 / 1023.0) );
delay(1);
}
}
float avgVoltage = totalVoltage / 4;
delay(1);
void loop()
{
float totalVoltage = 0.0;
for (int reading = 0; reading < 4; reading++)
{
totalVoltage += (analogRead(0) * (5.0 / 1023.0) );
delay(1);
}
}
float avgVoltage = totalVoltage / 4;
delay(1);
void loop()
{
float totalVoltage = 0.0;
for (int reading = 0; reading < 4; reading++)
{
totalVoltage += (analogRead(0) * (5.0 / 1023.0) );
delay(1);
}
}
float avgVoltage = totalVoltage / 4;
delay(1);
void loop()
{
float totalVoltage = 0.0;
for (int reading = 0; reading < 4; reading++)
{
totalVoltage += (analogRead(0) * (5.0 / 1023.0) );
delay(1);
}
}
float avgVoltage = totalVoltage / 4;
delay(1);
// print out the value you read:
Serial.println(voltageavg);
if (voltageavg>2.9){
digitalWrite(ledPin,HIGH);
delay(1);
digitalWrite(ledPin,LOW);
}
delay(1);
}
You can only have one loop() function in a program
Try this
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
int ledPin = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop()
{
digitalWrite(ledPin, LOW);
float totalVoltage = 0.0;
for (int reading = 0; reading < 4; reading++) //read the voltage 4 times
{
totalVoltage += (analogRead(0) * (5.0 / 1023.0) ); //add to the running total
delay(1);
}
float voltageavg = totalVoltage / 4;
Serial.println(voltageavg);
if (voltageavg > 2.9)
{
digitalWrite(ledPin, HIGH);
delay(1);
digitalWrite(ledPin, LOW);
}
delay(1);
}
Thank you so much for help. I was able to run it and also I implemented potentiometer so I can adjust threshold(desired tension). Basically I would use digital luggage scale to find desired tension with potentiometer, and I would continue to string. This way I would basically calibrate stringer each time when i string. Here is complete code:
/*
ReadAnalogVoltage
Reads an analog input on pin 0, converts it to voltage, and prints the result to the serial monitor.
Graphical representation is available using serial plotter (Tools > Serial Plotter menu)
Attach the center pin of a potentiometer to pin A0, and the outside pins to +5V and ground.
This example code is in the public domain.
*/
int ledPin = 13;
// the setup routine runs once when you press reset:
const int analogPin1 = A1;
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(ledPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop()
{
int potValue = analogRead(analogPin1);
float threshold = potValue * (5.0 / 1023.0);
Serial.println(threshold);
delay(1);
digitalWrite(ledPin, LOW);
float totalVoltage = 0.0;
for (int reading = 0; reading < 4; reading++) //read the voltage 4 times
{
totalVoltage += (analogRead(0) * (5.0 / 1023.0) ); //add to the running total
delay(1);
}
float voltageavg = totalVoltage / 4;
Serial.println(voltageavg);
if (voltageavg > threshold)
{
digitalWrite(ledPin, HIGH);
delay(1);
digitalWrite(ledPin, LOW);
}
delay(1);
}