Step by Step Guide

Learn how to control outputs from your PIXIE M1 board. Specifically, you will make a small traffic light blink its red, yellow, and green LEDs in sequence. This is your first step into programming behavior using code.

 

1. What You’ll Need

2. Make the Connections

Connect the parts as shown by the diagram bellow

Traffic Light Module

  • G (Ground) → Connect to breadboard ground rail (blue/negative row)
  • R (Red LED) → Connect to Pixie M1 Pin 1
  • Y (Yellow LED) → Connect to Pixie M1 Pin 3
  • G (Green LED) → Connect to Pixie M1 Pin 2

Push Button

  • G (Ground) → Connect to breadboard ground rail (blue/negative row)
  • VIN (Power) → Connect to Pixie M1 3V3 pin
  • S (Signal) → Connect to Pixie M1 Pin 6

3. Connect to PC & Upload Code

  • Install Arduino IDE and Setup Axiometa PIXIE M1 if you haven't already
  • Connect the Pixie M1 to your computer using the USB-C cable
  • Select the correct board in Arduino IDE:
  • Go to Tools → Board →  Axiometa Pixie M1
  • Copy and Paste the code you can find at the end of this page.
  • Upload code (CMD+U or CTRL+U)

4. Test

After uploading Press the button - the traffic light sequence should start:

  • Red light for 2 seconds
  • Yellow light for 2 seconds
  • Green light for 2 seconds
  • Green Flashing
  • Back to Red

Next Steps:

  • Change the timing of each light
  • Add sound effects with a buzzer, for alarming visually impaired
Back to blog

Arduino Code

example.ino
// Traffic Light Simulation
// Red LED on pin 1, Yellow LED on pin 2, Green LED on pin 3
// Button on pin 6

const int redPin = 1;
const int yellowPin = 2;
const int greenPin = 3;
const int buttonPin = 6;

bool buttonPressed = false;
bool lastButtonState = false;
bool trafficLightActive = false;

void setup() {
  // Initialize LED pins as outputs
  pinMode(redPin, OUTPUT);
  pinMode(yellowPin, OUTPUT);
  pinMode(greenPin, OUTPUT);
  
  // Initialize button pin as input with pullup resistor
  pinMode(buttonPin, INPUT_PULLUP);
  
  // Start with red light on (default state)
  digitalWrite(redPin, HIGH);
  digitalWrite(yellowPin, LOW);
  digitalWrite(greenPin, LOW);
}

void loop() {
  // Read button state (LOW when pressed due to pullup)
  bool currentButtonState = !digitalRead(buttonPin);
  
  // Detect button press (rising edge)
  if (currentButtonState && !lastButtonState && !trafficLightActive) {
    buttonPressed = true;
  }
  
  lastButtonState = currentButtonState;
  
  // If button was pressed and traffic light sequence isn't running
  if (buttonPressed && !trafficLightActive) {
    trafficLightActive = true;
    buttonPressed = false;
    
    // Start traffic light sequence
    runTrafficLightSequence();
    
    // Return to default red state
    digitalWrite(redPin, HIGH);
    digitalWrite(yellowPin, LOW);
    digitalWrite(greenPin, LOW);
    
    trafficLightActive = false;
  }
}

void runTrafficLightSequence() {
  // 1. One second wait (red stays on)
  delay(1500);
  
  // 2. Switch to yellow
  digitalWrite(redPin, LOW);
  digitalWrite(yellowPin, HIGH);
  digitalWrite(greenPin, LOW);
  delay(2000); // Yellow for 2 seconds
  
  // 3. Switch to green
  digitalWrite(redPin, LOW);
  digitalWrite(yellowPin, LOW);
  digitalWrite(greenPin, HIGH);
  delay(5000); // Green for 5 seconds
  
  // 4. Green flashing (3 times)
  for (int i = 0; i < 3; i++) {
    digitalWrite(greenPin, LOW);
    delay(500);
    digitalWrite(greenPin, HIGH);
    delay(500);
  }
  
  // 5. Switch to yellow
  digitalWrite(redPin, LOW);
  digitalWrite(yellowPin, HIGH);
  digitalWrite(greenPin, LOW);
  delay(2000); // Yellow for 2 seconds
  
  // 6. Back to red (handled in main loop)
}