I want to create a smart gate that can be opened with the press of a button and eventually through my phone.
After noticing that many places now use digital systems to open gates instead of manual methods, I decided to turn this idea into a project.
So I will start this assignment by making this idea by using a button and then I will search how to make it through my phone.
SOFTWARE
Simulation Software
Arduino Software
Tinkercad
Thinking about what the components make this function and idea (Servo motor, Push button, Buzzer)
Selecting from the components in tinker Arduino, breadboard, servo motor, push button, and buzzer
connections:
starting with connecting the 5-volt and GND from Arduino to positive and negative lines on the breadboard.
Servo --> Connect 3 pins of the servo motor with the +ve, and -ve lines in the breadboard and PIN 11 in Arduino.
Buzzer --> Connect the positive terminal to PIN 6 and the -ve terminal to the -ve line.
Push button --> Connect one terminal to PIN 7 and the other one to the -ve line.
Coding:
Thinking about how can I make the code to perform the idea.
I need to set the buzzer to LOW, and the servo to 0 degrees.
If the push button is pressed, the servo motor will rotate to 90 degrees, and the buzzer will release a sound for a second.
Then the servo will return to 0 degrees.
#include <Servo.h>
Servo servo_11;
void setup()
{
pinMode(6, OUTPUT);
servo_11.attach(11, 500, 2500);
pinMode(7, INPUT_PULLUP); // PULLUP to make the button always HIGH
}
void loop()
{
digitalWrite(6, LOW);
servo_11.write(0);
if (digitalRead(7) == LOW) {
digitalWrite(6, HIGH);
servo_11.write(90);
delay(1000); // Wait for 1000 millisecond(s)
servo_11.write(0);
}
}
First, testing each component to make sure that all works well.
Arduino --> connecting the 5-volt and GND from Arduino to positive and negative lines on the breadboard.
Servo --> Connect 3 pins of the servo motor with the +ve, and -ve lines in the breadboard and PIN 11 in Arduino.
Buzzer --> Connect the positive terminal to PIN 6 and the -ve terminal to the -ve line.
Push button --> Connect one terminal to PIN 7 and the other one to the -ve line.
Next, connected the Arduino Jake to the laptop, and from Arduino IDE I chose the correct port and then uploaded the code on Arduino.
First, when using the push button It did not work correctly, the servo was always rotating as if I were pressing the button.
Solution
I searched and found that I have to edit the code and make the button(INPUT_PULLUP), which ensures that the input pin reads a HIGH (logic 1) state when the switch is open (not pressed).
When the switch is pressed, the input pin is connected directly to the ground, causing it to read LOW (logic 0).
This week, I learned how to connect many components with Arduino, making code blocks to make the code of the project and I will use this in my final project.
In the MidWeek session, I worked with a peer to program the Arduino board to control one 7-segment display so that it counts down from 9 to 1 and it was a very fun activity.