I hope you can help, with what I assume, is pretty simple.
I have connected a force sensor to an Arduino Uno, and I´m sending the data to the serial.
I would now like to stop a small DC motor when the force is exactly 2.0 V.
I can easily get the motor to run by just connecting it to the Arduinos 5 V and GND, but I don´t know how to make the connection so the digital pin 13 will turn the motor off.
Do I need transistors and diodes to make it work?
I am using this code:
This example code is in the public domain.
*/
int motorPin = 13;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
pinMode(motorPin, OUTPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// 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);
// print out the value you read:
Serial.println(voltage);
if (voltage > 0.5) {
digitalWrite(motorPin, HIGH);
}
else {
digitalWrite(motorPin, LOW);
}
}
Hi guys
Thanks alot for your replies. Will you comment on, if this will work: (See attached diagram)
I have a 12 V dc motor (running at 1 RPM) and a torque sensor. I would like to be able to drive the motor in both directions and continiously read the motors torque with the sensor. The torque sensor is attacted to the motor shaft, and an an elastic band is also attached which will resist more and more, the further the motor is running. I will use an INA125P IC to boost the torque sensors signal and let the Arduino plot the readings in the serial.
Then I will use a H-bridge (L293D) to control the motor and stop it, when a specific value from the torque sensor is reached in the serial.
I would like the motor to run clockwise until e.g. a voltage of 2.0 is read in the serial, then the motor should stop a few seconds, before running back to the starting position.
The motor should then drive counterclockwise to -2.0 and stop, and drive back to the starting position.
Would you be able to program something like that in Arduino, and am I missing some components?