It came up to my mind while thinking of the assignment to make a piggy bank or coin box that opens when I get near it.
I searched for similar projects like: coin box
But I decided to make it using IR sensor instead of the method shown in the link.
software
I used Arduino to burn the code to arduino uno to start the trial physically
I used tinker cad to test and simulate the circuit before prototyping it physically to protect the electronics from burning or any problem
materials
arduino uno + usb cable
IR sensor
servo motor
breadboard
for most connections
for connecting the IR sensor
At first, I opened tinker cad and started to put the electronics or tools I need then I started to wire it:
1- PIR sensor "INPUT": VCC ' red wire ' to +
GND ' black wire ' to -
out ' orange wire ' to pin 4
2- servo motor "OUTPUT": Power ' red wire ' to +
ground ' brown wire ' to -
signal ' green wire ' to pin 3
I then used code blocks to make the code as following:
from control I selected --> if - else
from math I selected --> 0 < 0 and brought HIGH or LOW block
from input I selected --> read digital pin
I put read digital pin 4 in the first 0 and HIGH block in the second 0. After that, I put the math in the if condition.
from output I choose --> rotate servo
I set the pin to 3 following my wiring diagram then set the degree to 45 " to open the door for the coin when I get near the IR " then wait 5 seconds then rotate to 90 degrees again
Else --> when I'm not near the sensor rotate servo to 90 degrees to close the door.
By choosing Blocks + text I viewed the code text to copy it to arduino IDE
IR sensor: VCC ' red wire ' to +
GND ' black wire ' to -
out ' Yellow wire ' to pin 4
servo motor:
Power ' red wire ' to +
ground ' brown wire ' to -
signal ' orange wire ' to pin 3
white wire from + to 5v
black wire from - to GND
copying the code to Arduino IDE then connecting the arduino to the laptop using usb cable then uploading
don't forget to check from tools:
board --> arduino uno
port --> the com connected to the arduino
Testing physically
First problem was that the action of the servo only happens when I move in the simulation but I needed time to put the coins before it closes the door again. So I put a delay for 5 secs as shown in the design part in the video
second problem was when I tested the IR sensor physically the servo was always 45 degrees and when I put my hand it goes to 90 degrees !!
This was solved by changing the condition from HIGH to LOW
to understand how this sensor works we could consider that it sends a laser line and as long as it's not cut this is it's HIGH value
but if we put an obstacle to cut this laser this is when it's LOW
So if it's LOW " there is an obstacle or I come close " it opens . wait 5 secs . close again
else --> HIGH " no one near " . Stay closed
It doesn't really relate to my final project but I gained more knowledge in making code using code blocks
Teamwork with Sorour making " HAHAHA waving hand " =D