Creating an automatic alcohol dispenser with an IR sensor

I started working with Arduino's about a month ago, and decided to do my first big project.

So I wanted to make an automatic alcohol dispenser using one of those cheap IR sensors and an Arduino Pro Micro.

I've already written the code, and I'm waiting for the parts, but I wanted some advice on what should I use to power the whole thing.

Since both the relay and the water pump are 5v, I think I can use an USB charger capable of supplying 1.50 amps.

I'm wondering if I can power the Arduino, the relay and the pump all from the same charger, by just striping the wires, and connecting them to all of the inputs. Will this work or will it cause any problems?


It will work with power supply but what is the current consumption of the motor ? Just check it out

The listing says it's 0.1A.

Then it's all fine. also make sure it doesn't pump too fast

Thanks for helping!

I actually have written the code in a way so it pumps alcohol for 1 second then stops accepting any signal from the IR sensor for about 5 seconds and only after that it can pump again.

Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
Posting images:

Since I'm still waiting for the components to arrive, I only have a schematic that I made in Tinkercad.

Since Tinkercad doesn't have all of the components, the PIR Sensor represents the IR Sensor and the Blue LED represents the relay.


IR Sensor:

Relay: 1 2 4 8 Channel 5V Relay Shield Module Board for Arduino Raspberry Pi ARM yk | eBay

 * Automatic Alchool Dispenser - Sketch

int relay = 3;
int ledPin2 = 4;
int ledPin3 = 9;
int ledPin = 7; // RED LED pin
int inputPin = 2;               // choose the input pin (for sensor)
int pirState = LOW;             
int val = 0;                    
void setup() {
  pinMode(ledPin, OUTPUT);      // declare LED as output
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(relay, OUTPUT);       // relay is indeed an output
  pinMode(inputPin, INPUT);     // declare sensor as input
void loop(){
  val = digitalRead(inputPin);  // read input value
  if (val == HIGH) {            // check if the input is HIGH
    //delay (2000);
    digitalWrite(ledPin, HIGH); // turn LED ON
    digitalWrite(relay, HIGH); // here goes RELAY switch ON
    // here goes RELAY switch ON
    digitalWrite(ledPin3, LOW); 
     delay (1000);
    digitalWrite(ledPin, LOW);
    digitalWrite(relay, LOW); // here goes RELAY switch off;
   // here goes RELAY switch off;
        delay (500);
    digitalWrite(ledPin2, HIGH);
    delay (2500);
    digitalWrite(ledPin2, LOW);
    digitalWrite(ledPin3, HIGH);
    if (pirState == LOW) {
      pirState = HIGH;
  } else {
   digitalWrite(ledPin, LOW); // turn LED OFF
    digitalWrite(ledPin3, HIGH);
    if (pirState == HIGH){
      pirState = LOW;
     if (pirState == HIGH){
      pirState = LOW;

What is the purpose of the variable ‘pirState’ ?

I'm gonna be honest with you, I found the PIR sensor part of the code itself on some website that I don't remember so it would be easier to start.

I'm not sure but I think that the purpose of that variable is to tell if something is in the way of the sensor, to detect motion. LOW should be the state when there's no motion and then it switches to HIGH when there's motion. I'm not sure, I might be completely wrong.

Edit: After messing around a bit more with the 'pirState' variable I'm not really sure what was it's purpose, it was present in some lines of the code, but after changing the parts that contained 'pirState' to 'inputPin' and totally removing the 'pirState' variable from the start of the code, it works exactly the same way...

thats why I asked you because I didnt find any use of it :slight_smile: