กลับไปหน้ารวมไฟล์
sd-card-with-toggle-switch-led-919683-en.md

For this project, I wanted to be able to use a rocker on/off toggle switch to control an LED, and additionally connect an SD card so that in future projects I could modify the loop code to use the switch to read/write data to the SD card.

I had difficulty finding a good wiring diagram for this, so I've made one for you here with Fritzing!

The TWTADE rocker on/off switch (basic toggle switch) from Amazon comes attached to two wires already, so all you need to do is either strip off part of the insulation from the wires to be able to insert them fully into the breadboard, or otherwise solder typical male-male Arduino jumper wires to each wire end of the switch. Note that this is not a typical tactile button; it is a toggle switch that stays off when you toggle it off, and stays on when you toggle it on. In the Fritzing diagram I use a typical 3-pin on/off toggle switch, which you could alternatively use by soldering to the middle pin and one of the outer pins.

You are likely to run into initialization errors with your SD card, so make sure you format it properly to FAT16 before using it (you will likely need an SD card reader to connect it to your laptop to format it).

You are also likely to run into issues with the toggle switch and LED if you do not wire them correctly, or if you use the incorrect type of resistor (I got it to work with 1k Ohm resistor for the switch, and 220 Ohm resistor for the LED).

In the end, for this project, you will use a toggle switch to control an LED, and separately store some example data to a microSD card.

EXPANDED TECHNICAL DETAILS

Physical Logging Management

A practical project for creating a visual and physical control interface for high-capacity SD data loggers.

  • State-Triggered Write Logic: The Arduino monitors a physical toggle switch. The firmware only initiates or closes a file on the SD card based on the switch state (HIGH = Logging, LOW = Standby), preventing accidental data corruption.
  • Visual Status Feedback: Features a high-brightness LED that pulses during active write cycles. If the SD card is missing or fails to initialize, the Arduino triggers a unique "Blink Code" for instant hardware troubleshooting.

Hardware Hub

  • SPI Protocol Isolation: Uses the standard SD.h library to manage the SPI bus, ensuring that the logging process doesn't interfere with other connected sensors during the write-delay window.

ข้อมูล Frontmatter ดั้งเดิม

title: "SD Card With Toggle Switch & LED"
description: "This code uses a rocker toggle on/off switch to control an LED, and separately writes some data to a microSD Card."
author: "bobowman"
category: ""
tags:
  - "lights"
  - "rocker switch"
  - "toggle switch"
  - "sd card"
views: 2057
likes: 0
price: 1499
difficulty: "Intermediate"
components:
  - "1x SmartQ C307 USB 3.0 Portable Card Reader for SD, SDHC, SDXC, MicroSD, MicroSDHC, MicroSDXC, with Advanced All-in-One Design"
  - "1x Resistor 1k ohm"
  - "1x Arduino USB Cable"
  - "1x TWTADE Rocker Switch Toggle On/Off 2Pin Pre-Wired 6A/250V 10A/125V AC"
  - "1x HiLetgo Micro SD TF Card Adater Reader Module 6Pin SPI Interface Driver Module with chip Level Conversion for Arduino UNO R3 MEGA 2560 Due"
  - "1x LED (generic)"
  - "1x Arduino Uno Rev3"
  - "1x Solder Wire, Lead Free"
  - "1x Jumper wires (generic)"
  - "1x 128GB Micro SD Card for Nintendo Switch & Switch Lite, U3 V30 Memory Card Compatible with Mobile Device Storage Phone Tablet Drone, Class 10 MicroSD Card with High Speed Up to 95MB/s"
  - "1x Resistor 220 ohm"
  - "1x Soldering iron (generic)"
tools: []
apps:
  - "1x Arduino IDE"
downloadableFiles: []
documentationLinks: []
passwordHash: "cc7381593850f3cc8e066889657cb7f298325f1f6783c24bea3c42c938e8451b"
encryptedPayload: "U2FsdGVkX1/yzBtsRrtNEd2VQnWgK/GvB6gOPX7ZTeC+RZfHHEHDEhYmqb12HhPJ7TDr3JEg3+9MfxqTnG8lWhB1u95kroThNfZF+m/Shn8="
seoDescription: "Learn how to use a Toggle Switch to control an LED and write data to a microSD Card with Arduino in this simple project."
videoLinks: []
heroImage: "https://cdn.jsdelivr.net/gh/bigboxthailand/arduino-assets@main/images/projects/sd-card-with-toggle-switch-led-919683_cover.jpg"
lang: "en"