Thunderstorm Alert With Arduino Sensor Kit Base

In this project we’ll be building a light sensitivity-based Arduino project that will trigger various sensors depending upon the light intensity in the room. You may also use sound sensor instead of light sensor.
Things used in this project,
Hardware Components
  • Arduino Uno with Cable
  • Arduino Sensor Kit Base
Software Apps and Online Services
  • Arduino IDE
  • An active internet connection to download the package
If you would not like to download the Arduino IDE and prefer to run the project online then you may refer Arduino Web Editor.
Before we get started let’s quickly look at all the components on Arduino Sensor Base Kit.
Arduino Sensor Kit Base Hardware Overview
Image Reference:
In this project we’ll use a light sensor, buzzer, temperature & humidity sensor, LED and an OLED Screen.
Step 1 - Setting up your environment.
Since Arduino Sensor Base kit base has 10 sensors embedded just on board so instead of downloading and installing the libraries for each sensor, we can use Arduino_Sensorkit library. Go to Manage Library under Tools and search for Arduino_Sensorkit.
Please make sure you have an active internet connection for this step.
Step 2 - Writing the code for the project.
We’ll first import the Arduino Sensor kit library and declare the variables for buzzer, light sensor and the LED. Since we have the entire library loaded, we don’t need to declare the pin number for OLED and temperature & humidity sensor. If you wish you may also avoid declaring pin numbers for other components too. 
  1. #include "Arduino_SensorKit.h"  
  2. int buzzer = 5;  
  3. int light_sensor = A3;  
  4. int LED = 6;  
In the following setup() function we declare the serial communication, OLED and Environment library for temperature and humidity sensor. The setFlipMode() function is used to rotate your display on the OLED screen. We then set the pin mode for buzzer and LED as output.
  1. void setup() {  
  2.     Serial.begin(9600);  
  3.     Oled.begin();  
  4.     Environment.begin();  
  5.     Oled.setFlipMode(true);  
  6.     pinMode(buzzer, OUTPUT);  
  7.     pinMode(LED, OUTPUT);  
  8. }  
Inside the void loop function let us understand the code briefly. We start by making the buzzer off with noTone() and switching off the LED with Low input using digitalWrite() function.
  1. noTone(buzzer);  
  2. digitalWrite(LED, LOW);  
For the light sensor we read the raw value from pin (A3), assign it to raw_light variable and then map the value from 0, 1023 to 0, 100 to store in the light variable.
  1. int raw_light = analogRead(light_sensor); // read the raw value from light_sensor pin (A3);  
  2. int light = map(raw_light, 0, 1023, 0, 100); // map the value from 0, 1023 to 0, 100;  
You can set font and coordinates for the OLED display. Here we have used u8x8_font_chroma48medium8_r and the display coordinates start from (0,33).
  1. Oled.setFont(u8x8_font_chroma48medium8_r);  
  2. Oled.setCursor(0, 33); // Set the Coordinates  
The following code inside the if statement will only run if the light sensitivity is more than 20. If this is true then we switch on the buzzer, turn on the LED and display the current temperature with light sensitivity on the OLED screen.
  1. if (light > 20) {  
  2.     tone(buzzer, 85);  
  3.     digitalWrite(LED, HIGH);  
  4.     Oled.print("L:");  
  5.     Oled.print(light);  
  6.     Oled.println("T:");  
  7.     Oled.print(Environment.readTemperature());  
  8.     Oled.refreshDisplay();  
  9. else {  
  10.     Oled.print("L:");  
  11.     Oled.print(light);  
  12.     Oled.refreshDisplay();  
  13. }  
If the light sensitivity value is less than 20, we anyway display the light value from the else statement block.
And finally, we use the delay function with value 3000 that runs the loop after 3 seconds to check the light sensitivity.
The final code looks like this,
  1. #include "Arduino_SensorKit.h"  
  2. int buzzer = 5;  
  3. int light_sensor = A3;  
  4. int LED = 6;  
  5. void setup() {  
  6.     Serial.begin(9600);  
  7.     Oled.begin();  
  8.     Environment.begin();  
  9.     Oled.setFlipMode(true);  
  10.     pinMode(buzzer, OUTPUT);  
  11.     pinMode(LED, OUTPUT);  
  12. }  
  13. void loop() {  
  14.     noTone(buzzer);  
  15.     digitalWrite(LED, LOW);  
  16.     int raw_light = analogRead(light_sensor);  
  17.     int light = map(raw_light, 0, 1023, 0, 100);  
  18.     Oled.setFont(u8x8_font_chroma48medium8_r);  
  19.     Oled.setCursor(0, 33);  
  20.     if (light > 20) {  
  21.         tone(buzzer, 85);  
  22.         digitalWrite(LED, HIGH);  
  23.         Oled.print("L:");  
  24.         Oled.print(light);  
  25.         Oled.println("T:");  
  26.         Oled.print(Environment.readTemperature());  
  27.         Oled.refreshDisplay();  
  28.     } else {  
  29.         Oled.print("L:");  
  30.         Oled.print(light);  
  31.         Oled.refreshDisplay();  
  32.     }  
  33.     delay(3000); // add a delay to only read and print every 1 second  
  34. }  
Step 3 - Setting up your Hardware.
Place the Arduino Sensor Kit Base over Arduino and connect the Arduino to your laptop/computer. It should power up the Arduino with the kit base and you should a green LED glowing on the sensor kit.
Step 4 - Upload the Code
It’s time we upload the code. You can either first compile and then upload else directly upload which should compile it too.
If everything is fine then the LED and Buzzer should be ON with temperature & humudity and light sensitivity value displayed on the OLED screen, else only the light sensitivity valuse will be displayed with everything switched off.