🎯 Objective
To read the bending position of a Flex Sensor using an ADC (MCP3008) with Raspberry Pi 3. This setup is useful in gesture control and wearable electronics.
🧰 Components Required
| Component | Quantity |
|---|---|
| Raspberry Pi 3 | 1 |
| Flex Sensor | 1 |
| 10KΩ Resistor | 1 |
| MCP3008 ADC | 1 |
| Breadboard & Jumper Wires | As required |
⚡ Circuit Connections
Flex Sensor + MCP3008 + Raspberry Pi 3
| MCP3008 Pin | Connect To |
|---|---|
| VDD & VREF | 3.3V (Pin 1) |
| AGND & DGND | GND (Pin 6) |
| CLK | GPIO11 (Pin 23) |
| DOUT | GPIO9 (Pin 21) |
| DIN | GPIO10 (Pin 19) |
| CS/SHDN | GPIO8 (Pin 24) |
| CH0 | Flex sensor voltage divider output |
🧠 Python Code
import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1350000
def read_channel(channel):
adc = spi.xfer2([1, (8 + channel) << 4, 0])
data = ((adc[1] & 3) << 8) + adc[2]
return data
try:
while True:
flex_value = read_channel(0)
print("🤸 Flex Sensor Reading:", flex_value)
time.sleep(0.5)
except KeyboardInterrupt:
spi.close()
📊 Output
- Shows analog value corresponding to how much the sensor is bent.
- The more it bends, the higher the value.
💡 Applications
- Gesture recognition gloves
- Robotic hand control
- Wearable devices
🎯 उद्दिष्ट
Flex Sensor चा वापर करून त्याचे वाकले जाणे वाचणे आणि MCP3008 ADC च्या मदतीने Raspberry Pi 3 वर वाचणे.
🧰 लागणारे साहित्य
| घटक | संख्या |
|---|---|
| Raspberry Pi 3 | 1 |
| Flex Sensor | 1 |
| 10KΩ रेसिस्टर | 1 |
| MCP3008 ADC | 1 |
| ब्रेडबोर्ड आणि वायर | गरजेनुसार |
⚡ सर्किट कनेक्शन
Flex Sensor + MCP3008 + Raspberry Pi 3
| MCP3008 पिन | जोडणी |
|---|---|
| VDD & VREF | 3.3V |
| AGND & DGND | GND |
| CLK | GPIO11 |
| DOUT | GPIO9 |
| DIN | GPIO10 |
| CS/SHDN | GPIO8 |
| CH0 | Flex sensor चे output |
🧠 पाइथन कोड
import spidev
import time
spi = spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz = 1350000
def read_channel(channel):
adc = spi.xfer2([1, (8 + channel) << 4, 0])
data = ((adc[1] & 3) << 8) + adc[2]
return data
try:
while True:
flex_value = read_channel(0)
print("🤸 Flex Sensor वाचन:", flex_value)
time.sleep(0.5)
except KeyboardInterrupt:
spi.close()
📊 आउटपुट
- Flex Sensor किती वाकला आहे त्यावर आधारित analog value दर्शवते.
- जास्त वाकले असेल तर value जास्त असते.
💡 उपयोग
- Gesture control gloves
- रोबोटिक हात नियंत्रणे
- विअरेबल उपकरणे
Comments