Trouble Coding School Project

Hello everyone, so basically I have this Project I had been working on. When I started it my teacher said the coding of it would be easy and for me not to worry much about, but now it’s the only thing I have left to do and I’m really struggling. The Project is na automatic filling machine trhough na electrovalve with 2 rolls and a belt with a motor attached. To make it automatic I am using IR emitters and IR receivers, and I wanted to code in a way that when I put the bottle between the first “sensor” it would wait 2 seconds then it would start the motor, when it reaches the second it would stop the motor and start the valve during some seconds, then it would come to a third sensor that would stop everything so the bottles dont fall. Here is a pic of what it looks like as of right now, the right sensor is what I call the first

So far I have this code but it’s not working quite well,

#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

IRsend irsend;

const int RECV1 = 2;
const int RECV2 = 4;
const int RECV3 = 7;
const int motor = 8;
const int elecvalv = 12;
const int IRLED1 = 3;
const int IRLED2 = 5;
const int IRLED3 = 6;

void setup()

pinMode(RECV1, INPUT);
pinMode(RECV2, INPUT);
pinMode(RECV3, INPUT);
pinMode(motor, OUTPUT);
pinMode(elecvalv, OUTPUT);
pinMode(IRLED1, OUTPUT);
pinMode(IRLED2, OUTPUT);
pinMode(IRLED3, OUTPUT);



void loop()

digitalWrite(IRLED1, HIGH);
digitalWrite(IRLED2, HIGH);
digitalWrite(IRLED3, HIGH);

if (digitalRead(RECV1) == HIGH)
digitalWrite(motor, HIGH);

while (digitalRead (RECV2) == LOW)
digitalWrite(motor, LOW);


if (digitalRead(RECV2) == HIGH)
digitalWrite(motor, HIGH);
digitalWrite(elecvalv, HIGH);
while (digitalRead (RECV3) == LOW)
digitalWrite(motor, LOW);
digitalWrite(motor, HIGH);

if (digitalRead (RECV3) == HIGH)
digitalWrite(motor, LOW);

if ((digitalRead (RECV3) == HIGH) && (digitalRead(RECV1) == HIGH))
digitalWrite(motor, HIGH);
digitalWrite(elecvalv, LOW);


Please bear in mind my english is’nt the best and I’m really new to coding.

Your image did not appear - you obviously did not read your Post after submitting it.

I think this it

See this Image Guide


So far I have this code but it’s not working quite well,

You need to tell us what your program actually does and what you want it to do that is different.

Please modify your post and use the code button </>

so your code looks like this

and is easy to copy to a text editor. See How to use the Forum

Have a look at how millis() is used to manage timing without blocking in Several things at a time

I reckon you need a variable that keeps track of the state of the system - for example, Starting, Filling, Ending

Planning and Implementing a Program

I wanted to code in a way that when I put the bottle between the first "sensor" it would wait 2 seconds

What would wait? The bottle? The filling machine? The motor?

then it would start the motor

What would? The bottle?

when it reaches the second it

Now, I'm really confused.

Please try again with your project description. Be sure to NOT use the word it again ANYWHERE in your reply, since you seem unable to determine that it is a pronoun that has no referent.

So far I have this code but it's not working quite well,

What is actually happening?