Solar Powered Proximity Sensor

654

5

3

Posted

Introduction: Solar Powered Proximity Sensor

By:

Figueroa, Nicolás

Matallana, Marcelo

Noboa, Rafael

Peña, Jheraldo

Step 1: Get the Materials

7 220ohm resistors

7 different colored leds

1 Solar Panel

1 Rehcargable battery

1 Arduino Uno

1 HC-SR04

1 Buzzer

Step 2: Assembling Time!

Connect the cables to the Arduino Uno (as shown in the image).
Then weld the cables to the resistor, then weld the resistor to the larger end of each LED, finally connect each LED to a negative cable.
The resistors should be interconnected with a copper cable.

Then charge the code to the Arduino Uno.

Finally connect the solar panel to the recycled battery pack, be careful no to confuse the positive and negative.

Step 3: Time to Code!

As creating a code can be difficult, here is the code with an explanation to make it more comprehensive.

Also... The parts in spanish wont affect the code, just copy and paste it to the Arduino uno program. (A peruvian friend ask for explanation ,so here it is buddy :D )

int trigger = 10; // declaramos la palabra trigger como un tipo entero y al mismo tiempo reemplaza al pin 9
int echo = 9; // declaramos la palabra echo como un tipo entero y al mismo tiempo reemplaza al pin 8 float tiempo_de_espera,distancia; // creamos una variable de fotante; es decir, nos puede dar resultados en decimales.

void setup() { Serial.begin (9600); // establemos la comucicacion serial pinMode (trigger, OUTPUT); // declarmos el pin 9 como salida pinMode (echo, INPUT); // declaramos el 8 como entrada }

void loop() { digitalWrite (trigger,LOW); // ponemos en bajo el pin 8 durante 2 microsegundos delayMicroseconds(2); digitalWrite (trigger, HIGH);// ahora ponemos en alto pin 8 durante 10 microsegundos; delayMicroseconds (10); // pues este el momento en que emite el sonido durante 10 segungos digitalWrite (trigger, LOW); // ahora ponemos en bajo pin 8

tiempo_de_espera = pulseIn (echo,HIGH); // pulseIn, recoge la señal del sonido que emite el trigger /*La función pulseIn espera la aparición de un pulso en una entrada y mide su duración, dando como resultado la duración medida El primer parámetro (ECHO) es el pin sobre el que se realizará la medición. Y el segundo parámetro (HIGH) indica si el pulso a esperar será un 1 (HIGH) o un 0 (LOW). */ distancia =(tiempo_de_espera/2)/29.15; // formula para hallar la distancia

Serial.print (distancia); // imprimimos la distancia en cm Serial.println ("cm"); delay (100); if (distancia>=251 && distancia <=400){ // analogWrite (2,0); analogWrite (3,0); analogWrite (4,0); analogWrite (5,0); analogWrite (6,0); analogWrite (7,0); analogWrite (8,0); } if (distancia>=225 && distancia <=250){ analogWrite (2,255); analogWrite (3,0); analogWrite (4,0); analogWrite (5,0); analogWrite (6,0); analogWrite (7,0); analogWrite (8,0); } if (distancia>=201 && distancia <=224){ analogWrite (2,255); analogWrite (3,255); analogWrite (4,0); analogWrite (5,0); analogWrite (6,0); analogWrite (7,0); analogWrite (8,0); }if (distancia>=176 && distancia <=200){ analogWrite (2,255); analogWrite (3,255); analogWrite (4,255); analogWrite (5,0); analogWrite (6,0); analogWrite (7,0); analogWrite (8,0); } if (distancia>=150 && distancia <=175){ analogWrite (2,255); analogWrite (3,255); analogWrite (4,255); analogWrite (5,255); analogWrite (6,0); analogWrite (7,0); analogWrite (8,0); } if (distancia>=101 && distancia <=149){ analogWrite (2,255); analogWrite (3,255); analogWrite (4,255); analogWrite (5,255); analogWrite (6,255); analogWrite (7,0); analogWrite (8,0); } if (distancia>=50 && distancia <=100){ analogWrite (2,255); analogWrite (3,255); analogWrite (4,255); analogWrite (5,255); analogWrite (6,255); analogWrite (7,255); analogWrite (8,0); } if (distancia>=0 && distancia <=50){ analogWrite (2,255); analogWrite (3,255); analogWrite (4,255); analogWrite (5,255); analogWrite (6,255); analogWrite (7,255); analogWrite (8,255); } return distancia; }

Step 4: Styling

If wanted you can put it altogether in a nice case.
To do so you will need 4 wooden boards of 10.5cm by

20cm for the 4 sides and 2 of 20 cm by 11.5 for the top and bottom parts .

Make holes, use a drill if needed, for the LED lights, the HC-SR04 sensor and the buzzer to pass through.

Finally glue the solar panel to the top of the box.

Step 5: Video!

Share

    Recommendations

    • Spotless Contest

      Spotless Contest
    • Space Challenge

      Space Challenge
    • Science of Cooking

      Science of Cooking
    user

    We have a be nice policy.
    Please be positive and constructive.

    Tips

    Questions

    2 Comments

    Cool project. If you want to make the video a little easier for people to view you can upload it to a site like YouTube and then embed it on the page using the embed video tool in the step editor.