Skip to content

Commit 4b036eb

Browse files
committed
added Bourns Motorized Pot PRM examples
1 parent 30bec08 commit 4b036eb

File tree

2 files changed

+101
-0
lines changed

2 files changed

+101
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
Motorized potentiometer controller
3+
Moves a motorized potentiometer in the direction
4+
of a target value.
5+
6+
This was designed to work with a Bourns PRM series potentiometer
7+
e.g. PRM162-K420K-103B1
8+
9+
created 17 Jan 2017
10+
by Tom Igoe
11+
*/
12+
int target = 512; // target pot value
13+
int noise = 5; // electrical noise value for pot
14+
void setup() {
15+
Serial.begin(9600); // open serial communications
16+
pinMode(4, OUTPUT); // H-bridge is on pins 4 and 5
17+
pinMode(5, OUTPUT);
18+
}
19+
20+
void loop() {
21+
int sensor = analogRead(A0); // read pot
22+
int difference = target - sensor; // determine difference
23+
Serial.print(sensor); // print sensor
24+
Serial.print("\t"); // print tab
25+
Serial.println(difference); // print difference
26+
27+
// if difference is < noise in either direction:
28+
if (abs(difference) < noise) {
29+
difference = 0; // difference is irrelevant
30+
}
31+
moveMotor(difference); // move motor
32+
}
33+
34+
// direction of amount sets direction of motor
35+
// if direction = 0, motor turns off.
36+
// magnitude of direction is not used.
37+
void moveMotor(int amount) {
38+
if (amount < 0) {
39+
digitalWrite(4, HIGH);
40+
digitalWrite(5, LOW);
41+
} else {
42+
digitalWrite(4, LOW);
43+
digitalWrite(5, HIGH);
44+
}
45+
if (amount == 0) {
46+
digitalWrite(4, LOW);
47+
digitalWrite(5, LOW);
48+
}
49+
50+
}
51+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Motorized potentiometer controller
3+
Moves a motorized potentiometer back and forth
4+
across its range.
5+
6+
This was designed to work with a Bourns PRM series potentiometer
7+
e.g. PRM162-K420K-103B1
8+
9+
created 17 Jan 2017
10+
by Tom Igoe
11+
*/
12+
13+
int direction = 1;
14+
15+
void setup() {
16+
Serial.begin(9600); // open serial communications
17+
pinMode(4, OUTPUT); // H-bridge is on pins 4 and 5
18+
pinMode(5, OUTPUT);
19+
}
20+
21+
void loop() {
22+
int sensor = analogRead(A0); // read sensor
23+
Serial.println(sensor); // print it
24+
25+
if (sensor >= 1020) { // if sensor is near top of range
26+
direction = -1; // direction is downward
27+
}
28+
if (sensor <= 10) { // if sensor is near bottom of range
29+
direction = 1; // direction is upwards
30+
}
31+
moveMotor(direction); // move motor
32+
}
33+
34+
// direction of amount sets direction of motor
35+
// if direction = 0, motor turns off.
36+
// magnitude of direction is not used.
37+
void moveMotor(int amount) {
38+
if (amount < 0) {
39+
digitalWrite(4, HIGH);
40+
digitalWrite(5, LOW);
41+
} else {
42+
digitalWrite(4, LOW);
43+
digitalWrite(5, HIGH);
44+
}
45+
if (amount == 0) {
46+
digitalWrite(4, LOW);
47+
digitalWrite(5, LOW);
48+
}
49+
}
50+

0 commit comments

Comments
 (0)