want help to develop program

i am trying to make automatic hand sanitizer for my class room.. i am using arduino uno... now what is my aim?... my aim is to develop a program in which ir sensor module take digital / analog input from hand movements and turn ON 5v dc water pump only for 3 seconds after 3 seconds it will automatically turn off the pump even if hand is there. when the next person again put hand in front of sensor it will agin start for 3 seconds and turns off.... components used arduino uno, ir sensor module, 5v dc relay, 5v dc water pump.... someone plz provide code... i am not belong to electronics so i don't have enough knowledge about it.. can some pz provide me ready-made code plzz plzz plzz... goal of this project is to use only limited quantity of sanitizer because some naughty students from my class are purposely put hand infront of sensor more than 10 minutes to empty the sanitizer bottle so i want a program evenif hand is present for long time in front of sensor it operates only for 3 seconds... it again turn ON only when 1st person hand was removed and the next person hand is come in front of sensor... plz give me code plz help me to solve this plz

We can help you with your project(s) when you show us what you have currently done.

This should be easily accomplished using the Arduino platform.

How do you propose to power this ?


Always start with a good schematic.


Show us a good schematic of your circuit.
Show us a good image of your ‘actual’ wiring.
Give links to components.
Posting images:
https://forum.arduino.cc/index.php?topic=519037.0

Use CTRL T to format your code.
Attach your ‘complete’ sketch between code tags, use the </> icon in the posting menu.
[code]Paste your sketch here[/code]


If you need someone to do all the work, there is a ‘Gigs and Collaborations’ forum on this web site where you can ask for assistance.

#define sensor 2 //The input of IR sensor connected to pin 2
#define motor 8 //The output of Motor connected to pin 8
int count=0;
void setup()
{
pinMode(sensor,INPUT); // configuring pin A0 as Input
pinMode(motor, OUTPUT); // configuring pin 8 as Output
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

}
int readPin = 0;
// the loop routine runs over and over again forever:
void loop()
{
// read the input pin 2:
readPin = digitalRead(sensor);
if (readPin == 0)
{
count ++;
if(count < 10)
{
digitalWrite(motor,HIGH); // Send 1KHz motor signal...
// print out the value you read:
Serial.println("DC Pump is ON Now!!");
delay(100);
digitalWrite(motor,LOW);
}
}
else if (readPin == 1)
{
digitalWrite(motor,LOW); // Send 1KHz motor signal...
// print out the value you read:
count =0;
Serial.println("DC Pump is OFF Now!!");
}
}

i am trying to make automatic hand sanitizer for my class room.. i am using arduino uno... now what is my aim?... my aim is to develop a program in which ir sensor module take digital / analog input from hand movements and turn ON 5v dc water pump only for 3 seconds after 3 seconds it will automatically turn off the pump even if hand is there. when the next person again put hand in front of sensor it will agin start for 3 seconds and turns off.... components used arduino uno, ir sensor module, 5v dc relay, 5v dc water pump.... someone plz provide code... i am not belong to electronics so i don't have enough knowledge about it.. can some pz provide me ready-made code plzz plzz plzz... goal of this project is to use only limited quantity of sanitizer because some naughty students from my class are purposely put hand infront of sensor more than 10 minutes to empty the sanitizer bottle so i want a program evenif hand is present for long time in front of sensor it operates only for 3 seconds... it again turn ON only when 1st person hand was removed and the next person hand is come in front of sensor... plz give me code plz help me to solve this plz

in the code bellow motor start for 3 seconds then stop and again start i can't find any solution please help me out please

#define sensor 2 //The input of IR sensor connected to pin 2
#define motor 8 //The output of Motor connected to pin 8
int count=0;
void setup()
{
pinMode(sensor,INPUT); // configuring pin A0 as Input
pinMode(motor, OUTPUT); // configuring pin 8 as Output
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);

}
int readPin = 0;
// the loop routine runs over and over again forever:
void loop()
{
// read the input pin 2:
readPin = digitalRead(sensor);
if (readPin == 0)
{
count ++;
if(count < 10)
{
digitalWrite(motor,HIGH); // Send 1KHz motor signal...
// print out the value you read:
Serial.println("DC Pump is ON Now!!");
delay(100);
digitalWrite(motor,LOW);
}
}
else if (readPin == 1)
{
digitalWrite(motor,LOW); // Send 1KHz motor signal...
// print out the value you read:
count =0;
Serial.println("DC Pump is OFF Now!!");
}
}

Take a look at the blink without delay example and the state change example in the IDE.

Please remember to use code tags when posting code

Thank you for the information.

Looks like you are a budding expert :wink:

Are you able to measure the resistance of the motor ?

If so, what is it ?

Will this be plugged into AC or is it battery powered ?

Do you have a web link to the sensor, if so, please supply.

How are you powering the pump ?

Please draw a ‘power’ wiring schematic showing: Arduino, relay card, sensor and pump connections.

// constants won't change. Used here to set a pin number:
const int ledPin =  LED_BUILTIN;// the number of the LED pin

// Variables will change:
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change:
const long interval = 1000;           // interval at which to blink (milliseconds)

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // here is where you'd put code that needs to be running all the time.

  // check to see if it's time to blink the LED; that is, if the difference
  // between the current time and last time you blinked the LED is bigger than
  // the interval at which you want to blink the LED.
  unsigned long currentMillis = millis();

  if (currentMillis - previousMillis >= interval) {
    // save the last time you blinked the LED
    previousMillis = currentMillis;

    // if the LED is off turn it on and vice-versa:
    if (ledState == LOW) {
      ledState = HIGH;
    } else {
      ledState = LOW;
    }

    // set the LED with the ledState of the variable:
    digitalWrite(ledPin, ledState);
  }
}

