To control the two lamps using the Arduino UNO board, two relays and push buttons, you will need the following components:
1- Arduino UNO board:
The Arduino UNO board is a popular microcontroller board based on the ATmega328P microcontroller. It is one of the most commonly used Arduino boards and provides a versatile platform for creating interactive electronic projects.
The Arduino UNO board is suitable for beginners and experienced users alike, offering a flexible and accessible platform for prototyping and building various electronic projects, from simple LED blinking to complex robotics and home automation systems.
2- Two relays modules:
You'll need two relays modules that are compatible with the Arduino UNO and can switch the high-voltage lamps. Ensure it's rated for the voltage and current required for your lamps.
3- Two lamps (220V):
The two lamps you want to control, which are rated for 220V.
4- Power Supply for the Lamp:
You'll need a power source for the lamps, typically a 220V AC power supply.
5- Wiring:
Various wires and cables for connecting the components in your circuit.
6- 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.
7- 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 (Ω).
8- 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.
9- Jumper Wires:
You'll need jumper wires to make connections between the Arduino UNO, the two lamps, two relays, two push buttons and breadboard.
Once you have the necessary components, you can proceed with the following steps to control the two lamps with two push buttons:
1- Connect the first relay module to the first push button:
- Connect one leg of the push button to pin 4 of the Arduino.
- Connect another leg of the push button to the 5V pin of the Arduino.
- Place a 10k Ohm resistor between the third leg of the push button and the GND pin of the Arduino.
2- Connect the first relay to the Arduino UNO:
- Connect the relay's control pin (S) to pin 2 of Arduino UNO board.
- Connect the pin (+) of relay to pin 3.3V of Arduino UNO board.
- Connect the relay's ground pin (GND) to the Arduino UNO's GND.
3- Connect the first lamp and the power supply to the Relay:
- Connect one of the the power supply's wires to the relay's common (COM) terminal.
- Connect the wire of the lamp to the normally open (NO) terminal of the relay.
- Connect the neutral wire of the power supply directly to the neutral wire of the lamp.
4- Connect the seconf relay module to the second push button:
- Connect one leg of the push button to pin 5 of the Arduino.
- Connect another leg of the push button to the 5V pin of the Arduino.
- Place a 10k Ohm resistor between the third leg of the push button and the GND pin of the Arduino.
5- Connect the second relay to the Arduino UNO:
- Connect the relay's control pin (S) to pin 3 of Arduino UNO board.
- Connect the pin (+) of relay to pin 3.3V of Arduino UNO board.
- Connect the relay's ground pin (GND) to the Arduino UNO's GND.
6- Connect the second lamp and the power supply to the Relay:
- Connect one of the the power supply's wires to the relay's common (COM) terminal.
- Connect the wire of the lamp to the normally open (NO) terminal of the relay.
- Connect the neutral wire of the power supply directly to the neutral wire of the lamp.
To program an Arduino Uno board to turn on two lamps using two relays and two push buttons, you'll need to write the Arduino code. Here's a sample code to get you started:
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 |
#define Relay_lamp1 2 // the first relay connected to pin 2 of the Arduino #define lamp1_BUTTON_PIN 4 // the first push button connected to pin 4 of the Arduino #define Relay_lamp2 3 // the second relay connected to pin 3 of the Arduino #define lamp2_BUTTON_PIN 5 // the second push button connected to pin 5 of the Arduino byte lamp1lastButtonState = LOW; // to keep the state of the first button byte lamp1State = LOW; // to keep the state of first relay byte lamp2lastButtonState = LOW; // to keep the state of the second button byte lamp2State = LOW; // to keep the state of second relay unsigned long debounceDuration = 50; // millis unsigned long lastTimelamp1ButtonStateChanged = 0; unsigned long lastTimelamp2ButtonStateChanged = 0; void setup() { // initialize the first relay pin as an output: pinMode(Relay_lamp1, OUTPUT); // initialize the first pushbutton pin as an input: pinMode(lamp1_BUTTON_PIN, INPUT); // initialize the second relay pin as an output: pinMode(Relay_lamp2, OUTPUT); // initialize the second pushbutton pin as an input: pinMode(lamp2_BUTTON_PIN, INPUT); } void loop() { if (millis() - lastTimelamp1ButtonStateChanged > debounceDuration) { byte lamp1buttonState = digitalRead(lamp1_BUTTON_PIN); // vérifie si le bouton poussoir est enfoncé if (lamp1buttonState != lamp1lastButtonState) { lastTimelamp1ButtonStateChanged = millis(); lamp1lastButtonState = lamp1buttonState; if (lamp1buttonState == LOW) { lamp1State = (lamp1State == HIGH) ? LOW: HIGH; // Toggle the state of the relay when the button has been released digitalWrite(Relay_lamp1, lamp1State); // Turn the first lamp on or off depending on the state of the relay } } } if (millis() - lastTimelamp2ButtonStateChanged > debounceDuration) { byte lamp2buttonState = digitalRead(lamp2_BUTTON_PIN); if (lamp2buttonState != lamp2lastButtonState) { lastTimelamp2ButtonStateChanged = millis(); lamp2lastButtonState = lamp2buttonState; if (lamp2buttonState == LOW) { lamp2State = (lamp2State == HIGH) ? LOW: HIGH; // Toggle the state of the relay when the button has been released digitalWrite(Relay_lamp2, lamp2State); // Turn the second lamp on or off depending on the state of the relay } } } } |
This code sets up the two push buttons to toggle the two relays state when pressed. When you press one of the buttons, it will turn the lamp on, and when you press it again, it will turn the lamp off.
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