-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a1ffd18
commit e59aae6
Showing
3 changed files
with
184 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,14 @@ | ||
# air_throttle | ||
Air flow controlled by throttle with stepper motor | ||
# Air throttle | ||
Air flow controlled by throttle valve with stepper motor. | ||
A Hall-effect sensor detects when a stove is running and open the throttle. | ||
Otherwise the throttle is closed. | ||
|
||
## Hardware | ||
|
||
### List of components | ||
* SparkFun Pro Micro 5V 16MHz | ||
* stepper motor 28BYJ-48 | ||
* ULN2003 driver for stepper motors | ||
* Hall-effect sensor ACS712 - 20A | ||
* simple ventilation throttle valve | ||
* 0.96 OLED display (optionally) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* Hardware: | ||
* - board SparkFun Pro Micro 5V 16MHz. | ||
* - step motor 28BYJ-48 with ULN2003 driver | ||
* - hall sensor ACS712 - 20A. | ||
* | ||
*/ | ||
|
||
#include <ACS712.h> | ||
#include <Stepper.h> | ||
|
||
// Motor. | ||
const int steps = 32; // the number of motor steps. | ||
const int rotate_360 = 2048; // 32*64 - because of gear. | ||
Stepper motor(steps, 6, 8, 7, 9); // pay attention to pins order. Current order is proper. | ||
|
||
// HALL effect sensor. | ||
// SparFun has 5.0 volt with a max value of 1023 steps. | ||
// ACS712 5A uses 185 mV per A. | ||
// ACS712 20A uses 100 mV per A. <<----------- | ||
// ACS712 30A uses 66 mV per A. | ||
ACS712 acs(A0, 5.0, 1023, 100); | ||
|
||
|
||
void setup() { | ||
// Init rotor. | ||
motor.setSpeed(800); | ||
|
||
// Init HALL sensor. | ||
acs.autoMidPoint(); | ||
} | ||
|
||
|
||
bool is_stove_running = false; | ||
bool is_throttle_opened = false; | ||
int mA; // the value taken from Hall sensor (in miliampers). | ||
|
||
void loop() { | ||
// Read current. | ||
mA = acs.mA_AC(); | ||
//Serial.println(mA); | ||
|
||
// Stove is running. | ||
is_stove_running = (mA > 200) ? true : false; | ||
|
||
// Run motor if needed. | ||
if (is_stove_running && !is_throttle_opened) { | ||
open_throttle(motor); | ||
is_throttle_opened = true; | ||
} | ||
else if (!is_stove_running && is_throttle_opened) { | ||
close_throttle(motor); | ||
is_throttle_opened = false; | ||
} | ||
|
||
delay(500); | ||
} | ||
|
||
|
||
void open_throttle (Stepper motor) { | ||
motor.step(rotate_360/4); // 512 == turn 90 deg. | ||
} | ||
|
||
void close_throttle (Stepper motor) { | ||
motor.step(-rotate_360/4); // 512 == turn 90 deg. | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#include <ACS712.h> | ||
#include <Stepper.h> | ||
#include <Adafruit_SSD1306.h> | ||
#include <Adafruit_GFX.h> | ||
|
||
// OLED display. | ||
#define OLED_ADDR 0x3C | ||
Adafruit_SSD1306 display(-1); | ||
|
||
// Motor. | ||
const int steps = 32; // the number of motor steps. | ||
const int rotate_360 = 2048; // 32*64 - because of gear. | ||
Stepper motor(steps, 6, 8, 7, 9); // pay attention to pins order. Current order is proper. | ||
|
||
// HALL effect sensor. | ||
// SparFun has 5.0 volt with a max value of 1023 steps. | ||
// ACS712 5A uses 185 mV per A. | ||
// ACS712 20A uses 100 mV per A. <<----------- | ||
// ACS712 30A uses 66 mV per A. | ||
ACS712 acs(A0, 5.0, 1023, 100); | ||
|
||
|
||
void setup() { | ||
// Init rotor. | ||
motor.setSpeed(800); | ||
|
||
// Init HALL sensor. | ||
//pinMode(A0, INPUT); | ||
acs.autoMidPoint(); | ||
|
||
// Init and clear OLED display. | ||
display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR); | ||
display.clearDisplay(); | ||
display.display(); | ||
display.setTextColor(WHITE); | ||
} | ||
|
||
|
||
bool is_stove_running = false; | ||
bool is_throttle_opened = false; | ||
int mA; // the value taken from Hall sensor (in miliampers). | ||
|
||
void loop() { | ||
// Read current. | ||
mA = acs.mA_AC(); | ||
display_hall(mA, is_throttle_opened); | ||
//Serial.println(mA); | ||
|
||
// Stove is running. | ||
is_stove_running = (mA > 200) ? true : false; | ||
|
||
// Run motor if needed. | ||
if (is_stove_running && !is_throttle_opened) { | ||
display_throttle_state("opening..."); | ||
open_throttle(motor); | ||
is_throttle_opened = true; | ||
} | ||
else if (!is_stove_running && is_throttle_opened) { | ||
display_throttle_state("closing..."); | ||
close_throttle(motor); | ||
is_throttle_opened = false; | ||
} | ||
|
||
delay(500); | ||
} | ||
|
||
void open_throttle (Stepper motor) { | ||
motor.step(rotate_360/4); // 512 == turn 90 deg. | ||
} | ||
|
||
void close_throttle (Stepper motor) { | ||
motor.step(-rotate_360/4); // 512 == turn 90 deg. | ||
} | ||
|
||
// Views definitions. | ||
void display_hall(int hall, bool is_throttle_opened) { | ||
display.clearDisplay(); | ||
display.setTextSize(1); | ||
display.setCursor(0, 0); | ||
display.print("Hall [mA]:\n"); | ||
display.setTextSize(2); | ||
display.print(hall); | ||
display.print("\n"); | ||
display.setTextSize(1); | ||
display.print("Throttle: "); | ||
if (is_throttle_opened) { | ||
display.print("opened"); | ||
} else { | ||
display.print("closed"); | ||
} | ||
display.display(); | ||
} | ||
|
||
void display_throttle_state(String msg) { | ||
display.clearDisplay(); | ||
display.setTextSize(1); | ||
display.setCursor(0, 0); | ||
display.print("Throttle:\n"); | ||
display.setTextSize(2); | ||
display.print(msg); | ||
display.display(); | ||
} | ||
|