12 Volt Air Pump Controlled by Arduino Uno
by wthornbu in Circuits > Arduino
980 Views, 2 Favorites, 0 Comments
12 Volt Air Pump Controlled by Arduino Uno
This is an instruction for how to use a relay and Arduino Uno to control an air pump. I worked on this for a class art project that required an open hardware aspect. The general system is simple: an Arduino controls a relay connected to the air pump's power supply. I also added buttons that could be coded to adjust the air pump however you wish. I used the buttons to change how long the pump was on, more or less, and to turn it on and off.
Supplies
Arduino Uno
DC power supply for the UNO
TEROMAS Tire Inflator (This is where I got the 12 vault pump and power system)
https://www.amazon.com/dp/B07W1W2V9M?ref=ppx_yo2ov_dt_b_product_details&th=1
Solderable Breadboard
(3) x push switches
(10) x M-M wires (Male to Male jumper wires)
12V 1 Channel Relay Module with Optocoupler Isolation Support High or Low-Level Trigger
Rip Apart Teromas
I ripped apart the Teromas Tire Inflator. It had valuable things such as an LED display, buttons, light, and DC cable. I removed all those pieces as I only wanted the pump and the power supply. Be careful to cut the proper wire and not remove something you would later need to re-solder.
Solder in Relay
Once you have stripped the motor down to its bare parts, replace the button connected to the motor from the AC side with the 12v Chanel relay. This will allow us to control the motor by switching the relay on and off. Wire as shown. I used pin 7, but you can use any pin you wish to code.
Wire Buttons
Wire the buttons as shown. I wired the buttons to pins 8, 9, and 10, but you can wire them as you wish. I soldered the switches and wires on a breadboard, as shown.
Code
My code is as follows.
const int relayPin = 7; // Relay connected to pin 7
const int increaseButtonPin = 8; // Button to increase time connected to pin 8
const int decreaseButtonPin = 9; // Button to decrease time connected to pin 9
const int startStopButtonPin = 10; // Button to start/stop loop connected to pin 10
unsigned long onTime = 1000; // Initial on time in milliseconds (3 seconds)
unsigned long offTime = 1000; // Initial off time in milliseconds (3 seconds)
unsigned long lastIncreasePress = 0;
unsigned long lastDecreasePress = 0;
unsigned long lastStartStopPress = 0;
bool relayRunning = true; // Flag to indicate if the relay loop is running
const unsigned long debounceDelay = 50; // Debounce delay in milliseconds
void setup() {
pinMode(relayPin, OUTPUT);
pinMode(increaseButtonPin, INPUT_PULLUP); // Enable internal pull-up resistor
pinMode(decreaseButtonPin, INPUT_PULLUP); // Enable internal pull-up resistor
pinMode(startStopButtonPin, INPUT_PULLUP); // Enable internal pull-up resistor
}
void loop() {
// Check if increase button is pressed
if (digitalRead(increaseButtonPin) == LOW) {
if (millis() - lastIncreasePress > debounceDelay) {
lastIncreasePress = millis();
// Increase both on and off times by 500 milliseconds (half a second)
onTime += 1000;
offTime += 1000;
}
}
// Check if decrease button is pressed
if (digitalRead(decreaseButtonPin) == LOW) {
if (millis() - lastDecreasePress > debounceDelay) {
lastDecreasePress = millis();
// Decrease both on and off times by 500 milliseconds (half a second)
if (onTime > 1000 && offTime > 1000) { // Ensure time doesn't go below 500 milliseconds
onTime -= 1000;
offTime -= 1000;
}
}
}
// Check if start/stop button is pressed
if (digitalRead(startStopButtonPin) == LOW) {
if (millis() - lastStartStopPress > debounceDelay) {
lastStartStopPress = millis();
relayRunning = !relayRunning; // Toggle relayRunning flag
}
}
if (relayRunning) {
digitalWrite(relayPin, HIGH); // Turn on the relay
delay(onTime); // Keep it on for specified onTime
digitalWrite(relayPin, LOW); // Turn off the relay
delay(offTime); // Keep it off for specified offTime
}
}
I would not recommend using it as I got it off Chat GPT, and it does not work well. I coded button eight to increase how long the pump was on. Button 9 decreased how long the pump was on, and pin 10 turned the loop on and off.
You Are Done
Once you have all of the pieces together, the product is done. This can be used in many different ways, and I would love to see them. I used it to mimic breathing for a short film I made, but there are many options for how it can be used.
This is not shown within the images, but the Arduino will need to be powered separately as I cooked an Uno and tried to wire it into the same power supply as the motor.