From ae9a5f0b3fd6371c82e822855a4802f24ee3c211 Mon Sep 17 00:00:00 2001 From: Smits Date: Sun, 15 Feb 2026 20:28:52 +0100 Subject: [PATCH] Initial code commit with arduino sketch I used to test wiring and code on a simple breadboard. My first ever bit of Arduino code --- ESP32-LightSensor.ino | 71 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 ESP32-LightSensor.ino diff --git a/ESP32-LightSensor.ino b/ESP32-LightSensor.ino new file mode 100644 index 0000000..04eab32 --- /dev/null +++ b/ESP32-LightSensor.ino @@ -0,0 +1,71 @@ +#include +#include //https://github.com/tzapu/WiFiManager WiFi Configuration Magic +#include // Library for the light sensor + +const int configbutton = D9; // Input for config button +const int led = D10; // Output for status LED +int configbuttonStatus = digitalRead(configbutton); +bool ready = 0; +int counter = 0; +hp_BH1750 BH1750; + +int status = WL_IDLE_STATUS; + +void setup() +{ + pinMode(led, OUTPUT); + pinMode(configbutton, INPUT_PULLUP); + + Serial.println("reset button: "); + Serial.println(configbuttonStatus); + + + // check for the presence of the shield: + if (WiFi.status() == WL_NO_SHIELD) { + Serial.println("WiFi shield not present"); + while(true); // don't continue + } + + WiFiManager wifiManager; + wifiManager.autoConnect("ESP32-LS"); + + while(WiFi.status() != WL_CONNECTED) { + digitalWrite(led, HIGH); + delay(1000); + digitalWrite(led, LOW); + delay(1000); + } + + if(WiFi.status() == WL_CONNECTED){ + digitalWrite(led, HIGH); + } + + + bool avail = BH1750.begin(BH1750_TO_GROUND); + if (!avail) { + Serial.println("No BH1750 sensor found!"); + while (true) {}; + } +} + + +void loop () { + while(WiFi.status() != WL_CONNECTED) { + digitalWrite(led, HIGH); + delay(1000); + digitalWrite(led, LOW); + delay(1000); + } + + + if ( configbuttonStatus != digitalRead(configbutton) ) { + WiFiManager wifiManager; + wifiManager.startConfigPortal("ESP32-LS"); + Serial.println("connected...yeey :)"); + } + + BH1750.start(); + float lux=BH1750.getLux(); + Serial.println(lux); + delay(5000); +} \ No newline at end of file