In this tutorial we will see how to create an automatic garbage basket, with arduino nano an ultrasonic sensor, an sg90 servo motor and other electronic components. It includes the source code, electronic diagram and gerber file for printed circuit design, all totally free of charge.
You may be interested in projects in Arduino, pic, robotics, telecommunications, subscribe http://www.youtube.com/user/carlosvolt?sub_confirmation=1 videos with full source code and diagrams
Project electronic circuit
Project materials
Servo sg90: Features
- Dimensions (L x W xH) x 22.0 x 11.5 x 27 mm (0.86 x 0.45 x 1.0 inches)
- Weight: 9 grams
- Wired and connector weight: 10.6 grams
- Torque at 4.8 volts: 16.7 oz/in or 1.2 kg/cm
- Operating voltage: 4.0 to 7.2 volts
- Turning speed at 4.8 volts: 0.12 sec / 60 o
- Universal connector for most radio control receivers
- Compatible with cards like Arduino and microcontrollers that work at 5 volts.
How to control a servo motor?
You can place the servo shaft at various angles from 0 to 180o. Servos are controlled using a pulse width modulation (PWM) signal. This means that the PWM signal sent to the motor will determine the position of the shaft.
Arduino Nano
The Arduino Nano is a small board, complete and compatible with the test board based on the ATmega328 (Arduino Nano 3.x). It has about the same functionality as the Arduino Duemilanove, but in a different package. It only lacks a DC power connector and works with a Mini-B USB cable instead of a standard one.
Microcontroller | ATmega328 |
Architecture | Avr |
Operating voltage | 5 V |
Flash memory | 32 KB of which 2 KB uses the bootloader |
Sram | 2 KB |
Clock speed | 16 MHz |
Analog pins IN | 8 |
Eeprom | 1 KB |
DC current by I/O pins | 40 mA (I/O pins) |
Input voltage | 7-12 V |
Digital I/O Pins | 22 (6 of which are PWM) |
PWM output | 6 |
Energy consumption | 19 mA |
PCB size | 18 x 45 mm |
Weight | 7g |
Pin diagram
HC-SR04 Ultrasound Sensor Module
The HC-SR04 sensor is an excellent choice as an ultrasonic distance sensor. Its cost-benefit ratio makes it
optimal for a wide range of applications. The use of this module is quite simple because all
the control, transmission and reception electronics are contained in PCB. The user should only send a trigger pulse and
measure in high response pulse time. Only 4 cables are required to complete the interface with the HC-SR04 sensor module. The HC-SR04 is
compatible with most microcontrollers on the market, including the Arduino UNO,
Arduino MEGA and other compatible cards that work with 5 volts. There are libraries for this module that make the part of the software very simple. We
recommend purchasing some Dupont type cables to be able to use this sensor without welding.
It has two transducers: a piezoelectric emitter and receiver, in
addition to the electronics necessary for its operation. The operation of the sensor is as follows: the piezoelectric emitter emits 8
pulses of ultrasound(40KHz) after receiving the order on the TRIG
pin, the sound waves travel in the air and bounce when an object is found, the bounce
sound is detected by the piezoelectric receiver, then the ECHO pin changes to
High (5V) for a time equal to the time it delayed the wave from the time it was emitted until it was detected, the ECHO pulse time is measured by the microcontroller and so the distance to the object can be calculated. Sensor operation is not affected by sunlight or black material (although
soft materials aqueously such as fabric or wool can become difficult to detect).
Specifications:
-Simple interface: Only
4 cables
-Operating voltage: 5V DC -Sleep current: <
2mA
-Working current: 15mA -Measurement range: 2cm to 450cm
-Accuracy: +- 3mm
-Opening angle: 15o
-Ultrasound frequency: 40KHz
-Minimum duration of TRIG trigger pulse (TTL level): 10
S -Output ECO Pulse Duration (TTL Level): 100-25000’S
-Dimensions: 45mm x 20mm x 15mm
-Minimum waiting time between one measurement and the start of another 20ms (recommended 50ms)
Connection:
-VCC (+5V
DC) -TRIG (Ultrasound Shot)
-ECHO
(Ultrasound Reception) -GND (0V)
A 1K Resistor
A 5mm red LED diode
An ice cream stick
Three-pin Macho
Two nuts and screws
Waste basket
A Zocalo for Arduino
PCB Printed Circuit
Gerber file –> Gerber_CESTO_DE_RESIDUOS
Source code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
#include <Servo.h> const int Trigger = 2; //Pin 2 para el Trigger del sensor ultrasónico const int Echo = 3; //Pin 3 para el Eco del sensor ultrasónico Servo servoMotor1; // crear un objeto servo para controlar el servo void setup() { Serial.begin(9600);//iniciailzamos la comunicación a 9600 bps pinMode(Trigger, OUTPUT); //Se configura como salida pinMode(Echo, INPUT); //Se configura como entrada digitalWrite(Trigger, LOW);//Inicializamos el pin con estado BAJO o LOW servoMotor1.attach(4); // Asignamos el pin 4 para el control del servo servoMotor1.write(21); //Posisción inicial del servo para que quede la tapa cerrada } void loop() { long tiempo; //tiempo que demora en llegar el eco long distancia; //distancia en centimetros digitalWrite(Trigger, HIGH);//Activamos el pin 2 delayMicroseconds(10); //Enviamos un pulso durante 10us digitalWrite(Trigger, LOW); //Desactivamos el pin 2 tiempo = pulseIn(Echo, HIGH); //obtenemos el ancho del pulso y lo asignamos a la variable tiempo distancia = tiempo/59; //Convertimos el tiempo a distancia en cm if(distancia<=15){//Si la condición se cumple movemos el servo con eso abriemos la tapa del cesto de basura servoMotor1.write(80); delay(4000);//La tapa estrá abierta 4 segundos servoMotor1.write(21);//Tapa del cesto de basura cerrada } Serial.print("Distancia: ");//Imprimimos en el terminal serial el valor de la distancia en centímetros Serial.print(distancia); Serial.print("cm"); Serial.println(); delay(100); //Esperamos un tiempo breve antes de empezar de nuevo } |
SUBSCRIBE TO OUR NEWSLETTERS, RECEIVE IN YOUR EMAIL THE MOST OUTSTANDING NEWS, JUST BY ENTERING YOUR EMAIL
[wysija_form id=”1″]
RECOMMENDED PROJECT