Introduction: Arduino Morning Call
-Adapters
-Wooden box
-Utility knife
-Marking Pen
-Half transparent paper
-Breadboard(generic)
-Arduino UNO
-LEDs(generic)x4
-Ultrasonic Sensor(generic)
-Jumper wires(generic)x8
-Buzzer
-Resistor ohmx4
Step 1: Setup the Code
Buzzer = pin 7
On Ultrasonic Sensor: Echo = pin 3
Trig = pin 2
LEDs: RedLED = pin 4
YellowLED = pin 5
GreenLED = pin 6
Step 2: Setup the Whole Thing in the Arduino Breadboard
1.Breadboard
Connect the red wire from the 5V pin (positive channel) and black wire from the GND(negative channel) on the Arduino of the breadboard.
2.Ultrasonic Sensor Connect the ultrasonic sensor. Four jumper wires remain. Each of them will be inserted in digital ~3 、2 (Trig pin 2 and Echo pin 3)& left +25 、 left -22, jumper wires’ color doesn’t matter and make sure the ultrasonic sensor is facing out. And for the distance, I have set up that the green LED’s distance < 50, yellow LED’s distance < 20, red LED’s distance < 5 and for the distanceincm, it has to be > 5 and also <= 0, it’s for the Outside the permissible range of distances.
3.LEDs Connect the LEDs on the Arduino breadboard. The green LED- the longer leg to pin 6 and use a resistor ohm to the negative part on the board. Then repeat the same step for the yellow and red LED, make sure the longer leg of the red LED is pin 4, yellow LED is to pin 5.
4.Resistor ohm You will basically just inserted the resistor ohm right beside the LED. For example, the yellow LED is place on D 46 so the resistor ohm will be on C 46 (one leg) and another one will all be at negative -46(same place). Green LED is placed on D 39(shorter one) so the resistor ohm will be on C 39 (one leg) and another one will all be at negative -39(same place). Red LED is placed on D 34 so the resistor ohm will be on C 34 (one leg) and another one will all be at negative -34(same place). The last resistor ohm will be placed on C 28 which is the place right beside the buzzer black jumper wires and another leg is also negative 28.
5. Buzzer Connect the red jumper wires to of the buzzer to the left part of the board- D 29 and the black jumper wires to the left part of the board- D 28 (sound buzzer 500).
Step 3: Setup the Outer Part
Use the marketing pen to trace a line like a cross sign and draw it a bit bigger than the Arduino breadboard on the wooden paper(box). Cut along the line drawn. Then fold the cut-out places of the wooden paper (box) and stick it by the tape. After making the box, stick the half transparent paper to the top of the wooden carton.
Step 4: Finish!
CODE
#define trigPin 2
#define echoPin 3
#define LEDlampRed 4
#define LEDlampYellow 5
#define LEDlampGreen 6
#define soundbuzzer 7
int sound = 500;
void setup() {
Serial.begin (9600);
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(LEDlampRed, OUTPUT);
pinMode(LEDlampYellow, OUTPUT);
pinMode(LEDlampGreen, OUTPUT);
pinMode(soundbuzzer, OUTPUT);
}
void loop() {
long durationindigit, distanceincm;
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
durationindigit = pulseIn(echoPin, HIGH);
distanceincm = (durationindigit/5) / 29.1;
if (distanceincm < 50) { digitalWrite(LEDlampGreen, HIGH);
}
else {
digitalWrite(LEDlampGreen, LOW);
}
if (distanceincm < 20) {
digitalWrite(LEDlampYellow, HIGH);
}
else {
digitalWrite(LEDlampYellow,LOW);
}
if (distanceincm < 5) {
digitalWrite(LEDlampRed, HIGH); sound = 1000;
}
else {
digitalWrite(LEDlampRed,LOW);
} if (distanceincm > 5 || distanceincm <= 0){
Serial.println("Outside the permissible range of distances");
noTone(soundbuzzer);
}
else {
Serial.print(distanceincm);
Serial.println(" cm");
tone(soundbuzzer, sound);
}
delay(300);
}