Arduino Tutorials

Welcome to Arduino Tutorials.

Arduino Basic

Here is the Arduino Code and Circuit for a Flashing Lights using TinkerCAD

Let us Challenge you with Traffic Signal Arduino Project. Download the project rubric.

Arduino – Ultrasonic Sensor

Copy the Arduino Code for Ultrasonic Sensor for 3 LED Lights.

#define trigPin 13
#define echoPin 12
# define led 11
#define led2 10
#define led3 9
void setup()
{ Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(led, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop()
{ long duration, distance;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
distance = (duration/2) / 29.5;
if (distance < 30)
{ digitalWrite(led,HIGH);
if (distance < 20)
{ digitalWrite(led2,HIGH);
if (distance < 10)
{ digitalWrite(led3,HIGH);
}
}
}
else {
digitalWrite(led,LOW);
digitalWrite(led2,LOW);
digitalWrite(led3,LOW);
}
Serial.print(distance);
Serial.println(” cm”);
delay(2000);
}