Skip to content

Commit e59aae6

Browse files
committed
Added fully working code
1 parent a1ffd18 commit e59aae6

File tree

3 files changed

+184
-2
lines changed

3 files changed

+184
-2
lines changed

README.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,14 @@
1-
# air_throttle
2-
Air flow controlled by throttle with stepper motor
1+
# Air throttle
2+
Air flow controlled by throttle valve with stepper motor.
3+
A Hall-effect sensor detects when a stove is running and open the throttle.
4+
Otherwise the throttle is closed.
5+
6+
## Hardware
7+
8+
### List of components
9+
* SparkFun Pro Micro 5V 16MHz
10+
* stepper motor 28BYJ-48
11+
* ULN2003 driver for stepper motors
12+
* Hall-effect sensor ACS712 - 20A
13+
* simple ventilation throttle valve
14+
* 0.96 OLED display (optionally)

air_throttle.ino

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Hardware:
3+
* - board SparkFun Pro Micro 5V 16MHz.
4+
* - step motor 28BYJ-48 with ULN2003 driver
5+
* - hall sensor ACS712 - 20A.
6+
*
7+
*/
8+
9+
#include <ACS712.h>
10+
#include <Stepper.h>
11+
12+
// Motor.
13+
const int steps = 32; // the number of motor steps.
14+
const int rotate_360 = 2048; // 32*64 - because of gear.
15+
Stepper motor(steps, 6, 8, 7, 9); // pay attention to pins order. Current order is proper.
16+
17+
// HALL effect sensor.
18+
// SparFun has 5.0 volt with a max value of 1023 steps.
19+
// ACS712 5A uses 185 mV per A.
20+
// ACS712 20A uses 100 mV per A. <<-----------
21+
// ACS712 30A uses 66 mV per A.
22+
ACS712 acs(A0, 5.0, 1023, 100);
23+
24+
25+
void setup() {
26+
// Init rotor.
27+
motor.setSpeed(800);
28+
29+
// Init HALL sensor.
30+
acs.autoMidPoint();
31+
}
32+
33+
34+
bool is_stove_running = false;
35+
bool is_throttle_opened = false;
36+
int mA; // the value taken from Hall sensor (in miliampers).
37+
38+
void loop() {
39+
// Read current.
40+
mA = acs.mA_AC();
41+
//Serial.println(mA);
42+
43+
// Stove is running.
44+
is_stove_running = (mA > 200) ? true : false;
45+
46+
// Run motor if needed.
47+
if (is_stove_running && !is_throttle_opened) {
48+
open_throttle(motor);
49+
is_throttle_opened = true;
50+
}
51+
else if (!is_stove_running && is_throttle_opened) {
52+
close_throttle(motor);
53+
is_throttle_opened = false;
54+
}
55+
56+
delay(500);
57+
}
58+
59+
60+
void open_throttle (Stepper motor) {
61+
motor.step(rotate_360/4); // 512 == turn 90 deg.
62+
}
63+
64+
void close_throttle (Stepper motor) {
65+
motor.step(-rotate_360/4); // 512 == turn 90 deg.
66+
}
67+

air_throttle_with_oled.ino

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
#include <ACS712.h>
2+
#include <Stepper.h>
3+
#include <Adafruit_SSD1306.h>
4+
#include <Adafruit_GFX.h>
5+
6+
// OLED display.
7+
#define OLED_ADDR 0x3C
8+
Adafruit_SSD1306 display(-1);
9+
10+
// Motor.
11+
const int steps = 32; // the number of motor steps.
12+
const int rotate_360 = 2048; // 32*64 - because of gear.
13+
Stepper motor(steps, 6, 8, 7, 9); // pay attention to pins order. Current order is proper.
14+
15+
// HALL effect sensor.
16+
// SparFun has 5.0 volt with a max value of 1023 steps.
17+
// ACS712 5A uses 185 mV per A.
18+
// ACS712 20A uses 100 mV per A. <<-----------
19+
// ACS712 30A uses 66 mV per A.
20+
ACS712 acs(A0, 5.0, 1023, 100);
21+
22+
23+
void setup() {
24+
// Init rotor.
25+
motor.setSpeed(800);
26+
27+
// Init HALL sensor.
28+
//pinMode(A0, INPUT);
29+
acs.autoMidPoint();
30+
31+
// Init and clear OLED display.
32+
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
33+
display.clearDisplay();
34+
display.display();
35+
display.setTextColor(WHITE);
36+
}
37+
38+
39+
bool is_stove_running = false;
40+
bool is_throttle_opened = false;
41+
int mA; // the value taken from Hall sensor (in miliampers).
42+
43+
void loop() {
44+
// Read current.
45+
mA = acs.mA_AC();
46+
display_hall(mA, is_throttle_opened);
47+
//Serial.println(mA);
48+
49+
// Stove is running.
50+
is_stove_running = (mA > 200) ? true : false;
51+
52+
// Run motor if needed.
53+
if (is_stove_running && !is_throttle_opened) {
54+
display_throttle_state("opening...");
55+
open_throttle(motor);
56+
is_throttle_opened = true;
57+
}
58+
else if (!is_stove_running && is_throttle_opened) {
59+
display_throttle_state("closing...");
60+
close_throttle(motor);
61+
is_throttle_opened = false;
62+
}
63+
64+
delay(500);
65+
}
66+
67+
void open_throttle (Stepper motor) {
68+
motor.step(rotate_360/4); // 512 == turn 90 deg.
69+
}
70+
71+
void close_throttle (Stepper motor) {
72+
motor.step(-rotate_360/4); // 512 == turn 90 deg.
73+
}
74+
75+
// Views definitions.
76+
void display_hall(int hall, bool is_throttle_opened) {
77+
display.clearDisplay();
78+
display.setTextSize(1);
79+
display.setCursor(0, 0);
80+
display.print("Hall [mA]:\n");
81+
display.setTextSize(2);
82+
display.print(hall);
83+
display.print("\n");
84+
display.setTextSize(1);
85+
display.print("Throttle: ");
86+
if (is_throttle_opened) {
87+
display.print("opened");
88+
} else {
89+
display.print("closed");
90+
}
91+
display.display();
92+
}
93+
94+
void display_throttle_state(String msg) {
95+
display.clearDisplay();
96+
display.setTextSize(1);
97+
display.setCursor(0, 0);
98+
display.print("Throttle:\n");
99+
display.setTextSize(2);
100+
display.print(msg);
101+
display.display();
102+
}
103+

0 commit comments

Comments
 (0)