Programming, compiling and uploading the code to Arduino

On the main screen of Arduino Web Editor, click on the button NEW SKETCH to create a new sketch:

image-11

Arduino Web Editor assigns the name of the new sketch automatically. The name consists of the word sketch, an underscore, and six alphanumeric characters (the first three letters of the month, two digits for the day and a sequential letter: a, b, c, etc.).

We change the name of the new sketch to smart-streetlight following the steps shown in the figure:

image-12

Copy the following code and paste it in the code area on the right:

#include<SoftwareSerial.h>
int sensorPin = A0;
int sensorValue = 0;
int led = 3;
void setup () {
 pinMode(led, OUTPUT);
 Serial.begin(9600);
 // put your setup code here, to run once:
}
void loop () {
 sensorValue = analogRead(sensorPin);
 Serial.println(sensorValue);
 if(sensorValue <100)
 {
   Serial.println("LED light on");
   digitalWrite(led,HIGH);
   delay(1000);
 }
 digitalWrite(led,LOW);
 delay(sensorValue);
 // put your main code here, to run repeatedly:
}


Next, we click on the button Verify and Save. Arduino Web Editor will verify the integrity of the code (that it does not have errors) and will save it in the cloud under the assigned name:


image-13