#define BLYNK_TEMPLATE_ID "TMPL66WZ0vQzW"
#define BLYNK_TEMPLATE_NAME "Simulation Tem"
#define BLYNK_AUTH_TOKEN "0jn8WIUHVQb6TRWjrUgZiz7G9MLv-3cJ"
#include <BlynkSimpleEsp32.h>
char auth[] = BLYNK_AUTH_TOKEN;
char ssid[] = "Wokwi-GUEST";
char pass[] = "";
BlynkTimer timer;
#define buzzer 19
#define LDRanalog 34
const float GAMMA = 0.7;
const float RL10 = 50;
BLYNK_WRITE(V4)
{
int variabel = param.asInt();
if(variabel==1)
{
tone(buzzer, 262);
}
else
{
noTone(buzzer);
}
}
void BacaKirimSensor()
{
int nilaiADC = analogRead(LDRanalog);
float voltage = nilaiADC * 5/4095.0;
float resistance = 2000 * voltage / (1 - voltage / 5);
float lux = pow(RL10 * 1e3 * pow(10, GAMMA) / resistance, (1 / GAMMA));
Blynk.virtualWrite(V4, lux);
}
void setup() {
Blynk.begin(auth, ssid, pass);
timer.setInterval(1000L, BacaKirimSensor);
}
void loop() {
Blynk.run();
timer.run();
}