i found this code but as i already told my educational background is pharmacy i can't understand these codes plz help me to solve my issue

i leaned this from youtube video they prove code i run this code it will work perfectly but my aim is not satisfied so i tried to modify the code and i lost....still i can't find any solution so please help me out... i am powering my motor with usb cable it is 5v dc. i don't have any device to measure register of motor thank you

We can help, but please supply the information asked for in post #5.

If you continue to run the pump from the USB, you will damage something.

Do any friends have a DVM you can borrow ?

Are you able to measure the resistance of the motor ? NO...

If so, what is it ? NO...

Will this be plugged into AC or is it battery powered ? DC 5V

Do you have a web link to the sensor, if so, please supply.

How are you powering the pump ? USING USB 5V CABLE

Please draw a 'power' wiring schematic showing: Arduino, relay card, sensor and pump connections.

PLEASE FIND ATTACHMENT BELLOW

what is DVM i don't know the long form

DVM digital volt meter.


Is your USB cable plugged into a computer or is it plugged into a Cell Phone 5 volt charger ?

This is how things should be wired:

Do you have a 5v Cell phone type charger ?

Change as needed:
Pin 2 is sensor input.
Pin 8 is relay control output.

//********************************************************************
//                   YY/MM/DD
// Version 1.00      20/06/10        Running code
//
//********************************************************************

#define motorON                      LOW        //change as needed, most relay cards need a LOW to pick the relay
#define motorOFF                     !motorON

#define handDectected                LOW        //sensor gives a LOW when an object is detected, change as needed

const byte sensorPin               = 2;         //IR sensor connected to pin 2
const byte motorPin                = 8;         //motor relay connected to pin 8
const byte heartbeatLED            = 13;        //toggles every 500ms, acts as a heartbeat indication

byte lastReadSensor;                            //the state the sensor was last in

bool pumpFlag                      = false;     //true means the pump is on
bool waitFlag                      = false;     //false means we 'can' check the hand sensor

//timing stuff
unsigned long currentMillis;
unsigned long heartbeatMillis;

unsigned long checkSensorMillis;

unsigned long pumpMillis;
const unsigned long pumpOnInterval = 3 * 1000ul;  //the pump is on for 3 seconds

unsigned long waitingMillis;
const unsigned long waitInterval   = 2 * 1000ul;  //wait 2 seconds before we allow more dispensing

//********************************************************************
void setup()
{
  pinMode(sensorPin, INPUT_PULLUP);
  pinMode(motorPin, OUTPUT);
  pinMode(heartbeatLED, OUTPUT);

  // initialize serial communication at 9600 bits per second:
  Serial.begin(9600);

} //END of setup()

//********************************************************************
void loop()
{
  //save current time
  currentMillis = millis();

  //********************************
  //to help show if there is any blocking code, this LED toggles every 500ms
  if (currentMillis - heartbeatMillis >= 500)
  {
    //start this TIMER
    heartbeatMillis = currentMillis;

    digitalWrite(heartbeatLED, !digitalRead(heartbeatLED));
  }

  //********************************
  checkSensor();

  //********************************
  //pump ON TIMER
  if (pumpFlag == true && currentMillis - pumpMillis > pumpOnInterval)
  {
    //disable this TIMER
    pumpFlag = false;

    digitalWrite(motorPin, motorOFF);
    Serial.println("DC Pump is OFF Now!!");
    Serial.println("");

    //enter the waiting phase
    //start the TIMER
    waitingMillis = currentMillis;

    //enable the wait TIMER
    waitFlag = true;
  }

  //********************************
  //waiting phase TIMER
  if (waitFlag == true && currentMillis - waitingMillis > waitInterval)
  {
    //allow sensor checking
    //disabel this TIMER
    waitFlag = false;
  }

  //********************************
  //other non blocking code
  //********************************

} //END of loop()


//********************************************************************
void checkSensor()
{
  byte readStatus = 0;

  //************************
  //can we check the sensor yet ?
  if (currentMillis - checkSensorMillis < 50)
  {
    //no, it is not time to read the sensor
    return;
  }

  //restart the TIMER
  checkSensorMillis = currentMillis;

  //************************
  //read the sensor
  readStatus = digitalRead(sensorPin);

  //has the sensor state changed ?
  if (lastReadSensor == readStatus)
  {
    //no change
    return;
  }

  //save the new state
  lastReadSensor = readStatus;

  //if we are allowed, has the hand been detected ?
  if (waitFlag == false && pumpFlag == false && readStatus == handDectected)
  {
    //start the TIMER
    pumpMillis = currentMillis;

    //enable the pump TIMER
    pumpFlag = true;

    digitalWrite(motorPin, motorON);
    Serial.println("DC Pump is ON Now!!");

  }

  //************************
  //other sensors or switches
  //************************

} //END of  checkSensor()

thank you so much sir.. i'll check and post reply message .... again thank you so much

:slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: :slight_smile: i am very happy thank you so much the code is working properly again and again thank you so much for help me to develop my home based machine..... i am so happy now .... again thank you

What do you teach ?

What is the student ages ?

chemistry, pharmaceutical chemistry, pharmacy of 5th to 12th standard students and some pharma students

age of students 11 year to 18 years

Teachers are great !

you are great sir ... thanks again for providing this valuable information ...