Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

ESP8266 for selonoid lock

Armani09

Newbie
Newbie level 1
Joined
Dec 10, 2024
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
0
Visit site
Activity points
28
Lack of CODE or SYNTAX Tags
Hello! I'm making a project using esp8266. When the fire sensor, rain sensor, and smoke sensor triggers the solenoid lock should be unlock and will sent a notification thru blynk app. My problem is the solenoid lock is not working. Is their wrong with the code?


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
 
// Replace with your network credentials
char ssid[] = "404 Not Found";
char pass[] = "password";
char auth[] = "9FR_Idlv8jVtc-W9nWoHlHwIr_sD3-ub";
 
// Pin definitions
#define FLAME_SENSOR_PIN D1
#define GAS_SENSOR_PIN A0
#define RAIN_SENSOR_PIN D4
#define BUZZER_PIN D2
#define RELAY_PIN D3
 
// Thresholds
#define GAS_THRESHOLD 300
#define RAIN_THRESHOLD 500
 
void setup() {
  Serial.begin(9600);
  Blynk.begin(auth, ssid, pass);
 
  pinMode(FLAME_SENSOR_PIN, INPUT);
  pinMode(GAS_SENSOR_PIN, INPUT);
  pinMode(RAIN_SENSOR_PIN, INPUT);
  pinMode(BUZZER_PIN, OUTPUT);
  pinMode(RELAY_PIN, OUTPUT);
 
  Serial.println("System initialized. Waiting for flame, gas, and rain detection...");
}
 
void loop() {
  Blynk.run();
 
  // Flame sensor logic
  int flameStatus = digitalRead(FLAME_SENSOR_PIN);
  if (flameStatus == LOW) { // Flame detected
    Serial.println("Flame detected! Activating buzzer and relay...");
    Blynk.virtualWrite(V3, "Flame Detected");
    Blynk.logEvent("flamealert");
    digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer
    digitalWrite(RELAY_PIN, HIGH); // Turn on relay
  } else { // No flame detected
    Serial.println("No flame detected. Buzzer and relay off.");
    Blynk.virtualWrite(V3, "No Flame");
    digitalWrite(BUZZER_PIN, LOW); // Turn off buzzer
    digitalWrite(RELAY_PIN, LOW); // Turn off relay
  }
 
  // Gas sensor logic
  int gasValue = analogRead(GAS_SENSOR_PIN);
  Serial.print("Gas level: ");
  Serial.println(gasValue);
  Blynk.virtualWrite(V1, gasValue);
 
  if (gasValue > GAS_THRESHOLD) { // Gas detected
    Serial.println("Gas detected! Activating buzzer and relay...");
    Blynk.logEvent("gasalert");
    digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer
    digitalWrite(RELAY_PIN, HIGH); // Turn on relay
  }
 
  // Rain sensor logic
  int rainValue = analogRead(RAIN_SENSOR_PIN);
  Serial.print("Rain level: ");
  Serial.println(rainValue);
 
  if (rainValue < RAIN_THRESHOLD) { // Rain detected
    Serial.println("Rain detected! Activating buzzer and relay...");
    Blynk.virtualWrite(V2, "Rain Detected");
    Blynk.logEvent("rainalert");
    digitalWrite(BUZZER_PIN, HIGH); // Turn on buzzer
    digitalWrite(RELAY_PIN, HIGH); // Turn on relay
  } else { // No rain detected
    Serial.println("No rain detected.");
    Blynk.virtualWrite(V2, "No Rain");
    digitalWrite(BUZZER_PIN, LOW); // Turn off buzzer
  }
 
  delay(2000);
}

 
Last edited by a moderator:
Regardless of the code, depending on how you designed your circuit and how you routed it, it would be a surprise if it didn't lock.
In other words, you only provided half the information.
 

LaTeX Commands Quick-Menu:

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top