Panier d’achat

Aucun produit dans le panier.

LED Feu tricolore de circulation 5V

16.00 د.م.


Un module idéal pour simuler un feu tricolore.

  • couleur de la lumière: rouge, jaune et vert
  • tension de fonctionnement: 5 V/3.3 V
  • courant de fonctionnement: Lorsque vous utilisez 5 V sortie au niveau haut, la lumière rouge 13mA, jaune lumière 13mA, vert lumière 25mA.
  • compatible avec les différentes cartes de développement arduino, compatible et autres….

161 en stock

Quantité Discount (%) Prix
1 - 49 16.00 د.م.
50+ 12.5 % 14.00 د.م.
UGS : AL016 Catégories : , Étiquettes : , , , , , , , , ,

Tutoriel : Utilisation MODULE LED FEU TRICOLORE DE CIRCULATION 5V avec ARDUINO (English)


Here is a quick introduction to using the traffic light module. Hopefully it will provide you with the confidence include the beginnings of traffic control in your project.This example will demonstrate the use of an Arduino UNO in controlling the module. Once connected and the program loaded, lights will perform a pedestrian crossing sequence and provide feedback to the serial monitor.


Components

  • 1pcs Arduino UNO
  • 1pcs Traffic Light Module
  • 4pcs Male to Female Jumper Cables

Wiring

Wire the two boards together as can be seen in the image below, taking care to match the pin numbers.

Traffic Light Module_UNO Wiring Example_Fritzing ProjectCoding

The code consists of the definitions, a setup and a single loop. Initially the pin numbers and delay lengths are defined. Following this the setup defines the pins as outputs, sets them to a starting value and then launches the serial monitor. The loop contains the control program that will run continuously after the setup. The loop monitors the serial input for the letter ‘P’. Once it has been entered into the monitor, the sequence begins. First the green light is extinguished and the amber light lit. A loop cycles it through a number of times as defined by the earlier declared delay variable, each cycle passes through a pause. On completion the amber turns to red and it pauses once more in the same fashion. Following which the flashing amber state is reached. The flashing is controlled by doubling the amber delay, halving the pause and toggling the amber pin on each loop through. Once this has been completed the sequence finalises, the green is lit and the initial state restored.

Load the code below into the Arduino IDE and upload it to your board.

/*
  A simple program designed to setup and demonstrate the 3 Traffic Light LED module

  The program simulates a simple pedestrian crossing.
  Micro-Electroniques Générales au Maroc
 
*/
 
int redLEDpin = 13; // pin number for the red LED
int amberLEDpin = 12; // pin number for the amber LED
int greenLEDpin = 11; // pin number for the green LED

int amberDelay = 5; // pause in seconds to maintain the amber light
int redDelay = 10; // pause in seconds to maintain the red light

void setup() {
  pinMode(redLEDpin, OUTPUT); // set the R signal pin as an output
  pinMode(amberLEDpin, OUTPUT); // set the Y signal pin as an output
  pinMode(greenLEDpin, OUTPUT); // set the G signal pin as an output

  digitalWrite(redLEDpin,LOW); // set the red LED to off by default
  digitalWrite(amberLEDpin,LOW); // set the amber LED to off by default
  digitalWrite(greenLEDpin,HIGH); // set the green LED to on by default
  
  Serial.begin(9600); // launch the serial monitor
  Serial.println("Flux Workshop Traffic Light Example");
  Serial.println("Enter P to Cross");  
}

void loop() {
  // send data only when you receive data:
  if (Serial.available() > 0) { // check if data is available on the serial input
    char input = Serial.read(); // store the serial data in a variable
    if (input == 'P'){ // check if the incoming data is the letter 'P'
      Serial.println("--- BUTTON HAS BEEN PRESSED ---");
      Serial.println("--- GOING TO AMBER ---");  
      for (int count = 0; count <= amberDelay; count++){ // Loop through the amber sequence
        digitalWrite(amberLEDpin,HIGH); // set the amber LED to on
        digitalWrite(greenLEDpin,LOW); // set the green LED to off
        delay(1000);
      }
      Serial.println("--- GOING TO RED ---"); 
      for (int count = 0; count <= redDelay; count++){ // Loop through the amber sequence
        digitalWrite(amberLEDpin,LOW); // set the amber LED to off
        digitalWrite(redLEDpin,HIGH); // set the red LED to on
        delay(1000);
      }
      Serial.println("--- GOING TO FLASHING AMBER ---"); 
      for (int count = 0; count <= amberDelay*2; count++){ // Loop through the flashing amber sequence
        digitalWrite(amberLEDpin,!digitalRead(amberLEDpin)); // toggle the amber LED
        digitalWrite(redLEDpin,LOW); // set the red LED to off
        delay(500); // this is a shortened delay for it to flash faster
      }
      Serial.println("--- GOING TO BACK TO GREEN ---"); 
      digitalWrite(amberLEDpin,LOW); // set the amber LED to off
      digitalWrite(greenLEDpin,HIGH); // set the green LED to on
      delay(1000);
      Serial.println("Enter P to Cross"); // resend the instruction
    }
  }
}

Running

With the board loaded with the program and all the connections made the serial monitor will begin and await the input of the letter ‘P’. The sequence will then begin. The output should be as seen below. Please note the camera has a hard time dealing with bright LEDs.


What to try next?

  • Trigger a beeper as the sequence run like a pedestrian crossing.
  • Set the sequence into a container function and build up a full traffic junction.

Pour toutes questions, remarques ou suggestions relatives à ce tutoriel, n’hésitez pas à nous contacter à notre page Facebook. (Même à 23h ou minuit si je ne dors pas je vous répondrai!)


Avis

Il n’y a pas encore d’avis.

Soyez le premier à laisser votre avis sur “LED Feu tricolore de circulation 5V”

Votre adresse e-mail ne sera pas publiée. Les champs obligatoires sont indiqués avec *

Tous les résultats de recherche
×