Push buttons can play a significant role in robotics by serving as a means of human interaction and control in various ways:
Start/Stop Control: Push buttons are often used to start and stop robotic systems. For example, a start button can initiate the robot's operation, and a stop button can halt it in case of an emergency or to end a task.
Emergency Stop (E-Stop): Emergency stop buttons are critical safety features in robotics. They provide an immediate and easily accessible way to shut down the robot in case of a malfunction or a hazardous situation. This is crucial for ensuring the safety of both the robot and the people working around it.
Mode Selection: In more complex robotic systems, push buttons can be used to select different operational modes, such as autonomous mode, manual control mode, or specific task modes. Users can switch between these modes using buttons.
User Interface: Push buttons can be used to provide a simple user interface for users to interact with the robot. They can trigger specific actions or functions, like moving an arm, activating a gripper, or changing the robot's behavior.
Teaching and Programming: Push buttons can be used in a teaching or programming mode, where operators can manually move robot arms or other components to demonstrate desired motions or trajectories. This information can be recorded and later reproduced by the robot.
Limit or Home Switches: Push buttons can be used as limit switches or home switches in robotics. They help the robot establish reference points or boundaries for its movement, ensuring accuracy and safety.
Calibration and Configuration: Push buttons can be used for calibrating sensors, configuring parameters, or setting up the robot's initial conditions. They can be part of a setup process to ensure that the robot operates as intended.
Reset or Clear Function: Push buttons can be used to reset the robot's state, clear error conditions, or restart specific tasks. They can help recover from unexpected situations.
User Feedback: Some push buttons may include indicator lights or displays to provide feedback to the user, such as the current mode, status, or system health.
Push buttons, when combined with microcontrollers and control systems, offer a convenient way for humans to interact with and control robots, whether in industrial automation, research, or various other applications. Their design and functionality can vary based on the specific needs of the robotic system and the safety requirements associated with it.
To control three LEDs using an ESP32 and push buttons, you will need the following components:
ESP32 board :
The ESP32 is a popular and versatile microcontroller board that is widely used in the field of embedded systems and Internet of Things (IoT) development. It is developed by Espressif Systems and is part of the ESP (Espressif) series of microcontrollers.
LEDs :
LED stands for "Light Emitting Diode." It is a semiconductor device that emits light when an electric current passes through it.
Push button:
A push button, also known as a momentary switch or tactile switch, is a simple yet commonly used electromechanical component in electronics. It is designed to make or break an electrical connection temporarily when pressed or released.
Resistance
In the context of electronics and electrical circuits, a resistance refers to a passive two-terminal electrical component that restricts the flow of electric current. It is typically measured in ohms (Ω).
Breadboard:
A breadboard is a prototyping board that allows you to build circuits without soldering. It provides a convenient way to connect the components together.
Jumper Wires:
You'll need jumper wires to make connections between the ESP32 board, two LED , push buttons and breadboard.
Once you have the necessary components, you can proceed with the following steps to control three LEDs with push buttons:
Red LED :
1- Connect the anode (longer lead) of the red LED to a current-limiting resistor (e.g., 220-330 ohms).
2- Connect the other end of the resistor to one of the ESP32's digital output pins (pin GPIO 23).
3- Connect the cathode (shorter lead) of the red LED to the ground (GND) on the ESP32.
Green LED :
1- Connect the anode (longer lead) of the green LED to a current-limiting resistor (e.g., 220-330 ohms).
2- Connect the other end of the resistor to one of the ESP32's digital output pins (GPIO 21).
3- Connect the cathode (shorter lead) of the green LED to the ground (GND) on the ESP32.
Yellow LED :
1- Connect the anode (longer lead) of the yellow LED to a current-limiting resistor (e.g., 220-330 ohms).
2- Connect the other end of the resistor to one of the ESP32's digital output pins (GPIO 18).
3- Connect the cathode (shorter lead) of the yellow LED to the ground (GND) on the ESP32.
For push buttons
1- Push button 1:
- Connect one leg of the push button to pin GPIO 22 of the ESP32 board.
- Connect another leg of the push button to pin GND of the ESP32 board.
2- Push button 2:
- Connect one leg of the push button to pin GPIO 19 of the ESP32 board.
- Connect another leg of the push button to pin GND of the ESP32 board.
3- Push button 3:
- Connect one leg of the push button to pin GPIO 5 of the ESP32 board.
- Connect another leg of the push button to pin GND of the ESP32 board.
You can connect to your ESP32 board using a serial terminal (e.g., PuTTY, minicom) or use a tool like Thonny to write and execute MicroPython code.
Here's a simple example code to turn on the three LEDs (red LED, green LED and yellow LED) when the push buttons are pressed:
1- Import the necessary modules:
1 2 |
import machine from machine import Pin import time |
2- Configure the pins (GPIO) for the push buttons and the three LED:
1 2 3 4 5 6 7 8 |
red_led=Pin(23, Pin.OUT) red_button = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_UP) green_led=Pin(21, Pin.OUT) green_button = machine.Pin(19, machine.Pin.IN, machine.Pin.PULL_UP) yellow_led=Pin(18, Pin.OUT) yellow_button = machine.Pin(5, machine.Pin.IN, machine.Pin.PULL_UP) |
3- Create a variable to keep the state of the three LEDs (0 if the LED is off and 1 if the LED is on)
1 2 3 |
red_state=0; green_state=0; yellow_state=0; |
Create a loop to monitor the push buttons status and turn the three LEDs on/off accordingly:
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
while True: red_first = red_button.value() time.sleep(0.01) red_second = red_button.value() if red_first and not red_second: #Button pressed print('Button pressed!') if (red_state==0): red_led.value(1) # turn on red LED red_state=1 else: red_led.value(0) # turn off red LED red_state=0; time.sleep(0.5) elif not red_first and red_second: print('Button released!') #led_rouge.value(0) green_first = green_button.value() time.sleep(0.01) green_second = green_button.value() if green_first and not green_second: # Button pressed print('Button pressed!') if (green_state==0): green_led.value(1) # turn on green LED green_state=1 else: green_led.value(0) # turn off green LED green_state=0; time.sleep(0.5) elif not green_first and green_second: print('Button released!') yellow_first = yellow_button.value() time.sleep(0.01) yellow_second = yellow_button.value() if yellow_first and not yellow_second: # Button pressed print('Button pressed!') if (yellow_state==0): yellow_led.value(1) # turn on yellow LED yellow_state=1 else: yellow_led.value(0) # turn off yellow LED yellow_state=0; time.sleep(0.5) elif not yellow_first and yellow_second: print('Button released!') |
Here is the complete program in Micropython:
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import machine from machine import Pin import time red_led=Pin(23, Pin.OUT) # for red LED red_button = machine.Pin(22, machine.Pin.IN, machine.Pin.PULL_UP) red_state=0; green_led=Pin(21, Pin.OUT) # for green LED green_button = machine.Pin(19, machine.Pin.IN, machine.Pin.PULL_UP) green_state=0; while True: red_first = red_button.value() time.sleep(0.01) red_second = red_button.value() if red_first and not red_second: print('Button pressed!') if (red_state==0): red_led.value(1) red_state=1 else: red_led.value(0) red_state=0; time.sleep(0.5) elif not red_first and red_second: print('Button released!') green_first = green_button.value() time.sleep(0.01) green_second = green_button.value() if green_first and not green_second: print('Button pressed!') if (green_state==0): green_led.value(1) green_state=1 else: green_led.value(0) green_state=0; time.sleep(0.5) elif not green_first and green_second: print('Button released!') yellow_first = yellow_button.value() time.sleep(0.01) yellow_second = yellow_button.value() if yellow_first and not yellow_second: print('Button pressed!') if (yellow_state==0): yellow_led.value(1) yellow_state=1 else: yellow_led.value(0) yellow_state=0; time.sleep(0.5) elif not yellow_first and yellow_second: print('Button released!') |
When the button is pressed (the state is low), the LED lights up. If the button is pressed another time, the LED turns off. The 0.5 second delay is used to prevent pushbutton bounce, which can cause multiple button activations with a single press.
This simple example demonstrates how to use MicroPython to control three LEDs using push buttons with an ESP32 board.
Educational robotics refers to the use of robots and robotics technology to promote learning in educational settings. It involves the integration of technology, engineering, and computer science into the classroom, allowing students to engage in hands-on, project-based learning experiences.
In this context, our website represents an excellent resource for parents, teachers and children who wish to discover robotics.
Zaouiet Kontech-Jemmel-Monastir-Tunisia
+216 92 886 231
medaliprof@gmail.com
Robotic site created by MedAli-Teacher info