Okay so I have had to make many adjustments because it hates being in a box. I think the stuff I have been using is wearing out. I think the connections in the little holes of the breadboard are kind of iffy sometimes. I would have to jiggle the sensor around until it would work when it was directly plugged into the breadboard.
I deleted the buzzer from the project because for the intended use it was going to be too quiet to alert some one in a car.
I have also added to where it hooks up to a battery and switch. I bought the toggle switch at Home Depot.
I found a good sized box that used to be gift box and I painted it to put my project in. I made holes for the sensor, LEDs, and the switch. Everything fits quite snug without it just being squished in.
I had 3 LEDs originally, but not all three would ever work together once I put it in the box, so I took out the yellow LED. So along with this adjustment I also need to update my code. I move my green LED over to the place of the yellow LED. So in my code I just replaced yellow with green and deleted out the extra greens along with the coding for my buzzer that I am no longer using.
To make my LEDs reach the hole I made for them comfortably, I attached each of the legs to an alligator clip and then the alligator clips to the little things that go into the breadboard. For my sensor to reach, I soldered some wire I bought at Home Depot and then taped one of the little wires to the breadboard wires and then to the breadboard. It looks really horrible, but it turned out to work the best.
Here's my updated code:
#define echoPin 10 // Echo Pin
#define trigPin 9 // Trigger Pin
const int dur = 20;
const int red1 = 11;
const int green1 = 13;
int maximumRange = 200; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
void setup() {
// put your setup code here, to run once:{
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
pinMode(green1, OUTPUT);
pinMode(red1, OUTPUT);
digitalWrite(green1, HIGH);
digitalWrite(red1, HIGH);
delay(300);
digitalWrite(green1, LOW);
digitalWrite(red1, LOW);
}
void loop() {
// put your main code here, to run repeatedly: {
/* The following trigPin/echoPin cycle is used to determine the
distance of the nearest object by bouncing soundwaves off of it. */
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);
//Calculate the distance (in cm) based on the speed of sound.
distance = duration/58.2;
if (distance < 121){
digitalWrite(green1, LOW);
digitalWrite(red1, HIGH);
} else if (distance < 152){
digitalWrite(green1, HIGH);
digitalWrite(red1, LOW);
}
//Delay 50ms before next reading.
delay(50);
}
I kept trying to get it to work outside, but it would never recognize the car, but when
I brought it inside and raised it from the floor to the ceiling it worked just fine. Maybe it was stressing the cords when it was sitting upright.
My New Material List:
- Arduino Kit ( https://www.amazon.com/Elegoo-
Project-Starter-Tutorial- Arduino/dp/B01DGD2GAO/ref=sr_ 1_7?s=electronics&ie=UTF8&qid= 1504800970&sr=1-7&keywords= Arduino+Kit ) - Arduino(came in an arduino kit)
- Breadboard (arduino kit)
- Ping Sensor (Amazon.com)
- Red and Green LEDs (arduino kit)
- 220 Ohm resistors(2) (arduino kit)
- Soldering Kit ( https://www.amazon.com/
Soldering-Electronics- Adjustable-Temperature- Portable/dp/B071VLFGXL/ref=sr_ 1_8?s=hi&ie=UTF8&qid= 1504800558&sr=1-8&keywords= Soldering+Iron+Kit) - Thicker wire to solder (Home Depot)
- Arduino Software ( https://www.arduino.cc/en/Main/Software )
- A box to put end product in(a reused old gift box)
- Ping sensor ( https://www.amazon.com/Elegoo-HC-SR04-Ultrasonic-Distance-MEGA2560/dp/B01COSN7O6/ref=sr_1_1?s=electronics&ie=UTF8&qid=1512663686&sr=1-1&keywords=ping+sensor )
- toggle switch (Home Depot)
- 9V Battery (Walmart- I used a Duracell)
No comments:
Post a Comment