Home > Arduino > The TechsPassion Starter Shield

07/22/2023

The TechsPassion Starter Shield

Writing about The TechsPassion Starter Shield for educational and informational purposes only. however, do not hesitate to use this information on your own risk as we make no warranty of any kind.

One of my goals for this channel is to simplify learning for everyone. I'm introducing the perfect tool to kickstart your Arduino journey - the Techs Passion Starter Shield! Get ready to dive into endless possibilities with the Arduino Nano, 3 LEDs, 3 buttons, a distance sensor, and a light sensor.

Wiring and pins

LED Blinking Itself Using Light Sensor


#include 
#include 
#include 

const int LDR_PIN = A0;  // Light sensor (LDR) connected to analog pin A0
const int LED_PIN = 2;   // LED connected to digital pin 2

#define OLED_RESET 4
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  pinMode(LED_PIN, OUTPUT);
  // No need to set pinMode for the LDR, as it's an analog input
  pinMode(4, OUTPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (1);
  }

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(20, 20);
  display.println(F("Light:"));
  display.display();
  delay(2000);
}

void loop() {
  digitalWrite(4, LOW);
  // Read the LDR value (0 to 1023)
  int lightValue = analogRead(LDR_PIN);
  Serial.println(lightValue); // Optional: Print the LDR value to the Serial Monitor for debugging

  // Display the light value on the OLED
  display.clearDisplay();
  display.setCursor(20, 20);
  display.print(F("Light: "));
  display.print(lightValue);
  display.display();

  // Check if the light is off (LDR value is above a certain threshold)
  if (lightValue > 800) { // You might need to adjust this threshold based on your LDR and environment
    digitalWrite(LED_PIN, LOW); // Turn on the LED
  } else {
    digitalWrite(LED_PIN, HIGH);  // Turn off the LED
  }

  // Add a small delay to avoid rapid fluctuations in readings
  delay(500);
}


Light Sensor


#include 
#include 
#include 

const int LDR_PIN = A0;  // Light sensor (LDR) connected to analog pin A0
const int LED_PIN = 2;   // LED connected to digital pin 2

#define OLED_RESET 4
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 32

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET);

void setup() {
  pinMode(LED_PIN, OUTPUT);
  // No need to set pinMode for the LDR, as it's an analog input
  pinMode(4, OUTPUT);

  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
    Serial.println(F("SSD1306 allocation failed"));
    while (1);
  }

  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(20, 20);
  display.println(F("Light:"));
  display.display();
  delay(2000);
}

void loop() {
  digitalWrite(4, LOW);
  // Read the LDR value (0 to 1023)
  int lightValue = analogRead(LDR_PIN);
  Serial.println(lightValue); // Optional: Print the LDR value to the Serial Monitor for debugging

  // Display the light value on the OLED
  display.clearDisplay();
  display.setCursor(20, 20);
  display.print(F("Light: "));
  display.print(lightValue);
  display.display();

  // Check if the light is off (LDR value is above a certain threshold)
  if (lightValue > 900) { // You might need to adjust this threshold based on your LDR and environment
    digitalWrite(LED_PIN, HIGH); // Turn on the LED
  } else {
    digitalWrite(LED_PIN, LOW);  // Turn off the LED
  }

  // Add a small delay to avoid rapid fluctuations in readings
  delay(100);
}


Push Button to turn LED


const int buttonPin = 10;  // the number of the pushbutton pin
const int ledPin = 2;    // the number of the LED pin

// variables will change:
int buttonState = 0;  // variable for reading the pushbutton status

void setup() {
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);
  
  delay(100);
  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {
    // turn LED on:
    digitalWrite(2, HIGH);
  } else {
    // turn LED off:
    digitalWrite(2, LOW);
  }
}

Display distance on OLED


#include 
#include 
#include 

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

const int trigPin = 7; // Trigger Pin
const int echoPin = 6; // Echo Pin
const long dist = 10; // This is the distance to turn on the LED
void setup() {
   pinMode(2, OUTPUT);
   pinMode(4, OUTPUT);
   pinMode(trigPin, OUTPUT);
   pinMode(echoPin, INPUT);

   // Initialize the OLED display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("Start");
  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop() {
   long duration, distinches;
   
   digitalWrite(trigPin, LOW);
   delayMicroseconds(2);
   
   digitalWrite(trigPin, HIGH);
   delayMicroseconds(10);
   digitalWrite(trigPin, LOW);
   
   duration = pulseIn(echoPin, HIGH);
   distinches = duration / 74 / 2;

   // Update OLED display with current LED and score
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("Distance: ");
  display.println(distinches);
  display.setCursor(0, 20);
  
  display.display();

   if (distinches < dist) {
    digitalWrite(2, HIGH);  // turn the LED 
    digitalWrite(4, LOW); 
    delay(100);
   } else {
    digitalWrite(2, LOW);   // turn the LED off
    digitalWrite(4, LOW); 
    delay(100);
   }
    
}

Synchronicity


#include 
#include 
#include 

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

// Pin numbers for LEDs
const int ledPins[] = {2, 3, 4};

// Pin numbers for buttons
const int buttonPins[] = {8, 9, 10};

// Variables to store the current LED and button states
int currentLED = 0;
int buttonState;
int lastButtonState[] = {LOW, LOW, LOW};

// Variable to keep track of the score
int score = 0;

void setup() {
  // Initialize the LED pins as outputs
  for (int i = 0; i < 3; i++) {
    pinMode(ledPins[i], OUTPUT);
  }

  // Initialize the button pins as inputs
  for (int i = 0; i < 3; i++) {
    pinMode(buttonPins[i], INPUT);
    digitalWrite(buttonPins[i], HIGH);  // Enable internal pull-up resistors
  }

  // Initialize the OLED display
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
  display.clearDisplay();
  display.setTextSize(2);
  display.setTextColor(SSD1306_WHITE);
  display.setCursor(0, 0);
  display.println("Game Start");
  display.display();
  delay(2000);
  display.clearDisplay();
}

void loop() {
  // Turn off all LEDs
  for (int i = 0; i < 3; i++) {
    digitalWrite(ledPins[i], LOW);
  }

  // Randomly select an LED to light up
  currentLED = random(3);
  digitalWrite(ledPins[currentLED], HIGH);

  // Update OLED display with current LED and score
  display.clearDisplay();
  display.setCursor(0, 0);
  display.print("LED: ");
  display.println(currentLED + 1);
  display.setCursor(0, 20);
  display.print("Score: ");
  display.println(score);
  display.display();

  // Read the state of each button
  for (int i = 0; i < 3; i++) {
    buttonState = digitalRead(buttonPins[i]);

    // Check if the button state has changed
    if (buttonState != lastButtonState[i]) {
      // Button has been pressed
      if (buttonState == LOW) {
        // Check if the correct button was pressed
        if (i == currentLED) {
          score++;
          display.clearDisplay();
          display.setCursor(0, 0);
          display.println("Correct!");
          display.setCursor(0, 20);
          display.print("Score: ");
          display.println(score);
          display.display();
          delay(1000);
        } else {
          display.clearDisplay();
          display.setCursor(0, 0);
          display.println("Wrong!");
          display.setCursor(0, 20);
          display.print("Score: ");
          display.println(score);
          display.display();
          delay(1000);
        }
      }
    }

    lastButtonState[i] = buttonState;
  }

  delay(500);  // Delay between each LED
}

The TechsPassion Starter Shield
All content and information on this web site is intended for educational and entertainment purposes only.