NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

const int trig = 12; // This command labels the trig pin on the sensor to pin 12 on the arduino board
const int echo = 13; // This command labels the echo pin on the sensor to pin 13 on the arduino board

const int redLED = 6; // This command labels red led to pin number 6 on the arduino board
const int yellowLED = 10; // This command labels the yellow led to pin number 10 on the arduino board
const int greenLED = 11; // This command labels the green led to pin number 11 on the arduino boarc

int duration = 0; // This command sets the duration to 0
int distance = 0; // This command sets the distance to 0

void setup() // This command only runs once in the program to setup the code
{
Serial.begin(9600); // This command sets the baud rate of the arduino to 9600
pinMode(trig , OUTPUT); // This command sets the trig pin as an output
pinMode(echo , INPUT); // This command sets the echo pin on the sensor as an input

pinMode(yellowLED , OUTPUT); // This command sets the yellow led as an output
pinMode(redLED , OUTPUT); // This command sets the red led as an output
pinMode(greenLED , OUTPUT); // This command sets the green led as an output



}

void loop() // This command is the main body of the program, the code written inside loops indefinitely
{
digitalWrite(trig , HIGH); // This command sets the trigger pin to high
delayMicroseconds(1000); // This command pauses the code by 1000 microseconds
digitalWrite(trig , LOW); // This command sets the trigger pin to low
// These three codes sends an ultrasonic pulse from the sensor
duration = pulseIn(echo , HIGH); // This command is used to measure the duration of the echo pulse
distance = (duration/2) / 28.5 ; // This command divides the duration by 2 and then divides by the speed of sound in the air (28.5cm/ms) to calculate the distance to the object
Serial.println(distance); // This command then displays the distance value to the serial monitor

if ( distance <= 10) // This command checks whether the distance is less than or equal to 10
{
digitalWrite(redLED, HIGH); // This command switches on the red led
}
else // This command is activated when the condition for the if command has not been achieved
{
digitalWrite(redLED, LOW); // This command switches off the red led
}
if ( distance >= 10 && distance <= 25) // This command checks whether the distance is more than or equal to 10 and less than or equal to 25
{
digitalWrite(yellowLED, HIGH); // This command switches the yellow led on
}
else // This command activates when the if command condition has not been acheived
{
digitalWrite(yellowLED, LOW); // This command switches the yellow led off
}
if ( distance >= 25 ) // This command checks whether the distance from the sensor is more than or equal to 25
{
digitalWrite(greenLED, HIGH); // This command switches the green led on
}
else // This command activates when the if command condition has not been achieved
{
digitalWrite(greenLED, LOW); // This command switches the green led off
}}

     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.