Regarding the connection

Details :
Serial printer not showing any output
Smartphone- ColorsOS 14.0
Blynk server- blynk cloud (blr1.blynk.cloud)
Hardware model - Arduino Uno
communication type-wifi

#define BLYNK_TEMPLATE_ID "TMPL3oueNEgJS"
#define BLYNK_TEMPLATE_NAME "AUTOMATED PUBLIC LIGHTING"

#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
#include <SimpleTimer.h>

SimpleTimer timer;

const int RED_LED1 = 13;                          
const int BUTTON_PIN1 = 11;
const int RED_LED2 = 6;
const int BUTTON_PIN2 = 7;
const int IR1 = 2;
const int LED1 = 9;
const int IR2 = 4;
const int LED2 = 10;
const int LDR = A0;
int buttonState1;
int buttonState2;
int LDRValue;

char auth[] = BLYNK_AUTH_TOKEN;  
char ssid[] = "";
char pass[] = "";

void myTimerEvent()
{
  LDRValue = analogRead(LDR);
  Serial.print("LDR: ");
  Serial.println(LDRValue);
  Blynk.virtualWrite(V0, LDRValue);    
  Serial.println("\n-------------------------------");
LDRValue = analogRead(LDR);
  Serial.print("sensor = ");
  Serial.println(LDRValue);
  delay(500);

  if (LDRValue >= 1000) {
    analogWrite(LED2, LOW);
    analogWrite(LED1, LOW);
    Blynk.notify("LEDS ARE: off");
    Serial.println("It's Bright Outside; Lights status: OFF");
  } else {
    int brightness = 255;

    if (digitalRead(IR1) == LOW) {
      analogWrite(LED2, brightness);
      Blynk.notify("LED2 : ON(full_brightness)");
      Serial.println("It's Dark Outside; LED1 Lights status: ON");
    } else {
      analogWrite(LED2, brightness / 4);
      Blynk.notify("LED2 : ON(reduced_brightness)");
      Serial.println("No motion detected; Dimming LED1");
    }

    if (digitalRead(IR2) == LOW) {
      analogWrite(LED1, brightness);
      Blynk.notify("LED1 : ON(full_brightness)");
      Serial.println("It's Dark Outside; LED2 Lights status: ON");
    } else {
      analogWrite(LED1, brightness / 4);
      Blynk.notify("LED2 : ON(reduced_brightness)");
      Serial.println("No motion detected; Dimming LED2");
    }
  }

  buttonState1 = digitalRead(BUTTON_PIN1);
  Serial.print("Button state1: ");
  Serial.println(buttonState1);

  if (buttonState1 == LOW) {
    digitalWrite(RED_LED1, HIGH);
    Blynk.notify("RED_LED1:ON(EMERGENCY!!!!!!!!!!!!!!!!)");
    Serial.println("Emergency! RED_LED1 Lights status: ON");
  } else {
    digitalWrite(RED_LED1, LOW);
  }

  buttonState2 = digitalRead(BUTTON_PIN2);
  Serial.print("Button state2: ");
  Serial.println(buttonState2);

  if (buttonState2 == LOW) {
    digitalWrite(RED_LED2, HIGH);
    Blynk.notify("RED_LED2:ON(EMERGENCY!!!!!!!!!!!!!!!!)");
    Serial.println("Emergency! RED_LED2 Lights status: ON");
  } else {
    digitalWrite(RED_LED2, LOW);
  }
}

void setup() {
  Serial.begin(9600);
  pinMode(IR1, INPUT);
  pinMode(LED1, OUTPUT);
  pinMode(IR2, INPUT);
  pinMode(LED2, OUTPUT);
  pinMode(RED_LED1, OUTPUT);
  pinMode(BUTTON_PIN1, INPUT_PULLUP);
  pinMode(RED_LED2, OUTPUT);
  pinMode(BUTTON_PIN2, INPUT_PULLUP);
  
  LDRValue = 0;
  digitalWrite(LED1, LOW);
  digitalWrite(LED2, LOW);
  digitalWrite(RED_LED1, LOW);
  digitalWrite(RED_LED2, LOW);

  Blynk.begin(auth, ssid, pass);
  Serial.println("Blynk Begin");

  timer.setInterval(1000L, myTimerEvent);
}

void loop() {
  Blynk.run();
  timer.run();
  // Update virtual pins to reflect LED status
  Blynk.virtualWrite(V0, digitalRead(RED_LED1));
  Blynk.virtualWrite(V3, digitalRead(RED_LED2));
}

The Arduino Uno does not have any built-in WiFi capabilities. To use it with WiFi you need additional hardware, such as an ESP-01 in AT mode.

But, you’re using the wrong sketch for that. This sketch uses the Ethernet libraries…

that you’d normally use with an Ethernet shield, but then you also have some WiFi code in there, which is a mess…

In your first (now deleted) sketch you were using an SSID that implied that you were trying to connect to a 5G network, which wouldn’t work with most IoT capable boards.

So, you’re using the wrong hardware, the wrong libraries and the wrong type of WiFi network.

If you fix those issues then you still have the issue of your void loop.

Pete.

2 Likes

:grin: :smile: :smiley: :grinning: :joy:

Probably not the answer he was looking for! :see_no_evil:

:innocent:

Pete.

Thank you for your suggestions, sir. I corrected whatever you told, and it is working properly.

1 Like