Need code help with a iot project

Hello guys, I am building a iot project using 2 wemos boards where one acts as a counter which sends a high value when there's more than or equal to 1 person in the room. While the other acts as the relay system as well as window closing automation. I have an issue as when theres a person in the room i am unable to toggle the lights with my blynk app. but when the person exits i am abit to toggle. I have attached the counter as well as the relay code below. Thanks for the assistance guys:) [edited: i just added an image of how my circuit looks like below]
Relay code

// Template ID, Device Name and Auth Token are provided by the Blynk.Cloud
// See the Device Info tab, or Template settings
#define BLYNK_TEMPLATE_ID           "Please fill in"
#define BLYNK_DEVICE_NAME           "Please fill in"
#define BLYNK_AUTH_TOKEN            "Please fill in"
 
// Comment this out to disable prints and save space
#define BLYNK_PRINT Serial
 
 
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <Servo.h>

#include <Servo.h>
Servo tap_servo;
int tap_servo_pin =4;
int RelayPin1 = D2;
int RelayPin2 = D3;
int RelayPin3 = D5;
int RelayPin4 = D6;
const int pinButton = D8;
 
char auth[] = BLYNK_AUTH_TOKEN;
 
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "test";
char pass[] = "";
 
// This function will be called every time Slider Widget
// in Blynk app writes values to the Virtual Pin 1
BLYNK_WRITE(V1)
{
  int pinValue = param.asInt(); // assigning incoming value from pin V1 to a variable
  // You can also use:
  // String i = param.asStr();
  // double d = param.asDouble();
  //Serial.print("V1 Slider value is: ");
  //Serial.println(pinValue); 
  digitalWrite(RelayPin1, pinValue);
}
BLYNK_WRITE(V2) { //Button Widget is writing to pin V1
  int pinValue = param.asInt();
  digitalWrite(RelayPin2, pinValue);
}
BLYNK_WRITE(V3) { //Button Widget is writing to pin V2
  int pinValue = param.asInt();
  digitalWrite(RelayPin3, pinValue);
}
BLYNK_WRITE(V4) { //Button Widget is writing to pin V3
  int pinValue = param.asInt();
  digitalWrite(RelayPin4, pinValue);
}

 
void setup()
{
  Blynk.run();
  // Debug console
  Serial.begin(9600);
  tap_servo.attach(tap_servo_pin);
  pinMode(RelayPin1, OUTPUT);
  pinMode(RelayPin2, OUTPUT);
  pinMode(RelayPin3, OUTPUT);
  pinMode(RelayPin4, OUTPUT);
  pinMode(pinButton, INPUT);
  digitalWrite(RelayPin1, HIGH);
   digitalWrite(RelayPin2, HIGH);
   digitalWrite(RelayPin3, HIGH);
  digitalWrite(RelayPin4, HIGH);                                                                                                           
  
 
 
  Blynk.begin(auth, ssid, pass);
  // You can also specify server:
  //Blynk.begin(auth, ssid, pass, "blynk.cloud", 80);
  //Blynk.begin(auth, ssid, pass, IPAddress(192,168,1,100), 8080);
}
 
void loop()
{

   int value = analogRead(A0);//read value

  
  Serial.print("Value : ");
  Serial.println(value);
  {
 if (value > 900)
  {tap_servo.write(0);
  delay(10);
  }
  if (value < 500)
  {tap_servo.write(180);
  delay(10);
  }
  }
  int qq = digitalRead(RelayPin2);
  int stateButton = digitalRead(pinButton);
  if (stateButton == LOW && qq == HIGH){
    digitalWrite(RelayPin2, HIGH);
  }
  else if (stateButton == LOW && qq == LOW){
    digitalWrite(RelayPin2, LOW);
  }
  else if (stateButton == HIGH){
    digitalWrite(RelayPin2, stateButton);
  }
   
  delay(20);

   Blynk.run();

 
}

Counter code

#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE); 
#define sensorPin1 D0
#define sensorPin2 D5
#define relay D10

int sensorState1 = 0;
int sensorState2 = 0;
int count=0;

void setup()
{
  pinMode (sensorPin1,INPUT_PULLUP);
  pinMode (sensorPin2, INPUT_PULLUP);
  pinMode(relay, OUTPUT);

  lcd.begin(16,2);
  lcd.backlight();
  lcd.setCursor(4,0);
  lcd.print("COUNTER");
   lcd.setCursor(0,1);
  lcd.print("No Visitors     ");
  delay(200);
}

void loop()
{
  sensorState1 = digitalRead(sensorPin1);
  sensorState2 = digitalRead(sensorPin2);

  if(sensorState1 == LOW){
    count++; 
    delay(1000);
  }

  if(sensorState2 == LOW){
    if(count==0){
    }
    else{
      count--; 
    }
    delay(1000);
  }


   if(count<=0)
  {
    digitalWrite(relay, LOW); 
    lcd.setCursor(0,1);
    lcd.print("No visitors    ");
  }
  else if (count>0 && count<10){
    digitalWrite(relay, HIGH);
    lcd.setCursor(0,1);
    lcd.print("Visitors:   ");
    lcd.setCursor(12,1);
    lcd.print(count);
    lcd.setCursor(13,1);
    lcd.print("  "); 

  }
  else {
    digitalWrite(relay, HIGH);
    lcd.setCursor(0,1);
    lcd.print("Visitors:   ");
    lcd.setCursor(12,1);
    lcd.print(count);
  }
}

I want to be able to toggle the lights using blynk but at the same time using the counter to do so. so basically when someone in the room toggle on, but if i want to off i can still off using my phone and when there's no one in the room, it can toggle off but if i wanted to on i can use the blynk app to do so.

Please cut and paste the code directly into your post, using code tags. But first, format the code in the IDE editor, using CRTL-T.

See the "How to get the best out of the forum" post, linked at the head of every forum topic.

1 Like

done

Wemos makes dozens of types of board. Which one?

wemos d1 r1 sry

Which sketch detects people in the room? Really, you should post a system diagram, too.

the counter code, so basically when the someone enters/exit the room the ir sensor will send a signal to the wemos board, and if the counter is more than 0. It will send a high via the d10 pin of the board. I will try to make a system diagram when possible.

Have you done this yet? Why is it not possible to make a diagram now?

it takes awhile so i will do it give me about 10 min to do so, it won't be perfect but i will try my best.

Oh, that's no time at all. Can you also please provide some information about the sensors? Like links, for example?

okay noted

The diagram doesn't have to be really neat. Just accurate and complete.

do you have any place i can create a proper diagram having issues creating a neat one.

I said, it doesn't matter how neat.

do you have a site to create one.

Do you have Staples stores in your area? You can get the pencil and paper there.

nvm i am just drawing on paint as i am trying to use image to represent my parts too

What is wrong with pen and paper? If you think you need to include photogenic images of the components, you are on the wrong track. A schematic need not and usually should not display the physical appearance of the parts. Only symbols and labels that show how it's connected.

If you are more comfortable with MS Paint than paper, okay, but don't get sidetracked...

Okay, I see that you have edited your first post to add a Fritzing diagram. Please don't do that without comment (I got your PM but please post here instead). It makes the replies seem weird.

The diagram is almost useless, as most Fritzing diagrams are, except maybe for laying out a prototype. I don't mean to be callous, but in fact you have now basically ignored both the forum advice about how to use the forum, and also my advice. So it will be up to other people to help you. Good luck.